From b28115a8f9746036fdf99d87687f2f60f43b2d9f Mon Sep 17 00:00:00 2001 From: Duarte Santos Date: Tue, 25 Aug 2026 20:51:18 +0200 Subject: [PATCH] workout: give back the rest a re-checked set used to swallow MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit The other half of issue #3. "Breaks sometimes not shown after finished set (first / last)" — the last-set half was the quiet-finish rule, already fixed. This is the first-set half. Completing a set only counts as progress when it goes beyond the most sets this exercise has had done at once, so that unchecking and re-checking finished work does not replay navigation or reopen sheets. Correct, but it returned before anything could time a rest: uncheck a set to fix the reps, check it again, and nothing starts. If the original rest had already run out, you get no break at all — which is exactly what was reported, and why it reads as "sometimes". A re-check now fills that gap and only that gap: it starts a rest when none is running, and never touches one that is still counting down, because a running timer belongs to the set you finished most recently. Navigation and sheets stay gated exactly as before. --- frontend/src/lib/supersetFlow.js | 17 +++++++++++++++++ frontend/src/lib/supersetFlow.test.js | 23 ++++++++++++++++++++++- frontend/src/views/Workout.jsx | 10 ++++++++-- 3 files changed, 47 insertions(+), 3 deletions(-) diff --git a/frontend/src/lib/supersetFlow.js b/frontend/src/lib/supersetFlow.js index 07eb202..4b8c8fb 100644 --- a/frontend/src/lib/supersetFlow.js +++ b/frontend/src/lib/supersetFlow.js @@ -25,6 +25,23 @@ export function restAfterSet({ unitDone, lastUnit }) { return !unitDone || !lastUnit } +/** + * Whether re-checking an already-completed set should start a rest. + * + * The high-water rule deliberately swallows a re-check so that unchecking and re-checking + * finished work does not replay navigation or reopen sheets. But a re-check is still you + * telling the app a set is done, and that is the other half of issue #3 — "after the first + * set, sometimes a break doesn't appear". That is what it looks like when you uncheck a set + * to correct the reps after its rest has already run out: nothing times the rest you are + * actually about to take. + * + * So: fill a gap, never disturb a rest that is already counting down. A timer that is running + * belongs to the set you finished most recently, which is a better answer than restarting it. + */ +export function restOnRecheck({ timerRunning, unitDone, lastUnit }) { + return !timerRunning && restAfterSet({ unitDone, lastUnit }) +} + // Decide where a newly completed superset set goes next. Spent members are skipped, including // across the wrap. A round ends when no later member in display order has work left; this makes // the last *active* member the boundary rather than blindly using the group's last array index. diff --git a/frontend/src/lib/supersetFlow.test.js b/frontend/src/lib/supersetFlow.test.js index b5682db..91864f1 100644 --- a/frontend/src/lib/supersetFlow.test.js +++ b/frontend/src/lib/supersetFlow.test.js @@ -1,5 +1,5 @@ import { describe, expect, it } from 'vitest' -import { setProgressHighWater, supersetFlowStep, restAfterSet } from './supersetFlow.js' +import { setProgressHighWater, supersetFlowStep, restAfterSet, restOnRecheck } from './supersetFlow.js' const entry = done => ({ sets: done.map(value => ({ done: value })) }) @@ -51,3 +51,24 @@ describe('supersetFlowStep', () => { }) }) }) + +// Issue #3 has two halves. restAfterSet covers "no break after the LAST set of an exercise"; +// this covers "after the first set, sometimes a break doesn't appear" — the uncheck/re-check +// that the high-water rule swallows. +describe('rest on a re-check', () => { + it('starts the rest a swallowed re-check would otherwise cost you', () => { + expect(restOnRecheck({ timerRunning: false, unitDone: false, lastUnit: false })).toBe(true) + }) + + it('leaves a rest that is already counting alone', () => { + expect(restOnRecheck({ timerRunning: true, unitDone: false, lastUnit: false })).toBe(false) + }) + + it('still stays quiet on the last set of the last exercise', () => { + expect(restOnRecheck({ timerRunning: false, unitDone: true, lastUnit: true })).toBe(false) + }) + + it('rests after closing an exercise that is not the last one', () => { + expect(restOnRecheck({ timerRunning: false, unitDone: true, lastUnit: false })).toBe(true) + }) +}) diff --git a/frontend/src/views/Workout.jsx b/frontend/src/views/Workout.jsx index 9c49f67..f2aaf53 100644 --- a/frontend/src/views/Workout.jsx +++ b/frontend/src/views/Workout.jsx @@ -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 } from '../lib/supersetFlow.js' +import { setProgressHighWater, supersetFlowStep, restAfterSet, restOnRecheck } from '../lib/supersetFlow.js' import Media from '../components/Media.jsx' import { startFlow, exercisePicker, exConfigSheet, exerciseDetailSheet, topWeightSheet, finishWorkout, workoutCompleteSheet, confirmSheet, exerciseNoteSheet } from '../sheets.jsx' import Icon from '../components/Icon.jsx' @@ -411,7 +411,6 @@ function ActiveWorkout() { if (fresh && checked && fresh.entries[idx]) { const progress = setProgressHighWater(fresh.entries[idx], progressHighWater.current[idx] || 0) progressHighWater.current[idx] = progress.highWater - if (!progress.isNew) return const freshUnits = supersetUnits(fresh.entries) const freshUnit = freshUnits.find(u => u.includes(idx)) @@ -419,6 +418,13 @@ function ActiveWorkout() { const freshLastUnit = freshUnitIdx >= freshUnits.length - 1 const freshUnitDone = freshUnit?.every(ui => fresh.entries[ui].sets.every(x => x.done)) + // 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) + return + } + // Singleton units are ordinary exercises: they rest between sets and after the closing // one, and never enter superset navigation. stopRest() first so the rest that belongs // after this set replaces the one that was running, rather than stacking on it.