feat: catalogo+30, varianti, sostituti, reintroduzione Fase 2, free meal Fase 3 (PRD §5.1)
Quattro completamenti del PRD §5.1: catalogo, varianti/sostituti, fase 2,
free meal.
Catalogo ricette 16 → 46
- seed-recipes.ts: +30 ricette italiane keto bilanciate
(8 colazione · 8 pranzo · 6 spuntino · 8 cena)
- seed-ingredients.ts: 33 → 55 ingredienti
(verdura/carne/pesce/latticini/condimenti + categorie nuove `legumi` e
`cereali` per Fase 2)
- seed.ts: ora fa upsert anche degli ingredienti pre-esistenti per
propagare campi nuovi (es. phase2Week)
Varianti + sostituti
- Recipe.variants Json (array { name, description, kcalDelta? })
- RecipeIngredient.substitutes String[]
- /recipes/[id]: nuova sezione "Varianti suggerite" + riga "Sostituzioni:"
sotto ogni ingrediente quando presenti
Reintroduzione progressiva Fase 2
- Ingredient.phase2Week (settimana minima di reintroduzione, NULL=sempre)
- User.phase2StartedAt: settato automaticamente quando si passa a TRANSITION
- @ketopath/shared/planner/phase-progression: currentPhase2Week,
isRecipeAllowedForPhaseWeek, weeksSince
- plan.routes filtra fuori le ricette con ingredienti non ancora reintrodotti
- POST /me/profile/phase per avanzare di fase (idempotente sul timestamp)
- 12 unit test su phase-progression
- Esempi seed: lenticchie phase2Week=3, ceci=4, mela=5, pera=6, quinoa=7
Free Meal pianificato Fase 3
- MealSlot.isFreeMeal Boolean (default false)
- POST /me/meal-plans/slots/:id/free-meal toggle, valido solo in MAINTENANCE
- @ketopath/shared/planner/phase-progression: freeMealKcalAdjustment
(compensazione clamp -200/+50 kcal per pasto sui rimanenti)
- /plan: bottone ☆ in ogni SlotCard quando phase=MAINTENANCE; lo slot
marcato come pasto libero rende "Pasto libero pianificato" + ~750 kcal
stimate; macro tracker ne tiene conto
Indicatori di fase nel piano
- /plan ora include currentPhase + phase2Week dalla API
- Header del piano: "Settimana N di Fase 2" o "Mantenimento — Fase 3"
i18n: namespaces Plan + Recipe arricchiti
Schema migration 20260429XXXXXX_add_meal_plan_extras.
66/66 unit test verdi (12 nuovi). Smoke verificato live: API ritorna
correctly i campi nuovi, UI rende badge fase, bottoni ☆/↻, free-meal slot.
Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
This commit is contained in:
1 parent
2c11b73703
commit
bda96a3550
15 files changed
+1288
-44
No files matched your search
@@ -13,6 +13,13 @@ interface RecipeIngredientView {
|
||||
category: string;
|
||||
quantity: number;
|
||||
unit: string;
|
||||
substitutes: string[];
|
||||
}
|
||||
|
||||
interface RecipeVariant {
|
||||
name: string;
|
||||
description: string;
|
||||
kcalDelta?: number;
|
||||
}
|
||||
|
||||
interface RecipeView {
|
||||
@@ -29,6 +36,7 @@ interface RecipeView {
|
||||
phases: number[];
|
||||
notesChef: string | null;
|
||||
ingredients: RecipeIngredientView[];
|
||||
variants: RecipeVariant[];
|
||||
}
|
||||
|
||||
export default async function RecipePage({
|
||||
@@ -72,7 +80,9 @@ export default async function RecipePage({
|
||||
category: ri.ingredient.category,
|
||||
quantity: ri.quantity,
|
||||
unit: ri.unit,
|
||||
substitutes: ri.substitutes ?? [],
|
||||
})),
|
||||
variants: parseVariants(recipe.variants),
|
||||
};
|
||||
|
||||
return <RecipeContent recipe={view} />;
|
||||
@@ -80,6 +90,21 @@ export default async function RecipePage({
|
||||
|
||||
const ROMAN = ['I', 'II', 'III', 'IV', 'V', 'VI', 'VII', 'VIII', 'IX', 'X', 'XI', 'XII'];
|
||||
|
||||
function parseVariants(value: unknown): RecipeVariant[] {
|
||||
if (!Array.isArray(value)) return [];
|
||||
return value
|
||||
.filter((v): v is { name: string; description: string; kcalDelta?: number } => {
|
||||
if (!v || typeof v !== 'object') return false;
|
||||
const o = v as Record<string, unknown>;
|
||||
return typeof o.name === 'string' && typeof o.description === 'string';
|
||||
})
|
||||
.map((v) => ({
|
||||
name: v.name,
|
||||
description: v.description,
|
||||
...(typeof v.kcalDelta === 'number' ? { kcalDelta: v.kcalDelta } : {}),
|
||||
}));
|
||||
}
|
||||
|
||||
function RecipeContent({ recipe }: { recipe: RecipeView }) {
|
||||
const t = useTranslations('Recipe');
|
||||
const phasesAll = recipe.phases.length === 3;
|
||||
@@ -149,6 +174,11 @@ function RecipeContent({ recipe }: { recipe: RecipeView }) {
|
||||
<p className="text-ink-soft mt-1 font-mono text-[10px] uppercase tracking-widest">
|
||||
{ing.category}
|
||||
</p>
|
||||
{ing.substitutes.length > 0 ? (
|
||||
<p className="font-display text-ink-dim mt-1 text-xs italic leading-snug">
|
||||
{t('substitutesPrefix')} {ing.substitutes.join(', ')}
|
||||
</p>
|
||||
) : null}
|
||||
</div>
|
||||
<span className="text-ink font-mono text-sm tabular-nums">
|
||||
{formatQuantity(ing.quantity)} {ing.unit}
|
||||
@@ -190,6 +220,33 @@ function RecipeContent({ recipe }: { recipe: RecipeView }) {
|
||||
</aside>
|
||||
) : null}
|
||||
</section>
|
||||
|
||||
{recipe.variants.length > 0 ? (
|
||||
<>
|
||||
<div className="rule animate-rule-in my-12" />
|
||||
<section className="space-y-6">
|
||||
<p className="editorial-eyebrow">{t('variantsTitle')}</p>
|
||||
<ul className="grid gap-6 sm:grid-cols-2">
|
||||
{recipe.variants.map((v, i) => (
|
||||
<li key={i} className="border-ink/15 border p-5">
|
||||
<p className="font-display text-ink text-lg font-medium leading-tight">
|
||||
{v.name}
|
||||
</p>
|
||||
<p className="font-display text-ink-soft mt-2 text-base italic leading-snug">
|
||||
{v.description}
|
||||
</p>
|
||||
{v.kcalDelta != null ? (
|
||||
<p className="text-ink-dim mt-2 font-mono text-[10px] uppercase tracking-widest">
|
||||
{v.kcalDelta > 0 ? '+' : ''}
|
||||
{v.kcalDelta} kcal
|
||||
</p>
|
||||
) : null}
|
||||
</li>
|
||||
))}
|
||||
</ul>
|
||||
</section>
|
||||
</>
|
||||
) : null}
|
||||
</main>
|
||||
|
||||
<div className="rule-thick mt-16" />
|
||||
|
||||
Reference in new issue
Block a user