diff --git a/.gitignore b/.gitignore index ed4d94c..68539d4 100644 --- a/.gitignore +++ b/.gitignore @@ -6,4 +6,5 @@ webdist/ nix/*/result result .vscode/ -.session_store/ \ No newline at end of file +.session_store/ +.gitignore/ \ No newline at end of file diff --git a/web/src/components/tabs.rs b/web/src/components/tabs.rs index 9771c41..2e876ef 100644 --- a/web/src/components/tabs.rs +++ b/web/src/components/tabs.rs @@ -43,7 +43,6 @@ pub fn TabbedView<'a, G: Html>(cx: Scope<'a>, state: TabState<'a, G>) -> View view! {cx, li(class=class) { a(href=href) { (show) } } } - // TODO }) .collect(), ); diff --git a/web/src/routing/mod.rs b/web/src/routing/mod.rs index 1bba2b9..fbc0169 100644 --- a/web/src/routing/mod.rs +++ b/web/src/routing/mod.rs @@ -12,11 +12,14 @@ // See the License for the specific language governing permissions and // limitations under the License. -use crate::app_state::StateHandler; +use crate::{ + app_state::StateHandler, + components::{Footer, Header}, + pages::*, +}; use sycamore::prelude::*; use sycamore_router::{HistoryIntegration, Route, Router}; - -use crate::pages::*; +use tracing::{debug, instrument}; #[derive(Route, Debug)] pub enum Routes { @@ -71,52 +74,63 @@ pub struct HandlerProps<'ctx> { sh: StateHandler<'ctx>, } +#[instrument(skip_all, fields(?route))] +fn route_switch<'ctx, G: Html>(route: &Routes, cx: Scope<'ctx>, sh: StateHandler<'ctx>) -> View { + debug!("Handling route change"); + use ManageRoutes::*; + use PlanningRoutes::*; + match route { + Routes::Planning(Plan) => view! {cx, + PlanPage(sh) + }, + Routes::Planning(Inventory) => view! {cx, + InventoryPage(sh) + }, + Routes::Planning(Cook) => view! {cx, + CookPage(sh) + }, + Routes::Login => view! {cx, + LoginPage(sh) + }, + Routes::Recipe(RecipeRoutes::View(id)) => view! {cx, + RecipeViewPage(recipe=id.clone(), sh=sh) + }, + Routes::Recipe(RecipeRoutes::Edit(id)) => view! {cx, + RecipeEditPage(recipe=id.clone(), sh=sh) + }, + Routes::Manage(Categories) => view! {cx, + CategoryPage(sh) + }, + Routes::Manage(NewRecipe) => view! {cx, + AddRecipePage(sh) + }, + Routes::Manage(Staples) => view! {cx, + StaplesPage(sh) + }, + Routes::NotFound + | Routes::Manage(ManageRoutes::NotFound) + | Routes::Planning(PlanningRoutes::NotFound) + | Routes::Recipe(RecipeRoutes::NotFound) => view! {cx, + // TODO(Create a real one) + PlanPage(sh) + }, + } +} + #[component] pub fn Handler<'ctx, G: Html>(cx: Scope<'ctx>, props: HandlerProps<'ctx>) -> View { let HandlerProps { sh } = props; - use ManageRoutes::*; - use PlanningRoutes::*; view! {cx, Router( integration=HistoryIntegration::new(), view=move |cx: Scope, route: &ReadSignal| { - match route.get().as_ref() { - Routes::Planning(Plan) => view! {cx, - PlanPage(sh) - }, - Routes::Planning(Inventory) => view! {cx, - InventoryPage(sh) - }, - Routes::Planning(Cook) => view! {cx, - CookPage(sh) - }, - Routes::Login => view! {cx, - LoginPage(sh) - }, - Routes::Recipe(RecipeRoutes::View(id)) => view! {cx, - RecipeViewPage(recipe=id.clone(), sh=sh) - }, - Routes::Recipe(RecipeRoutes::Edit(id)) => view! {cx, - RecipeEditPage(recipe=id.clone(), sh=sh) - }, - Routes::Manage(Categories) => view! {cx, - CategoryPage(sh) - }, - Routes::Manage(NewRecipe) => view! {cx, - AddRecipePage(sh) - }, - Routes::Manage(Staples) => view! {cx, - StaplesPage(sh) - }, - Routes::NotFound - | Routes::Manage(ManageRoutes::NotFound) - | Routes::Planning(PlanningRoutes::NotFound) - | Routes::Recipe(RecipeRoutes::NotFound) => view! {cx, - // TODO(Create a real one) - PlanPage(sh) - }, + view!{cx, + div(class="app") { + Header(sh) + (route_switch(route.get().as_ref(), cx, sh)) + Footer { } + } } - }, ) } diff --git a/web/src/web.rs b/web/src/web.rs index 9a6fc1e..8791351 100644 --- a/web/src/web.rs +++ b/web/src/web.rs @@ -15,7 +15,6 @@ use sycamore::{futures::spawn_local_scoped, prelude::*}; use tracing::{info, instrument}; use crate::app_state::Message; -use crate::components::{Footer, Header}; use crate::{api, routing::Handler as RouteHandler}; #[instrument] @@ -33,11 +32,7 @@ pub fn UI(cx: Scope) -> View { sh.dispatch(cx, Message::LoadState); // TODO(jwall): This needs to be moved into the RouteHandler view.set(view! { cx, - div(class="app") { - Header(sh) - RouteHandler(sh=sh) - Footer { } - } + RouteHandler(sh=sh) }); } });