Skip to content

Open-source gym & body-weight tracker, now in the App Store (iPhone + Apple Watch) and as an Android APK. Plan routines, log workouts, see which muscles are trained, import from Strong/Hevy/FitNotes. Self-host it or use it on the phone alone.

Routine editor: replacing an exercise with itself leaves its weight and bodyweight setting alone (#110)

Duarte Santos49c173d189f2
diff --git a/frontend/src/lib/routines.js b/frontend/src/lib/routines.js
index 0175d0499..a3d97a892 100644
--- a/frontend/src/lib/routines.js
+++ b/frontend/src/lib/routines.js
@@ -42,9 +42,12 @@ export function copyRoutine(routine, suffix = 'Copy') {
* plan whose sets and reps match just carries on. With the new exercise's own planned weight in
* the slot, its history decides either way. One never logged keeps the slot's weight, since
* there is nothing better to start from.
+ *
+ * Picking the exercise that is already in the slot replaces nothing, and changes nothing.
*/
export function replaceSlotExercise(slot, id, S, rid) {
const old = slot || {}
+ if (old.id === id) return { ...old }
if ((modeOf(old) === 'cardio') !== isCardio(id)) {
const kept = ['sg', 'note', 'restSec'].filter(key => old[key] != null)
return { id, ...defaultConfig(id), ...Object.fromEntries(kept.map(key => [key, old[key]])) }
diff --git a/frontend/src/lib/routines.replace.test.js b/frontend/src/lib/routines.replace.test.js
index fdc0209a8..d674c9449 100644
--- a/frontend/src/lib/routines.replace.test.js
+++ b/frontend/src/lib/routines.replace.test.js
@@ -26,6 +26,14 @@ describe('replaceSlotExercise', () => {
expect(slot.id).toBe(BENCH)
})
+ it('changes nothing when the pick is the exercise already in the slot', () => {
+ // A push-up the user loaded with 20 kg and marked as not bodyweight, picked again from "Chosen".
+ const slot = { id: PUSH_UP, sg: 'sgA', sets: 3, mode: 'reps', reps: 8, weight: 20, bodyweight: false, side: true }
+ const same = replaceSlotExercise(slot, PUSH_UP, { workouts: [] }, 'A')
+ expect(same).toEqual(slot)
+ expect(same).not.toBe(slot)
+ })
+
it('keeps a timed slot timed', () => {
const next = replaceSlotExercise({ id: BENCH, sets: 3, mode: 'time', sec: 40, weight: 20 }, DB_BENCH)
expect(next).toEqual({ id: DB_BENCH, sets: 3, mode: 'time', sec: 40, weight: 20 })
diff --git a/frontend/src/views/RoutineEdit.jsx b/frontend/src/views/RoutineEdit.jsx
index 3919ee537..581241ca7 100644
--- a/frontend/src/views/RoutineEdit.jsx
+++ b/frontend/src/views/RoutineEdit.jsx
@@ -359,6 +359,9 @@ export default function RoutineEdit() {
// The new exercise's weight comes from its own sessions (lib/routines.js), read as they are
// now rather than as this render saw them: a sync can land while the picker is open.
const live = useStore.getState().S
+ // "+" on the exercise that is already in the slot: nothing to replace, and no toast that
+ // says something was.
+ if (quick && ex.id === openedOn) { picker.close(); return }
if (quick) { commit(ex, slot => replaceSlotExercise(slot, ex.id, live, id)); return }
const next = replaceSlotExercise(r.ex[i], ex.id, live, id)
exConfigSheet(ex, next, cfg => commit(ex, slot => ({ id: ex.id, sg: slot.sg, ...cfg })), null, r)
diff --git a/frontend/src/views/RoutineEdit.replace.test.jsx b/frontend/src/views/RoutineEdit.replace.test.jsx
index c65d638ce..69da79333 100644
--- a/frontend/src/views/RoutineEdit.replace.test.jsx
+++ b/frontend/src/views/RoutineEdit.replace.test.jsx
@@ -88,6 +88,15 @@ describe('RoutineEdit — Replace exercise', () => {
expect(picker.close).toHaveBeenCalledOnce()
})
+ it('"+" on the exercise already in the slot changes nothing and says nothing', () => {
+ mount()
+ const onPick = openReplace()
+ act(() => onPick(EXIDX[BENCH], true))
+ expect(slots()).toEqual([benchSlot, rowSlot])
+ expect(picker.close).toHaveBeenCalledOnce()
+ expect(useUI.getState().toastMsg).toBe('')
+ })
+
it('gives a replacement trained in another routine its own weight, not the old exercise\'s', () => {
// The dumbbells were planned at 30 in the upper-body routine: the bench's 80 is not theirs.
const upper = { id: 'r2', name: 'Upper', emoji: 'dumbbell', ex: [{ id: DB_BENCH, sets: 3, mode: 'reps', reps: 10, weight: 30 }] }