feat(workout): a per-exercise rest for warm-up ramp sets (warmupRestSec)

An exercise's restSec runs after every set, warm-up ramp included, so a heavy lift with a
150 s working rest also puts 150 s between two light ramp sets. Exercises may now carry a
second optional field, warmupRestSec: the rest between warm-up ramp sets.

- The break after the LAST ramp set (into the first work set) stays the working rest, because
  that is the rest the first heavy set actually needs.
- Without the field nothing changes: ramp sets rest like work sets, exactly as before.
- Like restSec, the field is set by plan files (and by external planners writing routines);
  no new UI, no new string, no locale change. It travels with a shared plan the same way
  restSec does and is dropped when unset.

Where:
- src/lib/supersetFlow.js: warmupRestSecFor(entry, setIdx, workRestSec), the pure rule,
  tested beside it (supersetFlow.test.js)
- src/views/Workout.jsx: the rest started after a checked set goes through it, at all four
  start sites (re-check, singleton, unit done, superset round done)
- src/lib/plan-share.js: export/import passthrough with the same clamp as restSec
  (plan-share.test.js)
- src/views/Workout.test.jsx: 45 s between ramp sets, 150 s after the last ramp set and
  after work sets

Why: a lifter asked for it after two sessions ("warm-up sets have way too large of a rest
period, it should only be 60-90 seconds max") while wanting 90-150 s on the working sets.
The only lever today is one number per exercise.

Tests: cd frontend && npm test -> 1338 passing (93 files), including the new cases.

Compatibility: additive. Old routines, old plan files and old sessions have no field and
behave exactly as before. The API stores routines as opaque JSON, so nothing server-side
changes. The AI Coach's payload allowlist does not include the field (not needed there).
This commit is contained in:
Boris Kurktchiev committed 2026-09-12 08:12:00 -04:00
1 parent 35c810a663
commit 82db21100a
6 files changed
+102 -8

No files matched your search

+8 -5
View File
@@ -10,7 +10,7 @@ import { fmtNum, capWords, fmtDate, todayISO, exCount, DAYN } from '../lib/forma
import { beep, vibrate } from '../lib/sound.js'
import { t, exerciseNameFor } from '../lib/i18n.js'
import { api } from '../lib/api.js'
import { insertionIndexAfterCurrentUnit, nextUnfinishedUnit, setProgressHighWater, supersetFlowStep, restAfterSet, restOnRecheck, restSecFor } from '../lib/supersetFlow.js'
import { insertionIndexAfterCurrentUnit, nextUnfinishedUnit, setProgressHighWater, supersetFlowStep, restAfterSet, restOnRecheck, restSecFor, warmupRestSecFor } from '../lib/supersetFlow.js'
import Media from '../components/Media.jsx'
import { startFlow, exercisePicker, exConfigSheet, exerciseDetailSheet, finishWorkout, workoutCompleteSheet, confirmSheet, exerciseNoteSheet, sessionNoteSheet, swapActiveWorkoutExercise, barWeightSheet, menuSheet, effortPickerSheet, exerciseHistorySheet, addRoutineToSessionSheet } from '../sheets.jsx'
import { effortColor } from '../lib/effort.js'
@@ -863,11 +863,14 @@ function ActiveWorkout() {
// 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 warm-up ramp set may rest shorter than a work set (the exercise's warmupRestSec); the
// last ramp set, into the first work set, still gets the working rest.
const restAfter = warmupRestSecFor(fresh.entries[idx], i, 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 (!restBeforeWarmup && restOnRecheck({ timerRunning: !!useUI.getState().timer, unitDone: freshUnitDone, lastUnit: freshWorkoutDone })) startRest(restSec, idx)
if (!restBeforeWarmup && restOnRecheck({ timerRunning: !!useUI.getState().timer, unitDone: freshUnitDone, lastUnit: freshWorkoutDone })) startRest(restAfter, idx)
return
}
@@ -876,17 +879,17 @@ function ActiveWorkout() {
// stopRest() first so a rest that belongs after this set replaces the one that was running.
if (freshUnitDone) stopRest()
if (!freshUnit || freshUnit.length <= 1) {
if (!restBeforeWarmup && restAfterSet({ unitDone: freshUnitDone, lastUnit: freshWorkoutDone })) startRest(restSec, idx)
if (!restBeforeWarmup && restAfterSet({ unitDone: freshUnitDone, lastUnit: freshWorkoutDone })) startRest(restAfter, idx)
return
}
const step = supersetFlowStep(fresh.entries, freshUnit, idx)
if (!step) return
if (step.unitDone) {
if (nextUnit?.length && !restBeforeWarmup) startRest(restSec, idx)
if (nextUnit?.length && !restBeforeWarmup) startRest(restAfter, idx)
} else {
if (step.nextIdx != null) update(s => { if (s.active) s.active.cur = step.nextIdx })
if (step.roundDone) startRest(restSec, idx)
if (step.roundDone) startRest(restAfter, idx)
}
}
}
+19
View File
@@ -202,6 +202,25 @@ afterEach(async () => {
})
describe('Workout set completion flow', () => {
it('rests the exercise\'s warm-up rest between ramp sets, and its working rest after the last ramp set', async () => {
await mount([exercise('ramped-squat', [false, false, false, false], {
target: { mode: 'reps', reps: 6, weight: 125, bodyweight: false, restSec: 150, warmupRestSec: 45 },
sets: [
{ w: 60, r: 8, done: false, phase: 'warmup' },
{ w: 95, r: 5, done: false, phase: 'warmup' },
{ w: 125, r: 6, done: false, phase: 'work' },
{ w: 125, r: 6, done: false, phase: 'work' },
],
})])
await toggleSet(0)
expect(mocks.startRest).toHaveBeenLastCalledWith(45, expect.any(Number))
await toggleSet(1)
expect(mocks.startRest).toHaveBeenLastCalledWith(150, expect.any(Number))
await toggleSet(2)
expect(mocks.startRest).toHaveBeenLastCalledWith(150, expect.any(Number))
expect(mocks.startRest).toHaveBeenCalledTimes(3)
})
it('starts rest after a non-final ordinary set, but stops rest without restarting it on the final set', async () => {
await mount([exercise('plain-bench', [false, false, false])])
await toggleSet(0)