//! Leptos application root and router for public app. use leptos::prelude::*; use leptos_meta::{MetaTags, Stylesheet, Title, provide_meta_context}; use leptos_router::components::Router; use crate::routes::UserRoutes; #[cfg(feature = "ssr")] use std::sync::Arc; #[cfg(feature = "ssr")] use crate::api::WebSocketState; #[cfg(feature = "ssr")] use chattyness_shared::WebSocketConfig; /// Application state for the public app. #[cfg(feature = "ssr")] #[derive(Clone)] pub struct AppState { pub pool: sqlx::PgPool, pub leptos_options: LeptosOptions, pub ws_state: Arc, pub ws_config: WebSocketConfig, } #[cfg(feature = "ssr")] impl axum::extract::FromRef for sqlx::PgPool { fn from_ref(state: &AppState) -> Self { state.pool.clone() } } #[cfg(feature = "ssr")] impl axum::extract::FromRef for LeptosOptions { fn from_ref(state: &AppState) -> Self { state.leptos_options.clone() } } #[cfg(feature = "ssr")] impl axum::extract::FromRef for Arc { fn from_ref(state: &AppState) -> Self { state.ws_state.clone() } } #[cfg(feature = "ssr")] impl axum::extract::FromRef for WebSocketConfig { fn from_ref(state: &AppState) -> Self { state.ws_config.clone() } } /// Shell component for SSR. pub fn shell(options: LeptosOptions) -> impl IntoView { view! { } } /// Main application component. /// /// This wraps `UserRoutes` with a `Router` for standalone use. /// For embedding in a combined app (e.g., chattyness-app), use `UserRoutes` directly. #[component] pub fn App() -> impl IntoView { // Provide meta context for title and meta tags provide_meta_context(); view! { <Router> <main> <UserRoutes /> </main> </Router> } }