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, }, }); } }