From 53f803c04cae7d47cb602a165999f4dc8af87835 Mon Sep 17 00:00:00 2001 From: Alexander Bocken Date: Tue, 21 Apr 2026 07:45:12 +0200 Subject: [PATCH] fix(fitness): only show projected kcal on future days in nutrition Past and today return projectedExercise=null, so the estimate no longer appears on days where the user could have just skipped a workout. Also skips the WorkoutSchedule lookup when not needed. --- package.json | 2 +- .../[[date=fitnessDate]]/+page.server.ts | 9 +++++---- 2 files changed, 6 insertions(+), 5 deletions(-) diff --git a/package.json b/package.json index a8884696..c23f9488 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "homepage", - "version": "1.37.3", + "version": "1.37.4", "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 e7bdcc0b..73c6f62b 100644 --- a/src/routes/fitness/[nutrition=fitnessNutrition]/[[date=fitnessDate]]/+page.server.ts +++ b/src/routes/fitness/[nutrition=fitnessNutrition]/[[date=fitnessDate]]/+page.server.ts @@ -14,6 +14,8 @@ export const load: PageServerLoad = async ({ fetch, params, locals }) => { // Run all independent work in parallel: 3 API calls + workout kcal DB query 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 exercisePromise = (async () => { try { @@ -24,16 +26,16 @@ export const load: PageServerLoad = async ({ fetch, params, locals }) => { createdBy: user.nickname, startTime: { $gte: dayStart, $lte: dayEnd } }).select('kcalEstimate').lean(), - WorkoutSchedule.findOne({ userId: user.nickname }).lean() + isFuture ? 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; } - // If no exercise done today, project kcal from the next scheduled template + // For future days without exercise, project kcal from the next scheduled template let projected = null; - if (kcal === 0) { + if (kcal === 0 && isFuture) { if (schedule?.templateOrder?.length) { const lastScheduled = await WorkoutSession.findOne({ createdBy: user.nickname, @@ -71,7 +73,6 @@ export const load: PageServerLoad = async ({ fetch, params, locals }) => { const recentFrom = new Date(); recentFrom.setDate(recentFrom.getDate() - 3); const recentFromStr = recentFrom.toISOString().slice(0, 10); - const todayStr = new Date().toISOString().slice(0, 10); const [foodRes, goalRes, weightRes, exerciseData, favRes, recentRes] = await Promise.all([ fetch(`/api/fitness/food-log?date=${dateParam}`),