Skip to content

Commit b208377

Browse files
authored
Merge pull request #856 from CodeWithCJ/dev
consistent weight display format in frontend
2 parents 38877bb + 4c34f39 commit b208377

8 files changed

Lines changed: 85 additions & 34 deletions

File tree

SparkyFitnessFrontend/src/components/ExerciseHistoryDisplay.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -94,7 +94,7 @@ const ExerciseHistoryDisplay: React.FC<ExerciseHistoryDisplayProps> = ({
9494
</strong>
9595
{entry.sets.map((set, i) => (
9696
<div key={i} className="pl-4">
97-
{`${set.reps}x${convertWeight(set.weight ?? 0, 'kg', weightUnit).toFixed(2)}${weightUnit}`}
97+
{`${set.reps}x${convertWeight(set.weight ?? 0, 'kg', weightUnit).toFixed(1)}${weightUnit}`}
9898
{set.duration
9999
? ` ${t('exercise.exerciseHistoryDisplay.durationLabel', 'for')} ${set.duration}min`
100100
: ''}

SparkyFitnessFrontend/src/pages/Diary/DailyProgress.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -449,7 +449,7 @@ const DailyProgress = ({ selectedDate }: { selectedDate: string }) => {
449449
</span>
450450
<span className="font-semibold text-gray-800 dark:text-slate-200">
451451
{adaptiveTdeeData.weightTrend
452-
? `${convertWeight(adaptiveTdeeData.weightTrend, 'kg', weightUnit).toFixed(2)} ${t(`units.${weightUnit}`, weightUnit)}`
452+
? `${convertWeight(adaptiveTdeeData.weightTrend, 'kg', weightUnit).toFixed(1)} ${t(`units.${weightUnit}`, weightUnit)}`
453453
: t('common.calculating', 'Calculating...')}
454454
</span>
455455
</div>

SparkyFitnessFrontend/src/pages/Diary/EditExerciseEntryDialog.tsx

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -72,7 +72,9 @@ const EditExerciseEntryDialog = ({
7272
const [sets, setSets] = useState<WorkoutPresetSet[]>(() => {
7373
return ((entry.sets as WorkoutPresetSet[]) || []).map((set) => ({
7474
...set,
75-
weight: convertWeight(Number(set.weight), 'kg', weightUnit),
75+
weight: parseFloat(
76+
convertWeight(Number(set.weight), 'kg', weightUnit).toFixed(1)
77+
),
7678
}));
7779
});
7880
const [notes, setNotes] = useState(entry.notes || '');

SparkyFitnessFrontend/src/pages/Diary/LogExerciseEntryDialog.tsx

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -91,7 +91,9 @@ const LogExerciseEntryDialog: React.FC<LogExerciseEntryDialogProps> = ({
9191
if (initialSets && initialSets.length > 0) {
9292
return initialSets.map((set) => ({
9393
...set,
94-
weight: convertWeight(set.weight || 0, 'kg', weightUnit),
94+
weight: parseFloat(
95+
convertWeight(set.weight || 0, 'kg', weightUnit).toFixed(1)
96+
),
9597
}));
9698
}
9799
return [{ set_number: 1, set_type: 'Working Set', reps: 10, weight: 0 }];

SparkyFitnessFrontend/src/pages/Exercises/AddWorkoutPlanDialog.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -531,7 +531,7 @@ const AddWorkoutPlanDialog: React.FC<AddWorkoutPlanDialogProps> = ({
531531
...s,
532532
id: s.id ? String(s.id) : crypto.randomUUID(),
533533
weight: parseFloat(
534-
convertWeight(s.weight ?? 0, 'kg', weightUnit).toFixed(2)
534+
convertWeight(s.weight ?? 0, 'kg', weightUnit).toFixed(1)
535535
),
536536
})) || [],
537537
})) || []

SparkyFitnessFrontend/src/pages/Exercises/WorkoutPresetForm.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -411,7 +411,7 @@ const WorkoutPresetForm: React.FC<WorkoutPresetFormProps> = ({
411411
...set,
412412
id: set.id ? String(set.id) : crypto.randomUUID(),
413413
weight: parseFloat(
414-
convertWeight(set.weight ?? 0, 'kg', weightUnit).toFixed(2)
414+
convertWeight(set.weight ?? 0, 'kg', weightUnit).toFixed(1)
415415
),
416416
})),
417417
})) || []

SparkyFitnessFrontend/src/pages/Reports/ExerciseReportsDashboard.tsx

Lines changed: 56 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -541,13 +541,12 @@ const ExerciseReportsDashboard = ({
541541
existingEntry = { date, volume: 0, comparisonVolume: 0 };
542542
acc.push(existingEntry);
543543
}
544+
const currentVolume = entry.sets.reduce(
545+
(sum, set) => sum + set.reps * set.weight,
546+
0
547+
);
544548
existingEntry.volume += parseFloat(
545-
formatWeight(
546-
entry.sets.reduce(
547-
(sum, set) => sum + set.reps * set.weight,
548-
0
549-
)
550-
)
549+
convertWeight(currentVolume, 'kg', weightUnit).toFixed(1)
551550
);
552551
// For comparison, we need to find the corresponding entry in comparisonExerciseProgressData
553552
// This assumes a 1:1 date mapping for simplicity, might need more complex logic for real-world scenarios
@@ -559,13 +558,12 @@ const ExerciseReportsDashboard = ({
559558
(compEntry) => compEntry.entry_date === entry.entry_date
560559
);
561560
if (comparisonEntry) {
561+
const compVolume = comparisonEntry.sets.reduce(
562+
(sum, set) => sum + set.reps * set.weight,
563+
0
564+
);
562565
existingEntry.comparisonVolume += parseFloat(
563-
formatWeight(
564-
comparisonEntry.sets.reduce(
565-
(sum, set) => sum + set.reps * set.weight,
566-
0
567-
)
568-
)
566+
convertWeight(compVolume, 'kg', weightUnit).toFixed(1)
569567
);
570568
}
571569
return acc;
@@ -691,9 +689,16 @@ const ExerciseReportsDashboard = ({
691689
};
692690
acc.push(existingEntry);
693691
}
692+
const currentMaxWeight = parseFloat(
693+
convertWeight(
694+
Math.max(...entry.sets.map((set) => set.weight)),
695+
'kg',
696+
weightUnit
697+
).toFixed(1)
698+
);
694699
existingEntry.maxWeight = Math.max(
695700
existingEntry.maxWeight,
696-
...entry.sets.map((set) => set.weight)
701+
currentMaxWeight
697702
);
698703
const comparisonEntry = Object.values(
699704
comparisonExerciseProgressData
@@ -703,9 +708,18 @@ const ExerciseReportsDashboard = ({
703708
(compEntry) => compEntry.entry_date === entry.entry_date
704709
);
705710
if (comparisonEntry) {
711+
const compMaxWeight = parseFloat(
712+
convertWeight(
713+
Math.max(
714+
...comparisonEntry.sets.map((set) => set.weight)
715+
),
716+
'kg',
717+
weightUnit
718+
).toFixed(1)
719+
);
706720
existingEntry.comparisonMaxWeight = Math.max(
707721
existingEntry.comparisonMaxWeight,
708-
...comparisonEntry.sets.map((set) => set.weight)
722+
compMaxWeight
709723
);
710724
}
711725
return acc;
@@ -765,6 +779,7 @@ const ExerciseReportsDashboard = ({
765779
<CartesianGrid strokeDasharray="3 3" />
766780
<XAxis dataKey="date" />
767781
<YAxis
782+
tickFormatter={(value) => formatWeight(value)}
768783
label={{
769784
value: t(
770785
'exerciseReportsDashboard.maxWeightCurrent',
@@ -777,6 +792,9 @@ const ExerciseReportsDashboard = ({
777792
}}
778793
/>
779794
<Tooltip
795+
formatter={(value: number | undefined) =>
796+
value ? `${formatWeight(value)} ${weightUnit}` : 0
797+
}
780798
contentStyle={{
781799
backgroundColor: 'hsl(var(--background))',
782800
}}
@@ -830,14 +848,18 @@ const ExerciseReportsDashboard = ({
830848
};
831849
acc.push(existingEntry);
832850
}
833-
existingEntry.estimated1RM = Math.round(
834-
Math.max(
835-
existingEntry.estimated1RM,
836-
...entry.sets.map(
837-
(set) => set.weight * (1 + set.reps / 30)
838-
)
851+
const currentMax1RM = Math.max(
852+
...entry.sets.map(
853+
(set) => set.weight * (1 + set.reps / 30)
839854
)
840855
);
856+
const converted1RM = parseFloat(
857+
convertWeight(currentMax1RM, 'kg', weightUnit).toFixed(1)
858+
);
859+
existingEntry.estimated1RM = Math.max(
860+
existingEntry.estimated1RM,
861+
converted1RM
862+
);
841863
const comparisonEntry = Object.values(
842864
comparisonExerciseProgressData
843865
)
@@ -846,14 +868,18 @@ const ExerciseReportsDashboard = ({
846868
(compEntry) => compEntry.entry_date === entry.entry_date
847869
);
848870
if (comparisonEntry) {
849-
existingEntry.comparisonEstimated1RM = Math.round(
850-
Math.max(
851-
existingEntry.comparisonEstimated1RM,
852-
...comparisonEntry.sets.map(
853-
(set) => set.weight * (1 + set.reps / 30)
854-
)
871+
const compMax1RM = Math.max(
872+
...comparisonEntry.sets.map(
873+
(set) => set.weight * (1 + set.reps / 30)
855874
)
856875
);
876+
const convertedComp1RM = parseFloat(
877+
convertWeight(compMax1RM, 'kg', weightUnit).toFixed(1)
878+
);
879+
existingEntry.comparisonEstimated1RM = Math.max(
880+
existingEntry.comparisonEstimated1RM,
881+
convertedComp1RM
882+
);
857883
}
858884
return acc;
859885
},
@@ -912,6 +938,7 @@ const ExerciseReportsDashboard = ({
912938
<CartesianGrid strokeDasharray="3 3" />
913939
<XAxis dataKey="date" />
914940
<YAxis
941+
tickFormatter={(value) => formatWeight(value)}
915942
label={{
916943
value: t(
917944
'exerciseReportsDashboard.estimated1RMCurrent',
@@ -924,6 +951,9 @@ const ExerciseReportsDashboard = ({
924951
}}
925952
/>
926953
<Tooltip
954+
formatter={(value: number | undefined) =>
955+
value ? `${formatWeight(value)} ${weightUnit}` : 0
956+
}
927957
contentStyle={{
928958
backgroundColor: 'hsl(var(--background))',
929959
}}

SparkyFitnessFrontend/src/pages/Reports/PrProgressionChart.tsx

Lines changed: 19 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@ import {
1313
} from 'recharts';
1414
import { usePreferences } from '@/contexts/PreferencesContext';
1515
import ZoomableChart from '@/components/ZoomableChart';
16+
import { formatWeight } from '@/utils/numberFormatting';
1617

1718
interface PrProgressionChartProps {
1819
prProgressionData:
@@ -27,7 +28,8 @@ interface PrProgressionChartProps {
2728

2829
const PrProgressionChart = ({ prProgressionData }: PrProgressionChartProps) => {
2930
const { t } = useTranslation();
30-
const { formatDateInUserTimezone } = usePreferences();
31+
const { formatDateInUserTimezone, weightUnit, convertWeight } =
32+
usePreferences();
3133
const [isMounted, setIsMounted] = React.useState(false);
3234

3335
React.useEffect(() => {
@@ -60,6 +62,10 @@ const PrProgressionChart = ({ prProgressionData }: PrProgressionChartProps) => {
6062
const formattedData = prProgressionData.map((d) => ({
6163
...d,
6264
date: formatDateInUserTimezone(d.date, 'MMM dd, yyyy'),
65+
oneRM: parseFloat(convertWeight(d.oneRM, 'kg', weightUnit).toFixed(1)),
66+
maxWeight: parseFloat(
67+
convertWeight(d.maxWeight, 'kg', weightUnit).toFixed(1)
68+
),
6369
}));
6470

6571
return (
@@ -94,8 +100,11 @@ const PrProgressionChart = ({ prProgressionData }: PrProgressionChartProps) => {
94100
/>
95101
<YAxis
96102
yAxisId="left"
103+
tickFormatter={(value) => formatWeight(value)}
97104
label={{
98-
value: t('prProgressionChart.weightKg', 'Weight (kg)'),
105+
value: t('prProgressionChart.weightUnit', {
106+
unit: weightUnit,
107+
}),
99108
angle: -90,
100109
position: 'insideLeft',
101110
}}
@@ -110,6 +119,14 @@ const PrProgressionChart = ({ prProgressionData }: PrProgressionChartProps) => {
110119
}}
111120
/>
112121
<Tooltip
122+
formatter={(value: number, name: string) => {
123+
if (
124+
name === t('prProgressionChart.maxReps', 'Max Reps')
125+
) {
126+
return [value, name];
127+
}
128+
return [`${formatWeight(value)} ${weightUnit}`, name];
129+
}}
113130
contentStyle={{ backgroundColor: 'hsl(var(--background))' }}
114131
/>
115132
<Legend />

0 commit comments

Comments
 (0)