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.

workout: give back the rest a re-checked set used to swallow

Duarte Santosb28115a8f974
diff --git a/frontend/src/lib/supersetFlow.js b/frontend/src/lib/supersetFlow.js
index 07eb2023b..4b8c8fb2b 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 b5682db3e..91864f118 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 9c49f674e..f2aaf53c7 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.