app: Correctly handle person count when editing ingredients
This commit is contained in:
parent
725c2ff3be
commit
66f9b729b5
1 changed files with 7 additions and 5 deletions
|
|
@ -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()}
|
||||
/>
|
||||
</div>
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue