Skip to content

790/food goals bug - #807

Open
ChaoticallyAlys wants to merge 6 commits into
devfrom
790/food-goals-bug
Open

ChaoticallyAlys wants to merge 6 commits into
devfrom
790/food-goals-bug

Conversation

@ChaoticallyAlys

@ChaoticallyAlys ChaoticallyAlys commented Nov 24, 2026 •

Copy link
Copy Markdown
Contributor

Summary

User edits are reflected once clicking out of the text box editor (onBlur()), so the user can type freely.

  • Originally added a delay so that the user’s changes are reflected immediately when typing, but because all the constraints are checked immediately upon change, the user is restricted from typing the value they want (e.g., trying to delete 1300 in the Calories goal will stop at 130, because the schema requires a value of >= 100).

Values are recalculated so that they scale according to user changes.
Notifications pop up if user input is out of range.

Changes

nutrition-goals.tsx

  • User can edit text boxes freely

  • Clicking out of text boxes immediately recalculates the new goals to keep the values balanced (ex: if a user has a goal of 200 calories, changing to a goal with 30 grams of protein, 500 grams of carbs, and 20 grams of fat should result in a calorie count of 2300 automatically)
    Calories Formula: protein * 4 + carbs * 4 + fat * 9 = calories
    When Calories change: All three macros scale by the same percentage (ex: increasing Calories by 20% → increases Protein, Carbs, and Fat by 20%)
    When a Macro changes: Calories automatically adjust based on the change (ex: decreasing Protein by 1 → decreases Calories by 4)

  • Validates goals twice to account for two situations:
    Before recalculation → user could’ve entered bad input
    After recalculation → there is a possibility that recalculation results in Calories < 100

  • Updates the goals to reflect user changes & calculations

  • Added Snackbar pop ups to notify user

peterplate/nutrition.ts

  • Converted goal limits validation to a reusable schema

nutrition/router.ts

  • Imported NutritionGoalsSchema to reuse for validation

layout-client.tsx

  • Prevented closing of notification once clicking out of goals editor

Testing Instructions

NOTE: Because changes scale proportionally, at low and high values the formula doesn’t match due to rounding to the nearest integer.

Test the items below for both Mobile and Desktop view for EACH goal:

  • Editing in the text box without clicking out of it shows no changes

  • Editing and clicking out of the text box reflects the saved change

  • Editing in the text box without clicking out of it but navigating to another page, then navigating back, reflects the saved change

  • Can type freely in the text box (enter no value, negative values, extremely large values > 10000)

  • Clicking out of text box results in correct notification of input error

    • Cal < 100 → “Calories must be at least 100”
    • Cal > 10000 → “Calories cannot exceed 10,000”
    • Protein < 1 → “Protein must be at least 1”
    • Protein > 500 → “Protein cannot exceed 500”
    • Carbs < 1 → “Carbs must be at least 1”
    • Carbs > 1000 → “Carbs cannot exceed 1,000”
    • Fat < 1 → “Fat must be at least 1”
    • Fat > 500 → “Fat cannot exceed 500”
    • Trying to make all macros < 100 Calories → “Changing [MACROS] results in [CAL<100] Calories. Calories must be at least 100.”
  • Editing each macros increases/decreases Calories proportionally. Editing:
    Protein changes in proportions of *4
    Carbs changes in proportions of *4
    Fat changes in proportions of *9

  • Editing Calories increases/decreases macros proportionally (e.g., decreasing Calories by 20% → decreases all macros by 20%)

Closes #790

This branch was previously deployed

1 inactive deployment
staging-807 — 929fc94d Deployed Nov 24, 2026 by github-actions[bot]
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant