//! The Askama entry point for the described "remove from cart" button. //! //! Shape 8 (`b279b9eb`), through the glue-module ruling `27d5e5b8`. //! //! # The confirm is carried across rather than settled here //! //! This is the weakest case in the shape's destructive column: taking a line //! off a cart is undone by adding it again, and the prompt asks about a //! decision the reader has made by pressing a button labelled Remove. Whether //! it earns its keep is a question for the copy, not for the conversion, so the //! prompt moves as it was written and the question is filed rather than //! answered by a translation. //! //! The tone is not in question: the row goes. //! //! `DELETE /api/cart/{item}` is a plain API route the description layer does //! not serve; the page already gives the row an id, so the control names it. //! See [`Action::replaces`]. //! //! Ids arrive as `impl Display` rather than `&str`: the caller is Askama and //! the server's ids are typed newtypes over `Uuid`, so asking for a string //! would push a `to_string()` into every call site to say what `format!` //! already says here. use std::fmt; use makeover_layout::Tone; use quasi_router::screen::Act; use quasi_router::{Action, Node}; /// The remove button for one cart line. #[must_use] pub fn html(item_id: impl fmt::Display) -> String { use quasi_axum::Serves as _; let act = Act::new( "Remove", Action::delete(format!("/api/cart/{item_id}")).replacing(format!("cart-row-{item_id}")), ) .tone(Tone::Danger) .confirm("Remove this item from your cart?"); quasi_webview::Webview::new().fragment(&Node::Act(act)) } #[cfg(test)] mod tests { #[test] fn a_removal_names_its_route_its_row_and_its_prompt() { let html = super::html("i7"); assert!(html.contains(r#"hx-delete="/api/cart/i7""#), "{html}"); assert!(html.contains(r##"hx-target="#cart-row-i7""##), "{html}"); assert!( html.contains(r#"hx-confirm="Remove this item from your cart?""#), "{html}" ); } #[test] fn a_removal_says_it_is_dangerous() { assert!(super::html("i7").contains(r#"data-tone="danger""#)); } }