From 66f9b729b50fb674fc6b24146ca9a967997b593f Mon Sep 17 00:00:00 2001 From: traxys Date: Fri, 30 Jun 2023 19:38:10 +0200 Subject: [PATCH] app: Correctly handle person count when editing ingredients --- app/src/recipe.rs | 12 +++++++----- 1 file changed, 7 insertions(+), 5 deletions(-) diff --git a/app/src/recipe.rs b/app/src/recipe.rs index 377f359..fc75e6e 100644 --- a/app/src/recipe.rs +++ b/app/src/recipe.rs @@ -262,6 +262,7 @@ struct EditIngredientProps { recipe: i64, ingredient: i64, amount: f64, + person_count: u32, update: Callback<()>, } @@ -290,7 +291,7 @@ async fn do_edit_ingredient_recipe( #[function_component] fn EditIngredient(props: &EditIngredientProps) -> Html { - let amount = use_state(|| props.amount); + let amount = use_state(|| props.amount * props.person_count as f64); let am = amount.clone(); let onchange = Callback::from(move |e: Event| { @@ -317,8 +318,10 @@ fn EditIngredient(props: &EditIngredientProps) -> Html { let ingredient = props.ingredient; let update = props.update.clone(); let mid = modal_id.clone(); + let pc = props.person_count as f64; let on_submit = Callback::from(move |_| { - let future = do_edit_ingredient_recipe(token.clone(), household, recipe, ingredient, *am); + let future = + do_edit_ingredient_recipe(token.clone(), household, recipe, ingredient, *am / pc); let err = err.clone(); let update = update.clone(); @@ -826,9 +829,7 @@ fn EditPersonCount(props: &EditPersonCountProps) -> Html { let error = error.clone(); wasm_bindgen_futures::spawn_local(async move { - match do_edit_person_count(token.clone(), household, recipe, *person_count) - .await - { + match do_edit_person_count(token.clone(), household, recipe, *person_count).await { Ok(_) => { let modal = bs::Modal::get_instance("#rcpEditPersonCount"); modal.hide(); @@ -1012,6 +1013,7 @@ fn RecipeInfoView(props: &RecipeInfoProps) -> Html { ingredient={*id} household={props.household} amount={*amount} + person_count={*person_count} update={props.update.clone()} />