From ca726c8e8b7475b494d9b79d7d9134429972c4a3 Mon Sep 17 00:00:00 2001 From: jmanczak Date: Wed, 6 May 2026 00:58:07 +0200 Subject: [PATCH] quote deletion confirmation --- src/web/pages/mod.rs | 5 +++- src/web/pages/quotes/id.rs | 52 +++++++++++++++++++++++++++++++++++++- 2 files changed, 55 insertions(+), 2 deletions(-) diff --git a/src/web/pages/mod.rs b/src/web/pages/mod.rs index 503e241..3b88706 100644 --- a/src/web/pages/mod.rs +++ b/src/web/pages/mod.rs @@ -51,7 +51,10 @@ pub fn pages() -> Router { // .route("/quotes", get(quotes::page)) .route("/quotes/{id}", get(quotes::id::page)) - .route("/quotes/{id}/delete", post(quotes::id::delete)) + .route( + "/quotes/{id}/delete", + get(quotes::id::delete_confirm).post(quotes::id::delete), + ) .route("/quotes/add", get(quotes::add::page)) .route("/quotes/add-form", post(quotes::add::form)) // diff --git a/src/web/pages/quotes/id.rs b/src/web/pages/quotes/id.rs index 0bc3354..f2a33c1 100644 --- a/src/web/pages/quotes/id.rs +++ b/src/web/pages/quotes/id.rs @@ -53,12 +53,62 @@ pub async fn page( span class="scale-[.75]" {(PreEscaped(icons::PEN))} "Edit" } + a href=(format!("/quotes/{id}/delete")) class="px-2 py-1 cursor-pointer border rounded flex flex-row gap-1 bg-pink-400/10 border-pink-400/25 hover:bg-pink-400/20 hover:border-pink-400/45" { + span class="scale-[.75]" {(PreEscaped(icons::TRASH))} + "Delete" + } + } + } @else { + "Failed to fetch quote. Are you sure it exists?" + } + } + ), + ) + .into_response()) +} + +pub async fn delete_confirm( + State(state): State, + Path(id): Path, + req: Request, +) -> Result { + let mut conn = state.pool.acquire().await?; + let u = match User::authenticate(&mut *conn, req.headers()).await? { + Some(u) => u, + None => return Ok(Redirect::to(&format!("/login?r={}", req.uri().path())).into_response()), + }; + let q = Quote::get_by_id(&mut conn, id).await; + + Ok(base( + "Delete Quote | Mnemosyne", + html!( + (nav(&mut conn, Some(&u), req.uri().path()).await) + + div class="max-w-4xl mx-auto px-2" { + div class="my-4 flex justify-between" { + p class="flex items-center gap-2 text-neutral-500" { + (PreEscaped(icons::TRASH)) + span class="font-lora" {"Deleting quote of ID " (id)} + } + } + @if let Ok(q) = q { + div class="border border-pink-400/25 bg-pink-400/10 rounded-md p-3 mb-4" { + p class="flex flex-wrap items-center gap-2 text-pink-200" { + span class="font-semibold" {"Are you sure you want to delete this quote?"} + span class="text-pink-300/80" {"This cannot be undone."} + } + } + (quote(&q)) + div class="flex flex-row w-full flex-wrap justify-start gap-2 mt-2" { form method="post" action=(format!("/quotes/{id}/delete")) { - button type="submit" class="px-2 py-1 border rounded flex flex-row gap-1 bg-pink-400/10 border-pink-400/25 hover:bg-pink-400/20 hover:border-pink-400/45" { + button type="submit" class="px-2 py-1 cursor-pointer border rounded flex flex-row gap-1 bg-pink-400/10 border-pink-400/25 hover:bg-pink-400/20 hover:border-pink-400/45" { span class="scale-[.75]" {(PreEscaped(icons::TRASH))} "Delete" } } + a href=(format!("/quotes/{id}")) class="px-2 py-1 border rounded flex flex-row gap-1 bg-neutral-200/5 border-neutral-200/25 hover:bg-neutral-200/15 hover:border-neutral-200/45" { + "Cancel" + } } } @else { "Failed to fetch quote. Are you sure it exists?"