From 8d79d7640cadab30ff1e7bfa8df41eb08ffbdf48 Mon Sep 17 00:00:00 2001 From: "Matthias P. Braendli" Date: Tue, 2 Jan 2024 14:30:44 +0100 Subject: Add more pages, improve nav --- src/main.rs | 61 ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++--- 1 file changed, 58 insertions(+), 3 deletions(-) (limited to 'src/main.rs') diff --git a/src/main.rs b/src/main.rs index 1850e66..cab477c 100644 --- a/src/main.rs +++ b/src/main.rs @@ -11,6 +11,8 @@ use axum::{ use sqlx::{Connection, SqliteConnection}; use tower_http::services::ServeDir; +mod config; + struct AppState { callsign : String, db : Mutex @@ -20,6 +22,9 @@ type SharedState = Arc; #[tokio::main] async fn main() -> std::io::Result<()> { + + // simple_logger:: + let mut conn = SqliteConnection::connect("sqlite:cats-radio-node.db").await.unwrap(); sqlx::migrate!() .run(&mut conn) @@ -35,6 +40,9 @@ async fn main() -> std::io::Result<()> { let app = Router::new() .route("/", get(dashboard)) + .route("/incoming", get(incoming)) + .route("/send", get(send)) + .route("/settings", get(settings)) .route("/form", get(show_form).post(accept_form)) .nest_service("/static", ServeDir::new("static")) /* requires tracing and tower, e.g. @@ -70,6 +78,7 @@ enum ActivePage { Dashboard, Incoming, Send, + Settings, } #[derive(Template)] @@ -80,9 +89,7 @@ struct DashboardTemplate<'a> { callsign: String, } -async fn dashboard( - State(state): State, - ) -> DashboardTemplate<'static> { +async fn dashboard(State(state): State) -> DashboardTemplate<'static> { DashboardTemplate { title: "Dashboard", callsign: state.callsign.clone(), @@ -90,6 +97,54 @@ async fn dashboard( } } +#[derive(Template)] +#[template(path = "incoming.html")] +struct IncomingTemplate<'a> { + title: &'a str, + page: ActivePage, + callsign: String, +} + +async fn incoming(State(state): State) -> IncomingTemplate<'static> { + IncomingTemplate { + title: "Incoming", + callsign: state.callsign.clone(), + page: ActivePage::Incoming, + } +} + +#[derive(Template)] +#[template(path = "send.html")] +struct SendTemplate<'a> { + title: &'a str, + page: ActivePage, + callsign: String, +} + +async fn send(State(state): State) -> SendTemplate<'static> { + SendTemplate { + title: "Send", + callsign: state.callsign.clone(), + page: ActivePage::Send, + } +} + +#[derive(Template)] +#[template(path = "settings.html")] +struct SettingsTemplate<'a> { + title: &'a str, + page: ActivePage, + callsign: String, +} + +async fn settings(State(state): State) -> SettingsTemplate<'static> { + SettingsTemplate { + title: "Settings", + callsign: state.callsign.clone(), + page: ActivePage::Settings, + } +} + async fn show_form() -> Html<&'static str> { Html( r#" -- cgit v1.2.3