feat: piano sensibile al protocollo digiuno (PRD §5.6 + §9.4)
Finora il fastingProtocol era una preferenza salvata ma ignorata dal
planner — ogni giorno generava 4 pasti. Ora cambia struttura per protocollo
e per giorno della settimana.
@ketopath/shared/planner
- protocolPlanForDay(protocol, dayOfWeek) → { share, kcalMultiplier }
- 14:10 → tutti e 4 i pasti, share default
- 16:8 → niente colazione: pranzo 50%, spuntino 10%, cena 40%
- 18:6 → niente colazione: pranzo 55%, spuntino 5%, cena 40%
- 20:4 → solo spuntino+cena (10/90)
- ESE 24h → mercoledì kcalMultiplier=0 (giorno saltato), altri default
- 5:2 → lunedì + giovedì kcalMultiplier=0.25, share 100% cena
- 7 unit test in protocol.test.ts
apps/api/plan
- POST /me/meal-plans: legge preferences.fastingProtocol, deriva il piano
per ogni giorno, salta MealSlot con share=0 e giorni a kcalMultiplier=0
- GET /me/meal-plans/current: include fastingProtocol nella risposta
- baseDailyTarget restituito invariato per il client
apps/web
- /plan mostra "Finestra alimentare 16:8" sotto il titolo della settimana
- plan-week distingue i giorni "fasting" (digiuno completo) e "leggeri"
(5:2 fasting day) con copy dedicato; rimuove totali calorici inappropriati
- i18n: Plan.protocolLabel + Plan.fastingDay/lightDay
Smoke tested: settato 16:8 da /profile, rigenerato il piano, verificato
che l'etichetta appaia e che ogni giorno abbia esattamente 3 pasti
(Pranzo / Spuntino / Cena, niente Colazione).
Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
This commit is contained in:
1 parent
ded4215664
commit
feb54c1f9a
7 files changed
+258
-25
No files matched your search
@@ -25,6 +25,14 @@ export interface CurrentPlan {
|
||||
id: string;
|
||||
weekStart: string;
|
||||
slots: PlanSlot[];
|
||||
fastingProtocol:
|
||||
| 'FOURTEEN_TEN'
|
||||
| 'SIXTEEN_EIGHT'
|
||||
| 'EIGHTEEN_SIX'
|
||||
| 'TWENTY_FOUR'
|
||||
| 'ESE_24'
|
||||
| 'FIVE_TWO'
|
||||
| null;
|
||||
}
|
||||
|
||||
function cookieHeader(): string {
|
||||
|
||||
@@ -62,6 +62,14 @@ function PlanPageContent({ plan }: { plan: Awaited<ReturnType<typeof fetchCurren
|
||||
<p className="font-display text-ink-soft animate-fade-up mt-5 max-w-2xl text-xl italic leading-snug [animation-delay:240ms]">
|
||||
{plan ? formatWeek(plan.weekStart) : t('noPlan')}
|
||||
</p>
|
||||
{plan?.fastingProtocol ? (
|
||||
<p className="animate-fade-up mt-4 [animation-delay:300ms]">
|
||||
<span className="editorial-eyebrow">{t('window')}</span>{' '}
|
||||
<span className="font-display text-pomodoro ml-2 text-base italic">
|
||||
{t(`protocolLabel.${plan.fastingProtocol}`)}
|
||||
</span>
|
||||
</p>
|
||||
) : null}
|
||||
</div>
|
||||
<div className="animate-fade-up flex flex-col items-stretch gap-3 [animation-delay:360ms] md:col-span-4 md:items-end">
|
||||
<form action={regeneratePlan}>
|
||||
|
||||
@@ -36,6 +36,11 @@ export function PlanWeek({ plan }: { plan: CurrentPlan }) {
|
||||
(a, b) => MEAL_ORDER.indexOf(a.meal) - MEAL_ORDER.indexOf(b.meal),
|
||||
);
|
||||
const dayKcal = slots.reduce((sum, s) => sum + (s.selected?.kcal ?? 0), 0);
|
||||
// Nessuno slot → giorno di digiuno completo (ESE_24).
|
||||
const isFastingDay = slots.length === 0;
|
||||
// Solo CENA con dailyKcal ridotto → giorno "leggero" del 5:2.
|
||||
const isLightDay = !isFastingDay && slots.length === 1 && slots[0].meal === 'CENA';
|
||||
|
||||
return (
|
||||
<section key={dayKey} aria-labelledby={`day-${dayKey}`} className="space-y-5">
|
||||
<header className="border-ink/15 grid items-baseline gap-2 border-b pb-3 sm:grid-cols-[auto_1fr_auto]">
|
||||
@@ -47,16 +52,31 @@ export function PlanWeek({ plan }: { plan: CurrentPlan }) {
|
||||
className="font-display text-ink text-2xl font-medium leading-none tracking-tight sm:text-3xl"
|
||||
>
|
||||
{t(`days.${dayKey}`)}
|
||||
{isFastingDay ? (
|
||||
<span className="font-display text-ink-dim ml-3 text-base italic">
|
||||
· {t('fastingDay')}
|
||||
</span>
|
||||
) : isLightDay ? (
|
||||
<span className="font-display text-ink-dim ml-3 text-base italic">
|
||||
· {t('lightDay')}
|
||||
</span>
|
||||
) : null}
|
||||
</h2>
|
||||
<span className="text-ink-soft font-mono text-[11px] uppercase tracking-widest">
|
||||
{t('dayTotal', { kcal: Math.round(dayKcal) })}
|
||||
{isFastingDay ? '— kcal' : t('dayTotal', { kcal: Math.round(dayKcal) })}
|
||||
</span>
|
||||
</header>
|
||||
<div className="divide-ink/10 grid grid-cols-1 divide-y sm:grid-cols-2 sm:gap-x-8 sm:divide-y-0 lg:grid-cols-4 lg:gap-x-6">
|
||||
{slots.map((slot, slotIdx) => (
|
||||
<SlotCard key={slot.id} slot={slot} index={slotIdx} />
|
||||
))}
|
||||
</div>
|
||||
{isFastingDay ? (
|
||||
<p className="font-display text-ink-soft text-base italic leading-snug">
|
||||
{t('fastingDayHint')}
|
||||
</p>
|
||||
) : (
|
||||
<div className="divide-ink/10 grid grid-cols-1 divide-y sm:grid-cols-2 sm:gap-x-8 sm:divide-y-0 lg:grid-cols-4 lg:gap-x-6">
|
||||
{slots.map((slot, slotIdx) => (
|
||||
<SlotCard key={slot.id} slot={slot} index={slotIdx} />
|
||||
))}
|
||||
</div>
|
||||
)}
|
||||
</section>
|
||||
);
|
||||
})}
|
||||
|
||||
Reference in new issue
Block a user