Redesign shopping list
Some checks failed
Build and Deploy / build-and-push (push) Failing after 1m19s

This commit is contained in:
2026-04-17 23:34:53 +02:00
parent a90e8ba9d2
commit 8e48ebdd95
7 changed files with 793 additions and 226 deletions

View File

@@ -218,6 +218,35 @@ export function aggregateRangeIngredientNeed(plans, startDate, numDays) {
});
}
/**
* Zapotrzebowanie składników dla konkretnych dni (tablica dateKey-ów).
* @param {Record<string, unknown>} plans
* @param {string[]} selectedDays — tablica dateKey-ów ('YYYY-MM-DD')
*/
export function aggregateSelectedDaysIngredientNeed(plans, selectedDays) {
if (!selectedDays || selectedDays.length === 0) return [];
const map = new Map();
for (const dk of selectedDays) {
const [y, m, d] = dk.split('-').map(Number);
const day = new Date(y, m - 1, d);
const dayPlan = getDayPlan(plans, day);
const lines = flattenDayIngredientLines(dayPlan);
for (const line of lines) {
const key = `${line.ingredientId}\t${line.unit}`;
const cur = map.get(key);
if (!cur) {
map.set(key, { ...line });
} else {
cur.amount = Math.round((cur.amount + line.amount) * 10) / 10;
}
}
}
return [...map.values()].sort((a, b) => {
const c = a.category.localeCompare(b.category);
return c !== 0 ? c : a.name.localeCompare(b.name, 'pl');
});
}
/**
* Jedna grupa na porę dnia: nagłówek pory raz, potem bloki przepisów ze składnikami.
*/