use leptos::prelude::*; use leptos::Params; use leptos_router::hooks::use_params; use leptos_router::hooks::use_query; use leptos_router::params::Params; use leptos_meta::{provide_meta_context, MetaTags, Stylesheet, Title}; use leptos_router::{ components::{ParentRoute, Route, Router, Routes}, path }; use crate::components::layout::Layout; use super::renderer::WikiPage; use super::editor::WikiEditor; pub fn shell(options: LeptosOptions) -> impl IntoView { view! { } } #[component] pub fn App() -> impl IntoView { // Provides context that manages stylesheets, titles, meta tags, etc. provide_meta_context(); view! { // injects a stylesheet into the document // id=leptos means cargo-leptos will hot-reload this stylesheet // sets the document title // content for this welcome page <Router> <Routes fallback=|| "Page not found.".into_view()> <ParentRoute path=path!("/") view=Layout> <Route path=path!("/~/*path") view=PageRender/> <Route path=path!("/edit/*path") view=PageEdit/> </ParentRoute> </Routes> </Router> } } #[derive(Params, PartialEq)] struct PageParams { path: Option<String> } // Renders a page #[component] fn PageRender() -> impl IntoView { let params = use_params::<PageParams>(); let page_path = params.read() .as_ref() .ok() .map(|params| params.path.clone() .unwrap_or("Unknown path".to_string())) .unwrap_or("Could not read params".to_string()); view! { <WikiPage url_path=page_path /> }.into_any() } // Renders a page #[component] fn PageEdit() -> impl IntoView { let params = use_params::<PageParams>(); let page_path = params.read() .as_ref() .ok() .map(|params| params.path.clone() .unwrap_or("Unknown path".to_string())) .unwrap_or("Could not read params".to_string()); view! { <WikiEditor url_path=page_path /> } }