app: Allow to list recipes

This commit is contained in:
traxys 2023-06-25 14:12:09 +02:00
parent 80e3d7ee86
commit f3788e31a9
3 changed files with 136 additions and 6 deletions

View file

@ -22,6 +22,7 @@ mod bootstrap;
mod ingredients;
mod recipe_creator;
mod sidebar;
mod recipe;
const API_ROUTE: &str = match option_env!("REGALADE_API_SERVER_BASE") {
None => "http://localhost:8085",
@ -50,11 +51,45 @@ enum Route {
NewRecipe,
#[at("/recipe/:id")]
Recipe { id: i64 },
#[at("/recipe")]
SearchRecipe,
#[at("/404")]
#[not_found]
NotFound,
}
#[derive(Clone, Copy, PartialEq, Eq, Debug)]
enum RouteKind {
Index,
Ingredients,
NewRecipe,
Recipe,
}
impl Route {
fn kind(&self) -> Option<RouteKind> {
match self {
Route::Index => Some(RouteKind::Index),
Route::Ingredients => Some(RouteKind::Ingredients),
Route::NewRecipe => Some(RouteKind::NewRecipe),
Route::Recipe { .. } => Some(RouteKind::Recipe),
Route::SearchRecipe => Some(RouteKind::Recipe),
_ => None,
}
}
}
impl RouteKind {
fn redirect_to(&self) -> Route {
match self {
RouteKind::Index => Route::Index,
RouteKind::Ingredients => Route::Ingredients,
RouteKind::NewRecipe => Route::NewRecipe,
RouteKind::Recipe => Route::SearchRecipe,
}
}
}
#[function_component]
fn App() -> Html {
html! {
@ -483,6 +518,11 @@ fn switch(route: Route) -> Html {
{format!("RECIPE {id}")}
</GlobalStateRedirector>
},
Route::SearchRecipe => html!{
<GlobalStateRedirector {route}>
<recipe::RecipeList />
</GlobalStateRedirector>
},
Route::NotFound => html! {
"Page not found"
},