Skip to content

Subtract dietary fiber caloric contribution from calorie target before calculating macro targets - #1531

Merged
CodeWithCJ merged 4 commits into
mainfrom
dev
Jun 14, 2026
Merged

Subtract dietary fiber caloric contribution from calorie target before calculating macro targets#1531
CodeWithCJ merged 4 commits into
mainfrom
dev

Conversation

@CodeWithCJ

@CodeWithCJ CodeWithCJ commented Jun 14, 2026

Copy link
Copy Markdown
Owner

Tip

Help us review and merge your PR faster!
Please ensure you have completed the Checklist below.
For Frontend changes, please run pnpm run validate to check for any errors.
PRs that include tests and clear screenshots are highly preferred!
Note: AI-generated descriptions must be manually edited for conciseness. Do not paste raw AI summaries.

Description

What problem does this PR solve?
(Keep it concise. 1–2 sentences.)

Deducts dietary fiber calories (2 kcal/g) from the daily calorie goal before applying percentage-based macro splits across onboarding, food goals, presets, and backend services.

How did you implement the solution?
(Brief technical approach.)

Updated the percentage-to-gram calculators across both the frontend (onboarding, daily goals, presets, previews) and backend (goal services) to deduct dietary_fiber * 2 from the total calorie pool before dividing the remaining budget into protein, carb, and fat targets.

Linked Issue: Closes # #1509

How to Test

  1. Check out this branch and run ...
  2. Navigate to...
  3. Verify that...

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.

Screenshots

Click to expand

Before

before

After

after

Notes for Reviewers

Optional — use this for anything that doesn't fit above: known tradeoffs, areas you'd like specific feedback on, qustions you have or context that helps reviewers.

…e calculating macro targets

Description: Deducts dietary fiber calories (2 kcal/g) from the daily calorie goal before applying percentage-based macro splits across onboarding, food goals, presets, and backend services.
@github-actions

github-actions Bot commented Jun 14, 2026

Copy link
Copy Markdown

PR Validation Results

Change Detection

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

⚠️ Recommendations (2)

  • Please select a PR type (Issue, New Feature, Refactor, or Documentation).
  • 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 updates the macronutrient calculations across the frontend and backend to adjust the total calories by subtracting the energy contribution of dietary fiber (calculated as fiber grams multiplied by 2) before computing macro percentages or grams. The review feedback highlights two key areas for improvement: first, in NutrientGoals.tsx, using Math.max(1, ...) as a divisor can lead to abnormally high percentages if adjusted calories are near zero, so it is safer to conditionally divide only when adjusted calories are positive; second, in the backend services, defensive checks should be added to handle cases where calories might be undefined or non-numeric to prevent NaN propagation.

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 SparkyFitnessFrontend/src/components/Onboarding/NutrientGoals.tsx Outdated
Comment thread SparkyFitnessFrontend/src/components/Onboarding/NutrientGoals.tsx Outdated
Comment thread SparkyFitnessFrontend/src/components/Onboarding/NutrientGoals.tsx Outdated
Comment thread SparkyFitnessServer/services/goalService.ts
Comment thread SparkyFitnessServer/services/goalPresetService.ts
CodeWithCJ and others added 3 commits June 14, 2026 16:04
Co-authored-by: gemini-code-assist[bot] <176961590+gemini-code-assist[bot]@users.noreply.github.com>
Co-authored-by: gemini-code-assist[bot] <176961590+gemini-code-assist[bot]@users.noreply.github.com>
@CodeWithCJ
CodeWithCJ merged commit 2ab2d1f into main Jun 14, 2026
7 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant