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
3
.gitignore
vendored
3
.gitignore
vendored
@ -6,4 +6,5 @@ webdist/
|
|||||||
nix/*/result
|
nix/*/result
|
||||||
result
|
result
|
||||||
.vscode/
|
.vscode/
|
||||||
.session_store/
|
.session_store/
|
||||||
|
.gitignore/
|
@ -43,7 +43,6 @@ pub fn TabbedView<'a, G: Html>(cx: Scope<'a>, state: TabState<'a, G>) -> View<G>
|
|||||||
view! {cx,
|
view! {cx,
|
||||||
li(class=class) { a(href=href) { (show) } }
|
li(class=class) { a(href=href) { (show) } }
|
||||||
}
|
}
|
||||||
// TODO
|
|
||||||
})
|
})
|
||||||
.collect(),
|
.collect(),
|
||||||
);
|
);
|
||||||
|
@ -12,11 +12,14 @@
|
|||||||
// See the License for the specific language governing permissions and
|
// See the License for the specific language governing permissions and
|
||||||
// limitations under the License.
|
// limitations under the License.
|
||||||
|
|
||||||
use crate::app_state::StateHandler;
|
use crate::{
|
||||||
|
app_state::StateHandler,
|
||||||
|
components::{Footer, Header},
|
||||||
|
pages::*,
|
||||||
|
};
|
||||||
use sycamore::prelude::*;
|
use sycamore::prelude::*;
|
||||||
use sycamore_router::{HistoryIntegration, Route, Router};
|
use sycamore_router::{HistoryIntegration, Route, Router};
|
||||||
|
use tracing::{debug, instrument};
|
||||||
use crate::pages::*;
|
|
||||||
|
|
||||||
#[derive(Route, Debug)]
|
#[derive(Route, Debug)]
|
||||||
pub enum Routes {
|
pub enum Routes {
|
||||||
@ -71,52 +74,63 @@ pub struct HandlerProps<'ctx> {
|
|||||||
sh: StateHandler<'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]
|
#[component]
|
||||||
pub fn Handler<'ctx, G: Html>(cx: Scope<'ctx>, props: HandlerProps<'ctx>) -> View<G> {
|
pub fn Handler<'ctx, G: Html>(cx: Scope<'ctx>, props: HandlerProps<'ctx>) -> View<G> {
|
||||||
let HandlerProps { sh } = props;
|
let HandlerProps { sh } = props;
|
||||||
use ManageRoutes::*;
|
|
||||||
use PlanningRoutes::*;
|
|
||||||
view! {cx,
|
view! {cx,
|
||||||
Router(
|
Router(
|
||||||
integration=HistoryIntegration::new(),
|
integration=HistoryIntegration::new(),
|
||||||
view=move |cx: Scope, route: &ReadSignal<Routes>| {
|
view=move |cx: Scope, route: &ReadSignal<Routes>| {
|
||||||
match route.get().as_ref() {
|
view!{cx,
|
||||||
Routes::Planning(Plan) => view! {cx,
|
div(class="app") {
|
||||||
PlanPage(sh)
|
Header(sh)
|
||||||
},
|
(route_switch(route.get().as_ref(), cx, sh))
|
||||||
Routes::Planning(Inventory) => view! {cx,
|
Footer { }
|
||||||
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)
|
|
||||||
},
|
|
||||||
}
|
}
|
||||||
|
|
||||||
},
|
},
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
|
@ -15,7 +15,6 @@ use sycamore::{futures::spawn_local_scoped, prelude::*};
|
|||||||
use tracing::{info, instrument};
|
use tracing::{info, instrument};
|
||||||
|
|
||||||
use crate::app_state::Message;
|
use crate::app_state::Message;
|
||||||
use crate::components::{Footer, Header};
|
|
||||||
use crate::{api, routing::Handler as RouteHandler};
|
use crate::{api, routing::Handler as RouteHandler};
|
||||||
|
|
||||||
#[instrument]
|
#[instrument]
|
||||||
@ -33,11 +32,7 @@ pub fn UI<G: Html>(cx: Scope) -> View<G> {
|
|||||||
sh.dispatch(cx, Message::LoadState);
|
sh.dispatch(cx, Message::LoadState);
|
||||||
// TODO(jwall): This needs to be moved into the RouteHandler
|
// TODO(jwall): This needs to be moved into the RouteHandler
|
||||||
view.set(view! { cx,
|
view.set(view! { cx,
|
||||||
div(class="app") {
|
RouteHandler(sh=sh)
|
||||||
Header(sh)
|
|
||||||
RouteHandler(sh=sh)
|
|
||||||
Footer { }
|
|
||||||
}
|
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
Loading…
x
Reference in New Issue
Block a user