diff --git a/aep-schedule-website/src/backend/fileserv.rs b/aep-schedule-website/src/backend/fileserv.rs index bde435f0ddb4c0f455485a8c8a4774459e7e9563..904ebf2b1b2e774b3684eded0dc7e9c57fb50b9b 100644 --- a/aep-schedule-website/src/backend/fileserv.rs +++ b/aep-schedule-website/src/backend/fileserv.rs @@ -21,7 +21,7 @@ pub async fn file_and_error_handler( if res.status() == StatusCode::OK { res.into_response() } else { - let handler = leptos_axum::render_app_to_stream(options.to_owned(), move || view! {<App/>}); + let handler = leptos_axum::render_app_to_stream(move || view! {<App/>}); handler(req).await.into_response() } } diff --git a/aep-schedule-website/src/backend/state.rs b/aep-schedule-website/src/backend/state.rs index 1379dc797fed00bdb15166dc872ea041ecd9944e..783d6e7afcd92ef30823bfb5d1f970700d679a73 100644 --- a/aep-schedule-website/src/backend/state.rs +++ b/aep-schedule-website/src/backend/state.rs @@ -1,3 +1,4 @@ +use crate::frontend::app::shell; use crate::frontend::app::App; use aep_schedule_generator::data::courses::Courses; use aep_schedule_generator::icalendar::calendar::Calendar; @@ -10,7 +11,7 @@ use axum::{ }; use leptos::prelude::*; use leptos_axum::handle_server_fns_with_context; -use leptos_router::RouteListing; +use leptos_axum::AxumRouteListing; use std::fs::File; use std::io::BufReader; use std::sync::Arc; @@ -31,11 +32,11 @@ pub struct AppState { pub courses: Arc<RwLock<Courses>>, pub calendar: Arc<RwLock<Calendar>>, pub users_to_notify: Arc<Mutex<UsersToNotify>>, - pub routes: Vec<RouteListing>, + pub routes: Vec<AxumRouteListing>, } impl AppState { - pub async fn new(leptos_options: LeptosOptions, routes: Vec<RouteListing>) -> Self { + pub async fn new(leptos_options: LeptosOptions, routes: Vec<AxumRouteListing>) -> Self { #[cfg(not(debug_assertions))] { // Don't spam Poly when reloading the website in debug mode @@ -130,15 +131,18 @@ pub async fn leptos_routes_handler( State(app_state): State<AppState>, req: Request<AxumBody>, ) -> Response { + let state = axum::extract::State(app_state.clone()); let handler = leptos_axum::render_route_with_context( - app_state.leptos_options.clone(), app_state.routes.clone(), move || { provide_context(app_state.calendar.clone()); provide_context(app_state.courses.clone()); provide_context(app_state.users_to_notify.clone()); }, - App, + { + let leptos_options = app_state.leptos_options.clone(); + move || shell(leptos_options.clone()) + }, ); - handler(req).await.into_response() + handler(state, req).await.into_response() } diff --git a/aep-schedule-website/src/frontend/app.rs b/aep-schedule-website/src/frontend/app.rs index d0bbb147fa5f6027a13d9e298a5fdc62efb7ecb3..b1648d9907b63a8ce8665f9efadc1f62ed8dbe41 100644 --- a/aep-schedule-website/src/frontend/app.rs +++ b/aep-schedule-website/src/frontend/app.rs @@ -14,12 +14,13 @@ use leptos_router::{ pub fn shell(options: LeptosOptions) -> impl IntoView { view! { <!DOCTYPE html> - <html lang="en"> + <html lang="fr"> <head> <meta charset="utf-8"/> <meta name="viewport" content="width=device-width, initial-scale=1"/> <AutoReload options=options.clone() /> <HydrationScripts options/> + <link rel="stylesheet" id="leptos" href="/pkg/aep-schedule-website.css"/> <MetaTags/> </head> <body> @@ -66,17 +67,11 @@ pub fn Nav() -> impl IntoView { #[component] pub fn App() -> impl IntoView { - view! { - - // injects a stylesheet into the document <head> - // id=leptos means cargo-leptos will hot-reload this stylesheet - <Stylesheet id="leptos" href="/pkg/aep-schedule-website.css"/> + provide_meta_context(); - // sets the document title - <Title text="Générateur d'horaire"/> - - // content for this welcome page + view! { <Router> + <Title text="Générateur d'horaire"/> <Nav/> <main class="h-full"> <FlatRoutes fallback=|| "Not found"> diff --git a/aep-schedule-website/src/lib.rs b/aep-schedule-website/src/lib.rs index da5d16113641118c50e3441dcda8826c8a4adc3a..986ebd05d17cc87ff9e2f2162ace6f800b89b1fa 100644 --- a/aep-schedule-website/src/lib.rs +++ b/aep-schedule-website/src/lib.rs @@ -3,7 +3,6 @@ pub mod backend; pub mod frontend; cfg_if::cfg_if! { if #[cfg(feature = "hydrate")] { - use leptos::prelude::*; use wasm_bindgen::prelude::wasm_bindgen; use crate::frontend::app::App; @@ -13,6 +12,6 @@ cfg_if::cfg_if! { if #[cfg(feature = "hydrate")] { _ = console_log::init_with_level(log::Level::Debug); console_error_panic_hook::set_once(); - leptos::mount_to_body(App); + leptos::mount::mount_to_body(App); } }} diff --git a/aep-schedule-website/src/main.rs b/aep-schedule-website/src/main.rs index ae90c0ac74427ac0e8ff5d77daed9ec4ca160a50..1bb04894d09b784725bcdc9255a1b987c865f989 100644 --- a/aep-schedule-website/src/main.rs +++ b/aep-schedule-website/src/main.rs @@ -19,7 +19,7 @@ cfg_if::cfg_if!(if #[cfg(feature = "ssr")] { // <https://github.com/leptos-rs/start-axum#executing-a-server-on-a-remote-machine-without-the-toolchain> // Alternately a file can be specified such as Some("Cargo.toml") // The file would need to be included with the executable when moved to deployment - let conf = get_configuration(None).await.unwrap(); + let conf = get_configuration(None).unwrap(); let leptos_options = conf.leptos_options; let routes = generate_route_list(App); let state = AppState::new(leptos_options.clone(), routes.clone()).await;