Skip to content

Use adjusted calorie goal for summary and per meal targets - #1543

Merged
CodeWithCJ merged 4 commits into
CodeWithCJ:mainfrom
gPinato:update-per-meal-diary
Jun 18, 2026
Merged

Use adjusted calorie goal for summary and per meal targets#1543
CodeWithCJ merged 4 commits into
CodeWithCJ:mainfrom
gPinato:update-per-meal-diary

Conversation

@gPinato

@gPinato gPinato commented Jun 15, 2026

Copy link
Copy Markdown

Description

What problem does this PR solve?

The Diary page shows inconsistent calorie and macro goals: the Daily Energy Goal widget displays the TDEE-adjusted value but the Nutrition Summary and per-meal targets (Breakfast, Lunch, Dinner, Snacks) still use the raw stored goal. This makes the page contradict itself when Adaptive TDEE or goal mode adjustments are active.

How did you implement the solution?

The server already computes adjusted goals internally via goalService.getUserGoals(..., true) but never exposed them in the API response. This PR adds an adjustedGoals field (nullable) to the daily summary response containing the adjusted calories and macros. The web and mobile frontends use this field to display consistent targets across all diary components.

How to Test

  1. Set calorie goal adjustment mode to Adaptive TDEE in Settings → Calculation Settings
  2. Ensure sufficient weight + intake data for Adaptive TDEE to compute (28 days)
  3. Navigate to the Diary page
  4. Verify the Nutrition Summary calorie goal matches the Daily Energy Goal widget
  5. Verify per-meal targets (Breakfast, Lunch, Dinner, Snacks) sum to the adjusted total
  6. Verify protein, carbs, and fat goals are scaled proportionally
  7. Switch to a non-adaptive mode (e.g. Fixed) and confirm everything reverts to raw stored goals

PR Type

  • Issue (bug fix)
  • New Feature
  • Refactor
  • Documentation

Checklist

All PRs:

  • [MANDATORY - ALL] Integrity & License: I certify this is my own work, free of malicious code, and I agree to the License terms.

New features only:

  • [] [MANDATORY for new feature] Alignment: I have raised a GitHub issue and it was reviewed/approved by maintainers or it was approved on Discord.

Frontend changes (SparkyFitnessFrontend/):

  • [MANDATORY for Frontend changes] Quality: I have run pnpm run validate and it passes.
  • [MANDATORY for Frontend changes] Translations: I have only updated the English (en) translation file.

Backend changes (SparkyFitnessServer/):

  • [MANDATORY for Backend changes] Code Quality: I have run typecheck, lint, and tests. New files use TypeScript, new endpoints have Zod schemas, and new endpoints include tests.
  • [MANDATORY for Backend changes] Database Security: I have updated rls_policies.sql for any new user-specific tables.

UI changes (components, screens, pages):

  • [MANDATORY for UI changes] Screenshots: I have attached Before/After screenshots below.

Mobile changes (SparkyFitnessMobile/):

  • [MANDATORY for Mobile changes] Tested on device or emulator: I have verified the changes work on iOS or Android.

Notes for Reviewers

  • adjustedGoals is a nullable field on the existing /daily-summary response — no new endpoints or DB changes
  • The field is null when raw and adjusted goals are identical (no adjustment active) — fully backward-compatible
  • The server leverages the existing goalService.getUserGoals(..., true) call that was already being made — we just compare it against the raw call and expose the difference to clients
  • The web frontend calls useDailySummary from Diary.tsx which hits the react-query cache (DailyProgress already fetches it) — no extra network request
  • 2 new unit tests cover: null when no adjustment, and correct values when goalService returns different adjusted goals

Giacomo Pinato and others added 3 commits June 15, 2026 13:05
The Nutrition Summary panel showed the raw stored calorie goal while
the Daily Energy Goal widget showed the TDEE-adjusted value — causing
inconsistent targets on the same Diary page. Compute adjusted macros
server-side (percentage-based when available, proportional fallback
otherwise) and expose them in the daily summary response.

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
DiaryTopControls now reads adjustedGoals from the cached daily summary
and overlays the TDEE-adjusted calorie and macro targets so both panels
show consistent values.

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
Prefer adjustedGoals from the API response for protein, carbs, and fat
targets so the mobile dashboard stays consistent with the TDEE-adjusted
calorie goal.

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
@github-actions github-actions Bot added backend bug Something isn't working frontend mobile labels Jun 15, 2026
@github-actions

github-actions Bot commented Jun 15, 2026

Copy link
Copy Markdown

PR Validation Results

Change Detection

  • 🖥️ Frontend changes detected
  • ⚙️ Backend changes detected
  • 📱 Mobile changes detected

⚠️ Recommendations (1)

  • Please link a related GitHub issue (Linked Issue: Closes #123).

✅ All required checks passed.

@gemini-code-assist gemini-code-assist Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Code Review

This pull request introduces support for adjusted nutritional goals across the web frontend, mobile app, and backend server. It fetches and applies adjustedGoals when they differ from raw goals, ensuring that users see dynamically adjusted targets. The review feedback highlights a few key issues: the mobile hook extracts adjustedGoals but fails to use them in the top-level calorie calculations; the web frontend does not include the loading state of the daily summary hook in its page loading check, potentially causing layout shifts; and the backend service uses any types and complex parsing logic that can be simplified for better type safety.

Important

The consumer version of Gemini Code Assist on GitHub is being sunset. Starting June 18, 2026, new organization installations will be blocked, and all code review activity will officially cease on July 17, 2026.
For more details on the timeline and next steps, please review the Help Documentation.

Comment thread SparkyFitnessMobile/src/hooks/useDailySummary.ts Outdated
Comment thread SparkyFitnessFrontend/src/pages/Diary/Diary.tsx Outdated
Comment thread SparkyFitnessServer/services/dailySummaryService.ts Outdated
Lift the adjustedGoals logic from DiaryTopControls into Diary.tsx so
both the Nutrition Summary and the per-meal cards (Breakfast, Lunch,
Dinner, Snacks) use the same TDEE-adjusted calorie goal for their
target calculations.

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
@gPinato
gPinato force-pushed the update-per-meal-diary branch from 42ca905 to 13bc825 Compare June 17, 2026 07:09
@CodeWithCJ
CodeWithCJ merged commit 5063632 into CodeWithCJ:main Jun 18, 2026
7 of 8 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants