Merge #164: a per-exercise rest for warm-up ramp sets, warmupRestSec (kurktchiev)

This commit is contained in:
Duarte Santos committed 2026-09-12 22:52:15 +02:00
commit 6c8bc51d18
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)