fix(fitness): include today in exercise kcal projection
CI / update (push) Successful in 3m41s

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.
This commit is contained in:
2026-04-21 12:59:31 +02:00
parent 5b7f23b8be
commit 8dbd793acd
2 changed files with 5 additions and 7 deletions
+1 -1
View File
@@ -1,6 +1,6 @@
{ {
"name": "homepage", "name": "homepage",
"version": "1.41.0", "version": "1.41.1",
"private": true, "private": true,
"type": "module", "type": "module",
"scripts": { "scripts": {
@@ -15,7 +15,7 @@ export const load: PageServerLoad = async ({ fetch, params, locals }) => {
const dayStart = new Date(dateParam + 'T00:00:00.000Z'); const dayStart = new Date(dateParam + 'T00:00:00.000Z');
const dayEnd = new Date(dateParam + 'T23:59:59.999Z'); const dayEnd = new Date(dateParam + 'T23:59:59.999Z');
const todayStr = new Date().toISOString().slice(0, 10); const todayStr = new Date().toISOString().slice(0, 10);
const isFuture = dateParam > todayStr; const isTodayOrFuture = dateParam >= todayStr;
const exercisePromise = (async () => { const exercisePromise = (async () => {
try { try {
@@ -26,16 +26,16 @@ export const load: PageServerLoad = async ({ fetch, params, locals }) => {
createdBy: user.nickname, createdBy: user.nickname,
startTime: { $gte: dayStart, $lte: dayEnd } startTime: { $gte: dayStart, $lte: dayEnd }
}).select('kcalEstimate').lean(), }).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; let kcal = 0;
for (const s of sessions) { for (const s of sessions) {
if (s.kcalEstimate?.kcal) kcal += s.kcalEstimate.kcal; 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; let projected = null;
if (kcal === 0 && isFuture) { if (kcal === 0 && isTodayOrFuture) {
if (schedule?.templateOrder?.length) { if (schedule?.templateOrder?.length) {
const lastScheduled = await WorkoutSession.findOne({ const lastScheduled = await WorkoutSession.findOne({
createdBy: user.nickname, createdBy: user.nickname,
@@ -147,8 +147,6 @@ export const load: PageServerLoad = async ({ fetch, params, locals }) => {
const projectedExercise = exerciseData.projected; const projectedExercise = exerciseData.projected;
// Compute initial showRoundOff server-side to avoid flicker // Compute initial showRoundOff server-side to avoid flicker
const today = new Date().toISOString().slice(0, 10);
const isTodayOrFuture = dateParam >= today;
let initialShowRoundOff = false; let initialShowRoundOff = false;
if (isTodayOrFuture && goal.dailyCalories) { if (isTodayOrFuture && goal.dailyCalories) {
const totalCal = (foodLog.entries ?? []).reduce( const totalCal = (foodLog.entries ?? []).reduce(