workout: optional per-exercise rest for normal sets

An exercise can now carry its own restSec: the workout timer prefers it
over the global default, a superset rests the longest resolved rest in
the group after each round, and the field travels with shared plans —
normalised on import like every other prescribed number. An explicit
restSec still times its rest when the global timer is turned off; only
the default is silenced. Closes #10.
This commit is contained in:
Alexby committed 2026-08-26 16:03:27 +02:00
1 parent 5314b342ff
commit 0b4a224c95
20 files changed
+195 -15

No files matched your search

+9 -5
View File
@@ -8,7 +8,7 @@ import { fmtNum, fmtDate, todayISO, exCount, DAYN } from '../lib/format.js'
import { beep, vibrate } from '../lib/sound.js'
import { t, exerciseNameFor } from '../lib/i18n.js'
import { api } from '../lib/api.js'
import { setProgressHighWater, supersetFlowStep, restAfterSet, restOnRecheck } from '../lib/supersetFlow.js'
import { setProgressHighWater, supersetFlowStep, restAfterSet, restOnRecheck, restSecFor } from '../lib/supersetFlow.js'
import Media from '../components/Media.jsx'
import { startFlow, exercisePicker, exConfigSheet, exerciseDetailSheet, topWeightSheet, finishWorkout, workoutCompleteSheet, confirmSheet, exerciseNoteSheet, sessionNoteSheet } from '../sheets.jsx'
import Icon from '../components/Icon.jsx'
@@ -417,11 +417,15 @@ function ActiveWorkout() {
const freshUnitIdx = freshUnits.indexOf(freshUnit)
const freshLastUnit = freshUnitIdx >= freshUnits.length - 1
const freshUnitDone = freshUnit?.every(ui => fresh.entries[ui].sets.every(x => x.done))
// The rest this set has earned: the exercise's own restSec when it set one, the global
// timer when it did not, and the longest of the group's across a superset (issue #10).
// Resolved once here so every branch below times the same break.
const restSec = restSecFor(fresh.entries, freshUnit || [idx], S.restSec)
// A re-check of finished work must not navigate or reopen a sheet, but it may still owe
// you a rest — see restOnRecheck, and the other half of issue #3.
if (!progress.isNew) {
if (restOnRecheck({ timerRunning: !!useUI.getState().timer, unitDone: freshUnitDone, lastUnit: freshLastUnit })) startRest(S.restSec)
if (restOnRecheck({ timerRunning: !!useUI.getState().timer, unitDone: freshUnitDone, lastUnit: freshLastUnit })) startRest(restSec)
return
}
@@ -430,7 +434,7 @@ function ActiveWorkout() {
// after this set replaces the one that was running, rather than stacking on it.
if (freshUnitDone) stopRest()
if (!freshUnit || freshUnit.length <= 1) {
if (restAfterSet({ unitDone: freshUnitDone, lastUnit: freshLastUnit })) startRest(S.restSec)
if (restAfterSet({ unitDone: freshUnitDone, lastUnit: freshLastUnit })) startRest(restSec)
return
}
@@ -441,11 +445,11 @@ function ActiveWorkout() {
const nextUnit = freshUnits[freshUnitIdx + 1]
// The top-weight sheet's explicit "Just close" path owns the choice not to advance.
if (!askTop && nextUnit?.length) update(s => { if (s.active) s.active.cur = nextUnit[0] })
startRest(S.restSec)
startRest(restSec)
}
} else {
if (step.nextIdx != null) update(s => { if (s.active) s.active.cur = step.nextIdx })
if (step.roundDone) startRest(S.restSec)
if (step.roundDone) startRest(restSec)
}
}
}
+34
View File
@@ -140,6 +140,40 @@ describe('Workout set completion flow', () => {
expect(mocks.startRest).not.toHaveBeenCalled()
})
// Issue #10. The workout is where the field earns its keep: whatever the routine wrote has
// to be the number the timer actually counts down, and a superset rests once for the group.
it('times the exercise’s own rest instead of the global one', async () => {
await mount([exercise('heavy-squat', [false, false], {
target: { mode: 'reps', reps: 5, weight: 100, restSec: 180 },
})])
await toggleSet(0)
expect(mocks.startRest).toHaveBeenCalledWith(180)
})
it('rests a superset for the longest its members asked for', async () => {
// A closes the round, but B is the one still recovering — 150 s, not A's 45 s.
await mount([
exercise('superset-a', [false, false], { sg: 'g1', target: { mode: 'reps', reps: 12, weight: 20, restSec: 45 } }),
exercise('superset-b', [false, false], { sg: 'g1', target: { mode: 'reps', reps: 5, weight: 100, restSec: 150 } }),
])
await toggleSet(0)
await act(async () => { root.render(React.createElement(Workout)) })
await toggleSet(2)
expect(mocks.startRest).toHaveBeenCalledWith(150)
})
it('still starts an explicit rest when the global timer is switched off', async () => {
await mount([exercise('heavy-squat', [false, false], {
target: { mode: 'reps', reps: 5, weight: 100, restSec: 180 },
})])
mocks.S.restSec = 0
await toggleSet(0)
expect(mocks.startRest).toHaveBeenCalledWith(180)
})
it('leaves a completed superset selected while its top-weight sheet owns the advance choice', async () => {
const group = 'superset-1'
await mount([