consistent weight display format in frontend#856
Conversation
Summary of ChangesHello, 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
Changelog
Using Gemini Code AssistThe 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
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 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
|
There was a problem hiding this comment.
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.
| 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) | ||
| ); |
There was a problem hiding this comment.
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.
Tip
Help us review and merge your PR faster!
Please ensure you have completed the Checklist below.
For Frontend changes, please run
pnpm run validateto 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:
pnpm run validate(especially for Frontend).en) translation file (if applicable).rls_policies.sqlfor any new user-specific tables.Screenshots (if applicable)
Before
[Insert screenshot/GIF here]
After
[Insert screenshot/GIF here]