use askama::Template; use askama_axum::IntoResponse; use axum::{extract::Query, routing, Router}; use serde::Deserialize; struct MenuItem { label: String, href: String, current: bool, } #[derive(Deserialize)] struct MenuParameters { mobile: bool, } #[derive(Template)] #[template(path = "layout/nav/nav-menu-items.html")] struct MenuResponse { mobile: bool, items: Vec, } impl MenuResponse { fn get_classes(&self, is_current_item: &bool) -> String { let common_classes = match self.mobile { true => "block border-l-4 py-2 pl-3 pr-4 text-base font-medium".to_string(), false => "inline-flex items-center border-b-2 px-1 pt-1 text-sm font-medium".to_string(), }; match (self.mobile, is_current_item) { (true, true) => common_classes + " border-indigo-500 bg-indigo-50 text-indigo-700", (true, false) => common_classes + " border-transparent text-gray-600 hover:border-gray-300 hover:bg-gray-50 hover:text-gray-800", (false, true) => common_classes + " border-indigo-500 text-gray-900", (false, false) => common_classes + " border-transparent text-gray-500 hover:border-gray-300 hover:text-gray-700", } } } async fn menu(Query(params): Query) -> impl IntoResponse { MenuResponse { mobile: params.mobile, items: vec![ MenuItem { label: "Accueil".to_string(), href: "/pages/home".to_string(), current: true, }, MenuItem { label: "CPS".to_string(), href: "/pages/cps".to_string(), current: false, }, ], }.into_response() } pub fn get_routes() -> Router { Router::new() .route("/menu", routing::get(menu)) }