From 5ef000dec0c4525c32911a6a531b81dd1ee7fa6c Mon Sep 17 00:00:00 2001 From: traxys Date: Mon, 26 Jun 2023 12:06:08 +0200 Subject: [PATCH] app,server: Display rating in recipe --- api/src/lib.rs | 3 ++- app/src/recipe.rs | 30 ++++++++++++++++++++++++------ src/routes/recipe.rs | 3 ++- 3 files changed, 28 insertions(+), 8 deletions(-) diff --git a/api/src/lib.rs b/api/src/lib.rs index bd1dd03..b0bd6c1 100644 --- a/api/src/lib.rs +++ b/api/src/lib.rs @@ -99,12 +99,13 @@ pub struct CreateRecipeResponse { #[derive(Serialize, Deserialize, Clone, Debug)] pub struct ListRecipesResponse { - pub recipes: Vec<(i64, String)>, + pub recipes: Vec<(i64, String, u8)>, } #[derive(Serialize, Deserialize, Clone, Debug)] pub struct RecipeInfo { pub name: String, + pub rating: u8, pub steps: String, pub ingredients: Vec<(i64, IngredientInfo, f64)>, } diff --git a/app/src/recipe.rs b/app/src/recipe.rs index 008652a..b6e9478 100644 --- a/app/src/recipe.rs +++ b/app/src/recipe.rs @@ -50,7 +50,7 @@ fn RecipeListInner(props: &RecipeListProps) -> HtmlResult { Ok(l) => html! {
- {for l.recipes.iter().sorted_by_key(|(_, name)| name).map(|(id, name)| html!{ + {for l.recipes.iter().sorted_by_key(|(_, name, _)| name).map(|(id, name, _)| html!{
@@ -623,6 +623,21 @@ fn EditSteps(props: &EditStepsProps) -> Html { } } +#[derive(Debug, Clone, PartialEq, Properties)] +struct RecipeRatingProps { + rating: u8, +} + +#[function_component] +fn RecipeRating(props: &RecipeRatingProps) -> Html { + let rating = (props.rating + 1).min(3); + html! { +
+ { for (0..rating).map(|_| html!{