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.

Per-side sets can be made warm-ups and back (#575)

Duarte Santoseeaa03715426
diff --git a/frontend/src/lib/history.js b/frontend/src/lib/history.js
index 562a539aa..fb275f27a 100644
--- a/frontend/src/lib/history.js
+++ b/frontend/src/lib/history.js
@@ -1071,15 +1071,21 @@ export function insertWarmupRow(rows, mode, target, step = 2.5, floor = 0) {
// warm-up (its weight, reps and tick kept; drops, bursts, sides and effort dropped, since a
// warm-up has none) and moves to the end of the warm-ups, so it is numbered, rested and left out
// of progression and records like any other warm-up. A row that is one already is left alone.
-// Only a plain straight set: a warm-up is one weight times one rep count, so a drop set would
-// lose its drops, a rest-pause row would add its bursts into one inflated rep count, and a
-// per-side row would merge both sides with no way back (a per-side warm-up is never made a work
-// set again).
-export const canBeWarmup = row => !!row && !isWarmupRow(row) && !isSideSet(row) && !isDropSet(row) && !isRestPauseSet(row)
+// Only a straight set: a warm-up is one weight times one rep count, so a drop set would lose its
+// drops and a rest-pause row would add its bursts into one inflated rep count. A per-side row
+// (#575) stays per side, the way insertWarmupRow adds a warm-up to a unilateral exercise: each
+// side keeps its own weight, reps and tick, so it can be made a work set again with nothing lost.
+export const canBeWarmup = row => !!row && !isWarmupRow(row) && !isDropSet(row) && !isRestPauseSet(row)
export function makeWarmupAt(rows, i) {
const src = rows[i]
if (!canBeWarmup(src)) return rows
+ if (isSideSet(src)) {
+ const side = v => ({ w: v.w || 0, r: v.r, done: !!v.done })
+ const warm = syncSideAggregate({ phase: 'warmup', warmup: true, sides: { L: side(src.sides.L), R: side(src.sides.R) } })
+ if (src.at != null) warm.at = src.at
+ return placeRow(rows, i, warm)
+ }
const warm = { w: src.w || 0, r: src.r, done: !!src.done, phase: 'warmup', warmup: true }
if (src.at != null) warm.at = src.at
return placeRow(rows, i, warm)
diff --git a/frontend/src/lib/history.test.js b/frontend/src/lib/history.test.js
index f41259a20..f7fabc344 100644
--- a/frontend/src/lib/history.test.js
+++ b/frontend/src/lib/history.test.js
@@ -1625,14 +1625,27 @@ describe('switching a row between warm-up and work', () => {
expect(makeWarmupAt(rows, 0)).toBe(rows)
})
- it('makeWarmupAt leaves drop, rest-pause and per-side rows as they are', () => {
+ it('makeWarmupAt leaves drop and rest-pause rows as they are', () => {
const drop = [{ w: 60, r: 8, done: true }, { w: 100, r: 5, done: true, type: 'dropset', drops: [{ w: 80, r: 4 }] }]
expect(makeWarmupAt(drop, 1)).toBe(drop)
const rp = [{ w: 60, r: 8, done: true }, { w: 100, r: 12, done: true, type: 'restpause', clusters: [{ r: 4, rest: 15 }] }]
expect(makeWarmupAt(rp, 1)).toBe(rp)
- const side = [{ w: 30, r: 6, done: true }, { w: 30, r: 11, done: false, sides: { L: { w: 30, r: 5, done: true }, R: { w: 0, r: 6, done: false } } }]
- expect(makeWarmupAt(side, 1)).toBe(side)
- expect([canBeWarmup(drop[1]), canBeWarmup(rp[1]), canBeWarmup(side[1]), canBeWarmup(drop[0])]).toEqual([false, false, false, true])
+ const sideDrop = [{ w: 30, r: 6 }, { w: 30, r: 10, type: 'dropset', sides: { L: { w: 30, r: 5, type: 'dropset', drops: [{ w: 20, r: 4 }] }, R: { w: 30, r: 5 } } }]
+ expect(makeWarmupAt(sideDrop, 1)).toBe(sideDrop)
+ expect([canBeWarmup(drop[1]), canBeWarmup(rp[1]), canBeWarmup(sideDrop[1]), canBeWarmup(drop[0])]).toEqual([false, false, false, true])
+ })
+
+ // #575: the set menu of a per-side exercise had no "Make it a warm-up set".
+ it('a per-side set becomes a per-side warm-up, each side kept, and goes back with nothing lost', () => {
+ const side = { w: 30, r: 11, done: false, rir: 1, sides: { L: { w: 30, r: 5, done: true, rir: 2 }, R: { w: 32.5, r: 6, done: false, rir: 1 } } }
+ const rows = [{ w: 30, r: 10, done: true, sides: { L: { w: 30, r: 5, done: true }, R: { w: 30, r: 5, done: true } } }, side]
+ expect(canBeWarmup(side)).toBe(true)
+ const warm = makeWarmupAt(rows, 1)
+ expect(warm[0]).toEqual({ phase: 'warmup', warmup: true, sides: { L: { w: 30, r: 5, done: true }, R: { w: 32.5, r: 6, done: false } }, r: 11, w: 32.5, done: false })
+ expect(warm[1]).toBe(rows[0])
+ const back = makeWorkAt(warm, 0)
+ expect(back[0]).toEqual({ sides: { L: { w: 30, r: 5, done: true }, R: { w: 32.5, r: 6, done: false } }, r: 11, w: 32.5, done: false })
+ expect(rows[1]).toEqual(side) // the input is never written to
})
it('a warm-up made one is left out of the best weight and the work-set count', () => {
diff --git a/frontend/src/views/Workout.jsx b/frontend/src/views/Workout.jsx
index b684b1566..25ac97c4f 100644
--- a/frontend/src/views/Workout.jsx
+++ b/frontend/src/views/Workout.jsx
@@ -440,11 +440,11 @@ function ExerciseBlock({ entryIdx, compact, dense, editing, onToggle, onToggleSi
subtitle: setLabel(entry.id, s, entry.target, speedUnit),
sections: [
// A warm-up logged as a work set (or the other way round) changes phase here. Reps sets
- // only, the kind a warm-up is added as; one work set always stays, and a per-side
- // exercise's work sets keep their sides, so a warm-up there is not made one again.
+ // only, the kind a warm-up is added as; one work set always stays. A per-side set keeps
+ // its two sides either way (#575), so it goes back and forth like any other.
{ items: [
!warm && mode === 'reps' && canBeWarmup(s) && entry.sets.some((x, j) => j !== i && !isWarmupRow(x)) && { icon: 'sunrise', label: t('Make it a warm-up set'), onClick: () => setPhaseAt(i, true) },
- warm && mode === 'reps' && !perSide && { icon: 'dumbbell', label: t('Count it as a working set'), onClick: () => setPhaseAt(i, false) },
+ warm && mode === 'reps' && { icon: 'dumbbell', label: t('Count it as a working set'), onClick: () => setPhaseAt(i, false) },
// Taken to failure: a toggle with its check, like the menu's other on/off rows. It counts
// as RIR 0 wherever effort is read, unless a rating was logged on the set. A timed
// per-side pair is one set, so both halves get it.
diff --git a/frontend/src/views/Workout.test.jsx b/frontend/src/views/Workout.test.jsx
index b26bf94fa..360920f23 100644
--- a/frontend/src/views/Workout.test.jsx
+++ b/frontend/src/views/Workout.test.jsx
@@ -2906,6 +2906,23 @@ describe('workout controls: the more menu and the set menu', () => {
expect(sets()[0]).toEqual({ w: 60, r: 5, done: false })
})
+ // #575: a per-side exercise's set menu had no "Make it a warm-up set".
+ it('makes a per-side set a warm-up and back, both sides kept', async () => {
+ const side = (l, r) => ({ w: 20, r: l + r, done: false, sides: { L: { w: 20, r: l, done: false }, R: { w: 20, r: r, done: false } } })
+ await mount([{ id: 'plain-lunge', target: { mode: 'reps', reps: 10, weight: 20, side: true }, sets: [side(5, 5), side(4, 6)] }])
+ const openSet = async k => { await act(async () => { container.querySelectorAll('button.n')[k].dispatchEvent(new dom.Event('click', { bubbles: true })) }) }
+ await openSet(1)
+ await act(async () => { item('Make it a warm-up set').onClick() })
+ const sets = () => mocks.S.active.entries[0].sets
+ expect(isWarmupRow(sets()[0])).toBe(true)
+ expect(sets()[0].sides).toEqual({ L: { w: 20, r: 4, done: false }, R: { w: 20, r: 6, done: false } })
+ await rerender()
+ await openSet(0)
+ await act(async () => { item('Count it as a working set').onClick() })
+ expect(sets().every(x => !isWarmupRow(x))).toBe(true)
+ expect(sets()[0].sides).toEqual({ L: { w: 20, r: 4, done: false }, R: { w: 20, r: 6, done: false } })
+ })
+
it('brings the legacy button rows back per switch', async () => {
await mount([exercise('plain-bench', [false]), exercise('plain-row', [false])], 0, {
wc: { setShortcuts: true, pairButtons: true, exerciseButtons: true },