create index page
This commit is contained in:
		
							
								
								
									
										17
									
								
								src/lib.rs
									
									
									
									
									
								
							
							
						
						
									
										17
									
								
								src/lib.rs
									
									
									
									
									
								
							| @@ -1,8 +1,10 @@ | ||||
| use axum::{Router, body::Body, response::Response, routing::get}; | ||||
| use axum::{body::Body, response::Response, routing::get, Router}; | ||||
| use maud::{html, Markup}; | ||||
| use partials::page; | ||||
| use sqlx::SqlitePool; | ||||
| use std::sync::Arc; | ||||
| use tokio::net::TcpListener; | ||||
| use tower_sessions::{MemoryStore, SessionManagerLayer}; | ||||
| use tower_sessions::{MemoryStore, Session, SessionManagerLayer}; | ||||
|  | ||||
| mod partials; | ||||
| mod station; | ||||
| @@ -73,12 +75,23 @@ async fn serve_marker_png() -> Response<Body> { | ||||
|         .unwrap() | ||||
| } | ||||
|  | ||||
| async fn index(session: Session) -> Markup { | ||||
|     let content = html! { | ||||
|         h1 { "Stationslauf-App" } | ||||
|         a role="button" href="/station" { | ||||
|             "Stationen" | ||||
|         } | ||||
|     }; | ||||
|     page(content, session, false).await | ||||
| } | ||||
|  | ||||
| /// Starts the main application. | ||||
| pub async fn start(listener: TcpListener, db: SqlitePool) { | ||||
|     let session_store = MemoryStore::default(); | ||||
|     let session_layer = SessionManagerLayer::new(session_store); | ||||
|  | ||||
|     let app = Router::new() | ||||
|         .route("/", get(index)) | ||||
|         .nest("/station", station::routes()) | ||||
|         .route("/pico.css", get(serve_pico_css)) | ||||
|         .route("/style.css", get(serve_my_css)) | ||||
|   | ||||
| @@ -1,11 +1,11 @@ | ||||
| use crate::{err, partials::page, station::Station, succ}; | ||||
| use axum::{ | ||||
|     Form, Router, | ||||
|     extract::State, | ||||
|     response::{IntoResponse, Redirect}, | ||||
|     routing::{get, post}, | ||||
|     Form, Router, | ||||
| }; | ||||
| use maud::{Markup, html}; | ||||
| use maud::{html, Markup}; | ||||
| use serde::Deserialize; | ||||
| use sqlx::SqlitePool; | ||||
| use std::sync::Arc; | ||||
| @@ -371,7 +371,10 @@ async fn index(State(db): State<Arc<SqlitePool>>, session: Session) -> Markup { | ||||
|     let stations = Station::all(&db).await; | ||||
|  | ||||
|     let content = html! { | ||||
|         h1 { "Stationen" } | ||||
|         h1 { | ||||
|             a href="/" { "↩️" } | ||||
|             "Stationen" | ||||
|         } | ||||
|         ol { | ||||
|             @for station in &stations { | ||||
|                 li { | ||||
|   | ||||
		Reference in New Issue
	
	Block a user