use crate::{page::new, Backend}; use axum::{ extract::{Path, State}, response::{IntoResponse, Redirect, Response}, routing::get, Router, }; use axum_extra::extract::CookieJar; use maud::{html, Markup, PreEscaped}; use std::sync::Arc; use uuid::Uuid; async fn index(State(backend): State>, cookies: CookieJar) -> Response { let (cookies, client) = backend.client(cookies).await; let sightings = backend.sightings_for_client(&client).await; let amount_total_cameras = backend.amount_total_cameras().await; let highscore = backend.highscore().await; let markup = new(html! { hgroup { h1 { "Digital Shadows" (PreEscaped("—")) "Who finds the most cameras?" } } p { mark { "TODO: Explanation of AEF / digital shadows / search game" } } p { mark { "TODO: Show optional SUCC message" } } form { fieldset role="group" { input name="name" placeholder="Replace Name" aria-label="Name"; input type="submit" value="Save"; } } p { mark { "TODO: Show optional REGISTER-NAME message" } } p { "You have found " (sightings.len()) "/" (amount_total_cameras) " cameras." } p { h2 { "Highscore" } ul.iterated { @for rank in highscore { li.card { span { span.font-headline.rank.text-muted { (rank.rank)"." } @if rank.uuid == client.uuid { (PreEscaped("")) } (rank.name) @if rank.uuid == client.uuid { (PreEscaped("")) } } span.font-headline.cam { (rank.amount)(PreEscaped(" "))"📸" } } } } } }); (cookies, markup).into_response() } async fn game( State(backend): State>, cookies: CookieJar, Path(uuid): Path, ) -> Result { let (cookies, client) = backend.client(cookies).await; let Ok(uuid) = Uuid::parse_str(&uuid) else { return Err(not_found().await.into_response()); }; let Some(camera) = backend.camera_by_uuid(uuid).await else { return Err(not_found().await.into_response()); }; let succ = backend.client_found_camera(&client, &camera).await; // TODO: show succ/err based on succ Ok(Redirect::to("/game")) } async fn not_found() -> Markup { new(html! { h1 { "uups" } }) } pub(super) fn routes() -> Router> { Router::new() .route("/game", get(index)) .route("/{*uuid}", get(game)) }