From 9e66d6e66ff8b5baac065a3740071c01ed1d2eca Mon Sep 17 00:00:00 2001 From: Jeremy Wall Date: Mon, 5 Sep 2022 12:11:39 -0400 Subject: [PATCH] Fix bad routing for recipe selection --- kitchen/src/web/mod.rs | 8 +++++++- web/src/components/recipe.rs | 1 - web/src/components/recipe_selection.rs | 2 +- web/src/router_integration.rs | 12 +++++++----- 4 files changed, 15 insertions(+), 8 deletions(-) diff --git a/kitchen/src/web/mod.rs b/kitchen/src/web/mod.rs index 561cee4..91d3140 100644 --- a/kitchen/src/web/mod.rs +++ b/kitchen/src/web/mod.rs @@ -71,7 +71,13 @@ async fn ui_static_assets(Path(path): Path) -> impl IntoResponse { let mut path = path.trim_start_matches("/"); path = match path { "" | "inventory" | "plan" | "cook" | "login" => "index.html", - _ => path, + _ => { + if path.starts_with("recipe") { + "index.html" + } else { + path + } + } }; debug!(path = path, "Serving transformed path"); StaticFile(path.to_owned()) diff --git a/web/src/components/recipe.rs b/web/src/components/recipe.rs index d5a4387..01f5346 100644 --- a/web/src/components/recipe.rs +++ b/web/src/components/recipe.rs @@ -61,7 +61,6 @@ pub fn recipe(idx: ReadSignal) -> View { let steps = create_memo(cloned!((recipe) => move || recipe.get().steps.clone())); view.set(view! { div(class="recipe") { - h1(class="recipe_title") { (title.get()) } div(class="recipe_description") { (desc.get()) } diff --git a/web/src/components/recipe_selection.rs b/web/src/components/recipe_selection.rs index 7bac672..85da76e 100644 --- a/web/src/components/recipe_selection.rs +++ b/web/src/components/recipe_selection.rs @@ -38,7 +38,7 @@ pub fn recipe_selection(props: RecipeCheckBoxProps) -> View { app_service.get_recipe_count_by_index(id.as_ref()) )); let for_id = id.clone(); - let href = format!("#recipe/{}", id); + let href = format!("/ui/recipe/{}", id); let name = format!("recipe_id:{}", id); let value = id.clone(); view! { diff --git a/web/src/router_integration.rs b/web/src/router_integration.rs index 3e76eb4..6a5e54f 100644 --- a/web/src/router_integration.rs +++ b/web/src/router_integration.rs @@ -198,11 +198,13 @@ impl DeriveRoute for AppRoutes { "/ui/cook" => AppRoutes::Cook, "/ui/inventory" => AppRoutes::Inventory, h => { - // TODO(jwall): Parse the recipe hash - let parts: Vec<&str> = h.splitn(2, "/").collect(); - if let Some(&"#recipe") = parts.get(0) { - if let Some(&idx) = parts.get(1) { - return AppRoutes::Recipe(idx.to_owned()); + if h.starts_with("/ui/recipe/") { + let parts: Vec<&str> = h.split("/").collect(); + debug!(?parts, "found recipe path"); + if let Some(&"recipe") = parts.get(2) { + if let Some(&idx) = parts.get(3) { + return AppRoutes::Recipe(idx.to_owned()); + } } } error!(origin=%input.0, path=%input.1, hash=%input.2, "Path not found");