mirror of
https://github.com/zaphar/kitchen.git
synced 2025-07-22 19:40:14 -04:00
Fix non dynamic routing :-(
This commit is contained in:
parent
a39ed5589f
commit
0167e6070d
1
.gitignore
vendored
1
.gitignore
vendored
@ -7,3 +7,4 @@ nix/*/result
|
||||
result
|
||||
.vscode/
|
||||
.session_store/
|
||||
.gitignore/
|
@ -43,7 +43,6 @@ pub fn TabbedView<'a, G: Html>(cx: Scope<'a>, state: TabState<'a, G>) -> View<G>
|
||||
view! {cx,
|
||||
li(class=class) { a(href=href) { (show) } }
|
||||
}
|
||||
// TODO
|
||||
})
|
||||
.collect(),
|
||||
);
|
||||
|
@ -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<G> {
|
||||
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<G> {
|
||||
let HandlerProps { sh } = props;
|
||||
use ManageRoutes::*;
|
||||
use PlanningRoutes::*;
|
||||
view! {cx,
|
||||
Router(
|
||||
integration=HistoryIntegration::new(),
|
||||
view=move |cx: Scope, route: &ReadSignal<Routes>| {
|
||||
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 { }
|
||||
}
|
||||
}
|
||||
|
||||
},
|
||||
)
|
||||
}
|
||||
|
@ -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<G: Html>(cx: Scope) -> View<G> {
|
||||
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)
|
||||
});
|
||||
}
|
||||
});
|
||||
|
Loading…
x
Reference in New Issue
Block a user