Skip to content

consistent weight display format in frontend#856

Merged
CodeWithCJ merged 1 commit intomainfrom
dev
Mar 7, 2026
Merged

consistent weight display format in frontend#856
CodeWithCJ merged 1 commit intomainfrom
dev

Conversation

@CodeWithCJ
Copy link
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!

Description

Provide a brief summary of your changes.

Related Issue

PR type [x] Issue [ ] New Feature [ ] Documentation
Linked Issue: # #792

Checklist

Please check all that apply:

  • [MANDATORY for new feature] Alignment: I have raised a GitHub issue and it was reviewed/approved by maintainers
  • Tests: I have included automated tests for my changes.
  • [MANDATORY for UI changes] Screenshots: I have attached "Before" vs "After" screenshots below.
  • [MANDATORY for Frontend changes] Quality: I have run pnpm run validate (especially for Frontend).
  • Translations: I have only updated the English (en) translation file (if applicable).
  • Architecture: My code follows the existing architecture standards.
  • Database Security: I have updated rls_policies.sql for any new user-specific tables.
  • [MANDATORY - ALL] Integrity & License: I certify this is my own work, free of malicious code(phishing, malware, etc.) and I agree to the License terms.

Screenshots (if applicable)

Before

[Insert screenshot/GIF here]

After

[Insert screenshot/GIF here]

@CodeWithCJ CodeWithCJ merged commit b208377 into main Mar 7, 2026
2 checks passed
@gemini-code-assist
Copy link
Contributor

Summary of Changes

Hello, I'm Gemini Code Assist1! I'm currently reviewing this pull request and will post my feedback shortly. In the meantime, here's a summary to help you and other reviewers quickly get up to speed!

This pull request refines the frontend's handling and display of weight-related data. The primary goal is to ensure a uniform presentation of weight values, typically to one decimal place, across all user interfaces. This includes updates to exercise logging, daily progress tracking, and various reporting charts, leading to a more polished and consistent user experience when interacting with weight metrics.

Highlights

  • Consistent Weight Display Precision: Standardized the display of weight values across various frontend components to one decimal place (e.g., 100.5kg instead of 100.50kg), improving visual consistency.
  • Enhanced Weight Unit Conversion: Ensured that weight values are consistently converted to the user's preferred unit and then formatted to one decimal place before display or further calculation, particularly in exercise history, daily progress, and workout logging dialogs.
  • Improved Reporting Chart Readability: Updated exercise reports and PR progression charts to correctly format Y-axis ticks and tooltip values with the user's selected weight unit and one decimal place, making the data easier to interpret.
  • Accurate Weight Calculations in Reports: Adjusted the calculation of exercise volume, max weight, and estimated 1RM in reports to apply weight unit conversion and consistent decimal precision, ensuring accuracy in displayed metrics.
Changelog
  • SparkyFitnessFrontend/src/components/ExerciseHistoryDisplay.tsx
    • Updated weight display to show one decimal place instead of two.
  • SparkyFitnessFrontend/src/pages/Diary/DailyProgress.tsx
    • Adjusted weight trend display to show one decimal place.
  • SparkyFitnessFrontend/src/pages/Diary/EditExerciseEntryDialog.tsx
    • Applied one-decimal-place formatting to converted weight values when editing exercise entries.
  • SparkyFitnessFrontend/src/pages/Diary/LogExerciseEntryDialog.tsx
    • Applied one-decimal-place formatting to converted weight values when logging new exercise entries.
  • SparkyFitnessFrontend/src/pages/Exercises/AddWorkoutPlanDialog.tsx
    • Formatted converted weight values to one decimal place during workout plan creation.
  • SparkyFitnessFrontend/src/pages/Exercises/WorkoutPresetForm.tsx
    • Formatted converted weight values to one decimal place in the workout preset form.
  • SparkyFitnessFrontend/src/pages/Reports/ExerciseReportsDashboard.tsx
    • Modified volume calculation to use convertWeight and toFixed(1) for consistent precision.
    • Updated max weight calculation to apply convertWeight and toFixed(1) before determining the maximum.
    • Added tickFormatter to Y-axis and formatter to Tooltip for max weight chart to display formatted weight values.
    • Adjusted estimated 1RM calculation to apply convertWeight and toFixed(1) to the calculated 1RM.
    • Added tickFormatter to Y-axis and formatter to Tooltip for estimated 1RM chart to display formatted weight values.
  • SparkyFitnessFrontend/src/pages/Reports/PrProgressionChart.tsx
    • Imported formatWeight utility for consistent number formatting.
    • Destructured weightUnit and convertWeight from usePreferences for use in chart formatting.
    • Applied convertWeight and toFixed(1) to oneRM and maxWeight data points for consistent display.
    • Added tickFormatter to Y-axis and updated Y-axis label to reflect the user's weight unit.
    • Implemented a formatter for the Tooltip to display weight values with formatWeight and the correct weightUnit.
Using Gemini Code Assist

The full guide for Gemini Code Assist can be found on our documentation page, here are some quick tips.

Invoking Gemini

You can request assistance from Gemini at any point by creating a comment using either /gemini <command> or @gemini-code-assist <command>. Below is a summary of the supported commands on the current page.

Feature Command Description
Code Review /gemini review Performs a code review for the current pull request in its current state.
Pull Request Summary /gemini summary Provides a summary of the current pull request in its current state.
Comment @gemini-code-assist Responds in comments when explicitly tagged, both in pull request comments and review comments.
Help /gemini help Displays a list of available commands.

Customization

To customize Gemini Code Assist for GitHub experience, repository maintainers can create a configuration file and/or provide a custom code review style guide (such as PEP-8 for Python) by creating and adding files to a .gemini/ folder in the base of the repository. Detailed instructions can be found here.

Limitations & Feedback

Gemini Code Assist may make mistakes. Please leave feedback on any instances where its feedback is incorrect or counter productive. You can react with 👍 and 👎 on @gemini-code-assist comments. If you're interested in giving your feedback about your experience with Gemini Code Assist for Github and other Google products, sign up here.

You can also get AI-powered code generation, chat, as well as code reviews directly in the IDE at no cost with the Gemini Code Assist IDE Extension.

Footnotes

  1. Review the Privacy Notices, Generative AI Prohibited Use Policy, Terms of Service, and learn how to configure Gemini Code Assist in GitHub here. Gemini can make mistakes, so double check it and use code with caution.

Copy link
Contributor

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

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 successfully standardizes the weight display format to one decimal place across the frontend, which improves consistency. More importantly, it fixes several bugs in the reporting components by correctly converting weight-based metrics to the user's preferred unit before aggregation and display. The changes are well-implemented. I've added one suggestion for refactoring in ExerciseReportsDashboard.tsx to reduce code duplication and improve maintainability.

Comment on lines +544 to 550
const currentVolume = entry.sets.reduce(
(sum, set) => sum + set.reps * set.weight,
0
);
existingEntry.volume += parseFloat(
formatWeight(
entry.sets.reduce(
(sum, set) => sum + set.reps * set.weight,
0
)
)
convertWeight(currentVolume, 'kg', weightUnit).toFixed(1)
);
Copy link
Contributor

Choose a reason for hiding this comment

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

medium

To improve maintainability and reduce code duplication, you could extract the logic for calculating and converting report metrics into helper functions. This pattern of calculating a value and then converting it is repeated for volumeTrend, maxWeightTrend, and estimated1RMTrend, for both the main data and the comparison data.

For example, for volumeTrend, you could define a helper function:

const getConvertedVolume = (entry: ExerciseProgressData): number => {
  const volume = entry.sets.reduce(
    (sum, set) => sum + set.reps * set.weight,
    0
  );
  return parseFloat(convertWeight(volume, 'kg', weightUnit).toFixed(1));
};

And then use it like this:

existingEntry.volume += getConvertedVolume(entry);
// ...
if (comparisonEntry) {
  existingEntry.comparisonVolume += getConvertedVolume(comparisonEntry);
}

A similar approach can be taken for maxWeightTrend and estimated1RMTrend. For maxWeight and 1RM calculations using Math.max, consider adding a guard for empty sets arrays to prevent issues with -Infinity.

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