Add meal plan editor
Some checks failed
Build and Deploy / build-and-push (push) Failing after 1m19s

This commit is contained in:
2026-03-30 22:50:53 +02:00
parent efe1cd941c
commit ee9ddd915e
6 changed files with 829 additions and 405 deletions

View File

@@ -1,4 +1,4 @@
import { RECIPES } from '../data/catalog.js';
import { INGREDIENTS, RECIPES } from '../data/catalog.js';
import { MEAL_SLOTS } from '../planner/mealSlots.js';
import { PLANS_STORAGE_KEY } from '../storageKeys.js';
import { startOfDay } from './dateUtils.js';
@@ -18,7 +18,32 @@ export function newPlanEntryId() {
return `e${Date.now()}-${Math.random().toString(36).slice(2, 11)}`;
}
/** Jedna pora dnia = tablica wpisów { id, recipeId, servings } */
function normalizeEntryExtras(x) {
const out = {};
if (x.substitutions && typeof x.substitutions === 'object' && !Array.isArray(x.substitutions) && Object.keys(x.substitutions).length > 0) {
out.substitutions = { ...x.substitutions };
}
if (Array.isArray(x.excludedIngredients)) {
const arr = x.excludedIngredients.filter((id) => typeof id === 'string');
if (arr.length > 0) out.excludedIngredients = arr;
}
if (x.amountOverrides && typeof x.amountOverrides === 'object' && !Array.isArray(x.amountOverrides)) {
const filtered = {};
for (const [k, v] of Object.entries(x.amountOverrides)) {
if (typeof v === 'number' && v >= 0) filtered[k] = v;
}
if (Object.keys(filtered).length > 0) out.amountOverrides = filtered;
}
if (Array.isArray(x.addedIngredients)) {
const valid = x.addedIngredients
.filter((a) => a && typeof a.ingredientId === 'string' && INGREDIENTS[a.ingredientId] && typeof a.amount === 'number' && a.amount >= 0 && typeof a.unit === 'string')
.map((a) => ({ ingredientId: a.ingredientId, amount: a.amount, unit: a.unit }));
if (valid.length > 0) out.addedIngredients = valid;
}
return out;
}
/** Jedna pora dnia = tablica wpisów { id, recipeId, servings, ...extras } */
export function normalizeSlotValue(v) {
if (!v) return [];
if (Array.isArray(v)) {
@@ -28,9 +53,7 @@ export function normalizeSlotValue(v) {
id: x.id && String(x.id).length ? String(x.id) : newPlanEntryId(),
recipeId: x.recipeId,
servings: Math.max(1, Math.min(12, Number(x.servings) || 1)),
...(x.substitutions && typeof x.substitutions === 'object' && !Array.isArray(x.substitutions) && Object.keys(x.substitutions).length > 0
? { substitutions: { ...x.substitutions } }
: {}),
...normalizeEntryExtras(x),
}));
}
if (typeof v === 'object' && v.recipeId && RECIPES[v.recipeId]) {
@@ -38,9 +61,7 @@ export function normalizeSlotValue(v) {
id: newPlanEntryId(),
recipeId: v.recipeId,
servings: Math.max(1, Math.min(12, Number(v.servings) || 1)),
...(v.substitutions && typeof v.substitutions === 'object' && !Array.isArray(v.substitutions) && Object.keys(v.substitutions).length > 0
? { substitutions: { ...v.substitutions } }
: {}),
...normalizeEntryExtras(v),
}];
}
return [];