From 8dbd793acdddff7c048b4485c841c3fdb7e0e39a Mon Sep 17 00:00:00 2001 From: Alexander Bocken Date: Tue, 21 Apr 2026 12:59:31 +0200 Subject: [PATCH] fix(fitness): include today in exercise kcal projection The projection gate required the date to be strictly after today, so the current day never showed a projected burn even before any workout had been logged. Loosened to >= today and removed a now-duplicate isTodayOrFuture/today declaration introduced by the earlier round-off flicker fix. --- package.json | 2 +- .../[[date=fitnessDate]]/+page.server.ts | 10 ++++------ 2 files changed, 5 insertions(+), 7 deletions(-) diff --git a/package.json b/package.json index 25b25f3f..5d7186d8 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "homepage", - "version": "1.41.0", + "version": "1.41.1", "private": true, "type": "module", "scripts": { diff --git a/src/routes/fitness/[nutrition=fitnessNutrition]/[[date=fitnessDate]]/+page.server.ts b/src/routes/fitness/[nutrition=fitnessNutrition]/[[date=fitnessDate]]/+page.server.ts index 73c6f62b..954e8fdc 100644 --- a/src/routes/fitness/[nutrition=fitnessNutrition]/[[date=fitnessDate]]/+page.server.ts +++ b/src/routes/fitness/[nutrition=fitnessNutrition]/[[date=fitnessDate]]/+page.server.ts @@ -15,7 +15,7 @@ export const load: PageServerLoad = async ({ fetch, params, locals }) => { const dayStart = new Date(dateParam + 'T00:00:00.000Z'); const dayEnd = new Date(dateParam + 'T23:59:59.999Z'); const todayStr = new Date().toISOString().slice(0, 10); - const isFuture = dateParam > todayStr; + const isTodayOrFuture = dateParam >= todayStr; const exercisePromise = (async () => { try { @@ -26,16 +26,16 @@ export const load: PageServerLoad = async ({ fetch, params, locals }) => { createdBy: user.nickname, startTime: { $gte: dayStart, $lte: dayEnd } }).select('kcalEstimate').lean(), - isFuture ? WorkoutSchedule.findOne({ userId: user.nickname }).lean() : Promise.resolve(null) + isTodayOrFuture ? WorkoutSchedule.findOne({ userId: user.nickname }).lean() : Promise.resolve(null) ]); let kcal = 0; for (const s of sessions) { if (s.kcalEstimate?.kcal) kcal += s.kcalEstimate.kcal; } - // For future days without exercise, project kcal from the next scheduled template + // For today or future days without logged exercise, project kcal from the next scheduled template let projected = null; - if (kcal === 0 && isFuture) { + if (kcal === 0 && isTodayOrFuture) { if (schedule?.templateOrder?.length) { const lastScheduled = await WorkoutSession.findOne({ createdBy: user.nickname, @@ -147,8 +147,6 @@ export const load: PageServerLoad = async ({ fetch, params, locals }) => { const projectedExercise = exerciseData.projected; // Compute initial showRoundOff server-side to avoid flicker - const today = new Date().toISOString().slice(0, 10); - const isTodayOrFuture = dateParam >= today; let initialShowRoundOff = false; if (isTodayOrFuture && goal.dailyCalories) { const totalCal = (foodLog.entries ?? []).reduce(