Fix bad routing for recipe selection

This commit is contained in:
Jeremy Wall 2022-09-05 12:11:39 -04:00
parent 9011ff13b2
commit 9e66d6e66f
4 changed files with 15 additions and 8 deletions

View File

@ -71,7 +71,13 @@ async fn ui_static_assets(Path(path): Path<String>) -> 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())

View File

@ -61,7 +61,6 @@ pub fn recipe(idx: ReadSignal<String>) -> View<G> {
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())
}

View File

@ -38,7 +38,7 @@ pub fn recipe_selection(props: RecipeCheckBoxProps) -> View<G> {
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! {

View File

@ -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");