From 0aa1d072311715d1e4f132f5731fc1c6726e35c8 Mon Sep 17 00:00:00 2001 From: jableader Date: Sun, 19 May 2024 21:31:58 +1000 Subject: [PATCH] Number of serves affects purchase amount --- src/components/shopping/shopping.js | 11 ++++++++++- 1 file changed, 10 insertions(+), 1 deletion(-) diff --git a/src/components/shopping/shopping.js b/src/components/shopping/shopping.js index 4488666..37a91b6 100644 --- a/src/components/shopping/shopping.js +++ b/src/components/shopping/shopping.js @@ -1,10 +1,19 @@ import units from '@/units.js'; +function scaleFactor(meal, recipe) { + const numYield = recipe.serves; + const numConsumers = meal.consumers.length; + + return numConsumers / numYield; +} + export function mealToShoppingListSources(meal) { const sources = []; for (const recipe of meal.recipes) { + const scale = scaleFactor(meal, recipe); for (const ingredient of recipe.ingredients) { - sources.push({ ingredient, meal, recipe, }); + const quantity = ingredient.quantity * scale; + sources.push({ meal, recipe, ingredient: { ...ingredient, quantity, }, }); } }