hover menu

This commit is contained in:
Priec
2026-06-20 12:13:15 +02:00
parent 42f30261d0
commit 0310f2d2f4
4 changed files with 94 additions and 14 deletions

View File

@@ -253,10 +253,39 @@ async fn show(
Ok((jar.add(cart_cookie(rebuilt)), response).into_response())
}
/// Mini-cart preview for the navbar hover dropdown. Lazy-loaded via htmx from
/// the header; returns just the `shop/_cart_preview.html` fragment.
#[debug_handler]
async fn preview(
jar: CookieJar,
ViewEngine(v): ViewEngine<TeraView>,
State(ctx): State<AppContext>,
) -> Result<Response> {
let (lines, valid, total) = resolve_cart(&ctx, &jar).await?;
let currency = lines
.first()
.and_then(|line| line["currency"].as_str())
.unwrap_or("EUR")
.to_string();
let rebuilt = serialize_cart(&valid);
let response = format::view(
&v,
"shop/_cart_preview.html",
json!({
"items": lines,
"total": format_price(total),
"currency": currency,
"lang": current_lang(&jar),
}),
)?;
Ok((jar.add(cart_cookie(rebuilt)), response).into_response())
}
pub fn routes() -> Routes {
Routes::new()
.add("/cart", get(show))
.add("/cart/add", post(add))
.add("/cart/update", post(update))
.add("/cart/remove", post(remove))
.add("/partials/cart", get(preview))
}