app: Correctly handle person count when adding ingredients

This commit is contained in:
traxys 2023-06-30 19:43:26 +02:00
parent 66f9b729b5
commit 840afc7ef4

View file

@ -405,6 +405,7 @@ struct AddIngredientProps {
token: String, token: String,
household: Uuid, household: Uuid,
recipe: i64, recipe: i64,
person_count: u32,
update: Callback<()>, update: Callback<()>,
} }
@ -422,10 +423,12 @@ fn AddIngredientInner(props: &AddIngredientProps) -> HtmlResult {
let household = props.household; let household = props.household;
let recipe = props.recipe; let recipe = props.recipe;
let update = props.update.clone(); let update = props.update.clone();
let pc = props.person_count as f64;
let on_submit = Callback::from(move |_| match &*s_ig { let on_submit = Callback::from(move |_| match &*s_ig {
&Some((id, _)) => match &*am { &Some((id, _)) => match &*am {
&Some(amount) => { &Some(amount) => {
let fut = do_add_ingredient_recipe(token.clone(), household, recipe, id, amount); let fut =
do_add_ingredient_recipe(token.clone(), household, recipe, id, amount / pc);
let am = am.clone(); let am = am.clone();
let s_ig = s_ig.clone(); let s_ig = s_ig.clone();
@ -516,6 +519,7 @@ fn AddIngredient(props: &AddIngredientProps) -> Html {
household={props.household} household={props.household}
recipe={props.recipe} recipe={props.recipe}
update={props.update.clone()} update={props.update.clone()}
person_count={props.person_count}
/> />
</Suspense> </Suspense>
</>} </>}
@ -1025,6 +1029,7 @@ fn RecipeInfoView(props: &RecipeInfoProps) -> Html {
household={props.household} household={props.household}
recipe={props.recipe_id} recipe={props.recipe_id}
update={props.update.clone()} update={props.update.clone()}
person_count={*person_count}
/> />
</div> </div>
<hr /> <hr />