From a98839585ddf9de7e98756d3ec39c339f73b73f3 Mon Sep 17 00:00:00 2001 From: AG Date: Fri, 28 Nov 2025 20:52:11 +0200 Subject: [PATCH] Hidden field values do not messup logged set --- components/History.tsx | 14 +++---- components/Tracker.tsx | 88 +++++++++++++++++++++++++++++++++-------- server/prisma/dev.db | Bin 61440 -> 61440 bytes 3 files changed, 79 insertions(+), 23 deletions(-) diff --git a/components/History.tsx b/components/History.tsx index 2b9530c..0092963 100644 --- a/components/History.tsx +++ b/components/History.tsx @@ -271,7 +271,7 @@ const History: React.FC = ({ sessions, onUpdateSession, onDeleteSe handleUpdateSet(set.id, 'weight', parseFloat(e.target.value))} /> @@ -282,8 +282,8 @@ const History: React.FC = ({ sessions, onUpdateSession, onDeleteSe handleUpdateSet(set.id, 'reps', parseFloat(e.target.value))} + value={set.reps === 0 ? '' : (set.reps ?? '')} + onChange={(e) => handleUpdateSet(set.id, 'reps', parseInt(e.target.value))} /> )} @@ -293,7 +293,7 @@ const History: React.FC = ({ sessions, onUpdateSession, onDeleteSe handleUpdateSet(set.id, 'bodyWeightPercentage', parseFloat(e.target.value))} /> @@ -304,7 +304,7 @@ const History: React.FC = ({ sessions, onUpdateSession, onDeleteSe handleUpdateSet(set.id, 'durationSeconds', parseFloat(e.target.value))} /> @@ -315,7 +315,7 @@ const History: React.FC = ({ sessions, onUpdateSession, onDeleteSe handleUpdateSet(set.id, 'distanceMeters', parseFloat(e.target.value))} /> @@ -326,7 +326,7 @@ const History: React.FC = ({ sessions, onUpdateSession, onDeleteSe handleUpdateSet(set.id, 'height', parseFloat(e.target.value))} /> diff --git a/components/Tracker.tsx b/components/Tracker.tsx index 2d3b2a8..c9ab2b9 100644 --- a/components/Tracker.tsx +++ b/components/Tracker.tsx @@ -121,14 +121,31 @@ const Tracker: React.FC = ({ userId, userWeight, activeSession, ac setLastSet(set); if (set) { - if (set.weight != null) setWeight(set.weight.toString()); - if (set.reps != null) setReps(set.reps.toString()); - if (set.durationSeconds != null) setDuration(set.durationSeconds.toString()); - if (set.distanceMeters != null) setDistance(set.distanceMeters.toString()); - if (set.height != null) setHeight(set.height.toString()); + setWeight(set.weight?.toString() || ''); + setReps(set.reps?.toString() || ''); + setDuration(set.durationSeconds?.toString() || ''); + setDistance(set.distanceMeters?.toString() || ''); + setHeight(set.height?.toString() || ''); } else { setWeight(''); setReps(''); setDuration(''); setDistance(''); setHeight(''); } + + // Clear fields not relevant to the selected exercise type + if (selectedExercise.type !== ExerciseType.STRENGTH && selectedExercise.type !== ExerciseType.BODYWEIGHT) { + setWeight(''); + } + if (selectedExercise.type !== ExerciseType.STRENGTH && selectedExercise.type !== ExerciseType.BODYWEIGHT && selectedExercise.type !== ExerciseType.PLYOMETRIC) { + setReps(''); + } + if (selectedExercise.type !== ExerciseType.CARDIO && selectedExercise.type !== ExerciseType.STATIC) { + setDuration(''); + } + if (selectedExercise.type !== ExerciseType.CARDIO && selectedExercise.type !== ExerciseType.LONG_JUMP) { + setDistance(''); + } + if (selectedExercise.type !== ExerciseType.HIGH_JUMP) { + setHeight(''); + } } }; updateSelection(); @@ -158,14 +175,37 @@ const Tracker: React.FC = ({ userId, userWeight, activeSession, ac exerciseName: selectedExercise.name, type: selectedExercise.type, timestamp: Date.now(), - ...(weight && { weight: parseFloat(weight) }), - ...(reps && { reps: parseInt(reps) }), - ...(duration && { durationSeconds: parseInt(duration) }), - ...(distance && { distanceMeters: parseFloat(distance) }), - ...(height && { height: parseFloat(height) }), - ...((selectedExercise.type === ExerciseType.BODYWEIGHT || selectedExercise.type === ExerciseType.STATIC) && { bodyWeightPercentage: parseFloat(bwPercentage) || 100 }) }; + switch (selectedExercise.type) { + case ExerciseType.STRENGTH: + if (weight) newSet.weight = parseFloat(weight); + if (reps) newSet.reps = parseInt(reps); + break; + case ExerciseType.BODYWEIGHT: + if (weight) newSet.weight = parseFloat(weight); + if (reps) newSet.reps = parseInt(reps); + newSet.bodyWeightPercentage = parseFloat(bwPercentage) || 100; + break; + case ExerciseType.CARDIO: + if (duration) newSet.durationSeconds = parseInt(duration); + if (distance) newSet.distanceMeters = parseFloat(distance); + break; + case ExerciseType.STATIC: + if (duration) newSet.durationSeconds = parseInt(duration); + newSet.bodyWeightPercentage = parseFloat(bwPercentage) || 100; + break; + case ExerciseType.HIGH_JUMP: + if (height) newSet.height = parseFloat(height); + break; + case ExerciseType.LONG_JUMP: + if (distance) newSet.distanceMeters = parseFloat(distance); + break; + case ExerciseType.PLYOMETRIC: + if (reps) newSet.reps = parseInt(reps); + break; + } + onSetAdded(newSet); if (activePlan) { @@ -564,11 +604,27 @@ const Tracker: React.FC = ({ userId, userWeight, activeSession, ac
{set.exerciseName}
- {set.weight != null && `${set.weight}kg `} - {set.reps != null && `x ${set.reps}`} - {set.distanceMeters != null && `${set.distanceMeters}m`} - {set.durationSeconds != null && `${set.durationSeconds}s`} - {set.height != null && `${set.height}cm`} + {set.type === ExerciseType.STRENGTH && + `${set.weight ? `${set.weight}kg` : ''} ${set.reps ? `x ${set.reps}` : ''}`.trim() + } + {set.type === ExerciseType.BODYWEIGHT && + `${set.weight ? `${set.weight}kg` : ''} ${set.reps ? `x ${set.reps}` : ''}`.trim() + } + {set.type === ExerciseType.CARDIO && + `${set.durationSeconds ? `${set.durationSeconds}s` : ''} ${set.distanceMeters ? `/ ${set.distanceMeters}m` : ''}`.trim() + } + {set.type === ExerciseType.STATIC && + `${set.durationSeconds ? `${set.durationSeconds}s` : ''}`.trim() + } + {set.type === ExerciseType.HIGH_JUMP && + `${set.height ? `${set.height}cm` : ''}`.trim() + } + {set.type === ExerciseType.LONG_JUMP && + `${set.distanceMeters ? `${set.distanceMeters}m` : ''}`.trim() + } + {set.type === ExerciseType.PLYOMETRIC && + `${set.reps ? `x ${set.reps}` : ''}`.trim() + }
)} diff --git a/server/prisma/dev.db b/server/prisma/dev.db index 509834d67c0c9f3fddfa386a22e10c7a7a20b766..c829101903f94f2a70dafe091a13914e1246a17d 100644 GIT binary patch delta 2821 zcma)7OKcTY7`~UjxV`h}gH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