From 032d450af21f990719953dc1ca1c651a661090c4 Mon Sep 17 00:00:00 2001 From: jmanczak Date: Tue, 5 May 2026 23:52:09 +0200 Subject: [PATCH] barebones quote-specific page --- src/web/pages/mod.rs | 1 + src/web/pages/quotes.rs | 3 ++- src/web/pages/quotes/id.rs | 53 ++++++++++++++++++++++++++++++++++++++ 3 files changed, 56 insertions(+), 1 deletion(-) create mode 100644 src/web/pages/quotes/id.rs diff --git a/src/web/pages/mod.rs b/src/web/pages/mod.rs index 6cd271a..fbc0e0a 100644 --- a/src/web/pages/mod.rs +++ b/src/web/pages/mod.rs @@ -50,6 +50,7 @@ pub fn pages() -> Router { .route("/logs", get(logs::page)) // .route("/quotes", get(quotes::page)) + .route("/quotes/{id}", get(quotes::id::page)) .route("/quotes/add", get(quotes::add::page)) .route("/quotes/add-form", post(quotes::add::form)) // diff --git a/src/web/pages/quotes.rs b/src/web/pages/quotes.rs index a25175d..bc11e3a 100644 --- a/src/web/pages/quotes.rs +++ b/src/web/pages/quotes.rs @@ -18,6 +18,7 @@ use crate::{ }; pub mod add; +pub mod id; #[derive(Deserialize)] pub struct PageQuery { @@ -85,7 +86,7 @@ pub async fn page( } div class="flex flex-col gap-4 mb-8" { @for q in "es { - (quote(q)) + a href=(format!("/quotes/{}", q.id)) {(quote(q))} } div class="flex justify-between items-center mt-4 text-neutral-400" { diff --git a/src/web/pages/quotes/id.rs b/src/web/pages/quotes/id.rs new file mode 100644 index 0000000..1deb7d0 --- /dev/null +++ b/src/web/pages/quotes/id.rs @@ -0,0 +1,53 @@ +use axum::{ + extract::{Path, Request, State}, + response::{IntoResponse, Redirect, Response}, +}; +use maud::{PreEscaped, html}; +use uuid::Uuid; + +use crate::{ + MnemoState, + error::CompositeError, + quotes::Quote, + users::{User, auth::UserAuthenticate}, + web::{ + components::{nav::nav, quote::quote}, + icons, + pages::base, + }, +}; + +pub async fn page( + 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( + "Add 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::SCROLL_TEXT)) + span class="font-lora" {"Quote of ID " (id)} + } + } + @if let Ok(q) = q { + (quote(&q)) + } @else { + "Failed to fetch quote. Are you sure it exists?" + } + } + ), + ) + .into_response()) +}