Skip to content

Commit 883bd96

Browse files
committed
fix: Ensure users can stop cardio timer
There was a bug where since the cardio timer updates two fields with two callbacks, the second update clobbered the first. This change ensures that the calback always gets the latest version of the exercise. This is not the first time this has happened with this new model, it may not be the best way to go about it. fixes: #861
1 parent 4f21649 commit 883bd96

2 files changed

Lines changed: 12 additions & 5 deletions

File tree

app/src/components/presentation/workout/cardio/cardio-exercise.tsx

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -44,7 +44,9 @@ interface CardioExerciseProps {
4444
isReadonly: boolean;
4545
showPreviousButton: boolean;
4646

47-
updateExercise: (ex: RecordedCardioExercise) => void;
47+
updateExercise: (
48+
cb: (ex: RecordedCardioExercise) => RecordedCardioExercise,
49+
) => void;
4850
onEditExercise: () => void;
4951
onRemoveExercise: () => void;
5052
}
@@ -59,8 +61,8 @@ export function CardioExercise(props: CardioExerciseProps) {
5961
setIndex: number,
6062
): CardioExerciseSetCallback<T> =>
6163
(val) =>
62-
props.updateExercise(
63-
props.recordedExercise.withSet(setIndex, (s) =>
64+
props.updateExercise((ex) =>
65+
ex.withSet(setIndex, (s) =>
6466
s
6567
.with({ [key]: val })
6668
.withCompletionTimeIfCompleted(OffsetDateTime.now()),
@@ -73,7 +75,7 @@ export function CardioExercise(props: CardioExerciseProps) {
7375
toStartNext={props.toStartNext}
7476
isReadonly={props.isReadonly}
7577
showPreviousButton={props.showPreviousButton}
76-
updateExercise={props.updateExercise}
78+
updateExercise={(x) => props.updateExercise(() => x)}
7779
onEditExercise={props.onEditExercise}
7880
onRemoveExercise={props.onRemoveExercise}
7981
>

app/src/components/smart/session-component.tsx

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -183,7 +183,12 @@ export default function SessionComponent(props: {
183183
<CardioExercise
184184
recordedExercise={item}
185185
updateExercise={(ex) =>
186-
updateSession((s) => s.withExercise(index, ex))
186+
updateSession((s) =>
187+
s.withExercise(
188+
index,
189+
ex(s.recordedExercises[index] as RecordedCardioExercise),
190+
),
191+
)
187192
}
188193
toStartNext={session.nextExercise === item}
189194
onEditExercise={() => {

0 commit comments

Comments
 (0)