diff --git a/frontend/src/lib/supersetFlow.js b/frontend/src/lib/supersetFlow.js
new file mode 100644
index 0000000..c78e72c
--- /dev/null
+++ b/frontend/src/lib/supersetFlow.js
@@ -0,0 +1,28 @@
+// Pure decisions for the active-workout superset flow. Keeping these independent of React and
+// the stores makes the uneven-round and re-check rules explicit and directly testable.
+const hasWork = (entries, idx) => !!entries[idx]?.sets?.some(set => !set.done)
+
+// A completion is new progress only when it takes this exercise beyond the largest number of
+// simultaneously completed sets seen in this mounted session. Uncheck/re-check therefore does
+// not repeat navigation or rest side effects, while completing an added set still can.
+export function setProgressHighWater(entry, previous = 0) {
+ const done = entry?.sets?.reduce((count, set) => count + (set.done ? 1 : 0), 0) || 0
+ return { isNew: done > previous, highWater: Math.max(previous, done) }
+}
+
+// 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.
+export function supersetFlowStep(entries, unit, fromIdx) {
+ if (!Array.isArray(entries) || !Array.isArray(unit) || unit.length <= 1) return null
+ const pos = unit.indexOf(fromIdx)
+ if (pos < 0) return null
+
+ const unitDone = !unit.some(idx => hasWork(entries, idx))
+ if (unitDone) return { unitDone: true, roundDone: false, nextIdx: null }
+
+ const wrapped = [...unit.slice(pos + 1), ...unit.slice(0, pos + 1)]
+ const nextIdx = wrapped.find(idx => hasWork(entries, idx)) ?? null
+ const roundDone = !unit.slice(pos + 1).some(idx => hasWork(entries, idx))
+ return { unitDone: false, roundDone, nextIdx }
+}
diff --git a/frontend/src/lib/supersetFlow.test.js b/frontend/src/lib/supersetFlow.test.js
new file mode 100644
index 0000000..2c96a16
--- /dev/null
+++ b/frontend/src/lib/supersetFlow.test.js
@@ -0,0 +1,36 @@
+import { describe, expect, it } from 'vitest'
+import { setProgressHighWater, supersetFlowStep } from './supersetFlow.js'
+
+const entry = done => ({ sets: done.map(value => ({ done: value })) })
+
+describe('supersetFlowStep', () => {
+ it('does not create navigation or rest flow for a normal singleton exercise', () => {
+ const entries = [entry([true]), entry([false])]
+ expect(supersetFlowStep(entries, [0], 0)).toBeNull()
+ })
+
+ it('does not count an uncheck/re-check of previously completed work as new progress', () => {
+ const finished = entry([true, true, true])
+ expect(setProgressHighWater(finished, 3)).toEqual({ isNew: false, highWater: 3 })
+ expect(setProgressHighWater(finished, 2)).toEqual({ isNew: true, highWater: 3 })
+ })
+
+ it('skips a spent short member and uses the last member with work as the round boundary', () => {
+ // A has just completed set two of three; B's only set was completed last round.
+ const entries = [entry([true, true, false]), entry([true])]
+ expect(supersetFlowStep(entries, [0, 1], 0)).toEqual({
+ unitDone: false,
+ roundDone: true,
+ nextIdx: 0
+ })
+ })
+
+ it('wraps to the next member with work at a normal round boundary', () => {
+ const entries = [entry([true, false, false]), entry([true])]
+ expect(supersetFlowStep(entries, [0, 1], 1)).toEqual({
+ unitDone: false,
+ roundDone: true,
+ nextIdx: 0
+ })
+ })
+})
diff --git a/frontend/src/views/Workout.jsx b/frontend/src/views/Workout.jsx
index 0d6493e..606168e 100644
--- a/frontend/src/views/Workout.jsx
+++ b/frontend/src/views/Workout.jsx
@@ -1,4 +1,4 @@
-import { useEffect, useState } from 'react'
+import { useEffect, useRef, useState } from 'react'
import { useNavigate } from 'react-router-dom'
import { useStore } from '../store/useStore.js'
import { useUI } from '../store/useUI.js'
@@ -8,6 +8,7 @@ import { fmtNum, fmtDate, todayISO, exCount, DAYN } from '../lib/format.js'
import { beep, vibrate } from '../lib/sound.js'
import { t } from '../lib/i18n.js'
import { api } from '../lib/api.js'
+import { setProgressHighWater, supersetFlowStep } from '../lib/supersetFlow.js'
import Media from '../components/Media.jsx'
import { startFlow, exercisePicker, exConfigSheet, exerciseDetailSheet, topWeightSheet, finishWorkout, workoutCompleteSheet, confirmSheet } from '../sheets.jsx'
import Icon from '../components/Icon.jsx'
@@ -196,6 +197,15 @@ function ActiveWorkout() {
const unit = A.entries.length ? unitOf(units, cur) : []
const unitIdx = units.findIndex(u => u === unit)
const isSuperset = unit.length > 1
+ // Superset flow: keep the active exercise in view - completing a set scrolls to the
+ // next exercise in the group, then back up to the first exercise of the next round.
+ const exRefs = useRef({})
+ const progressHighWater = useRef(A.entries.map(e => e.sets.filter(s => s.done).length))
+ useEffect(() => {
+ if (!isSuperset) return
+ const el = exRefs.current[cur]
+ if (el && typeof el.scrollIntoView === 'function') el.scrollIntoView({ behavior: 'smooth', block: 'nearest' })
+ }, [cur, isSuperset, A.entries.length])
const total = A.entries.reduce((n, e) => n + e.sets.length, 0)
const done = setsDoneActive(A)
@@ -282,15 +292,13 @@ function ActiveWorkout() {
const m = modeAt(idx)
const cardioEntry = m === 'cardio'
const isLastUnit = unitIdx >= units.length - 1
- let askTop = false, exJustDone = false, workoutDone = false
+ let askTop = false, exJustDone = false, workoutDone = false, checked = false
mutEntry(idx, e => {
e.sets[i].done = !e.sets[i].done
+ checked = e.sets[i].done
if (e.sets[i].done) {
beep(S.sound, 1040, 0.12); vibrate(30)
- const isLastExInUnit = idx === unit[unit.length - 1]
const unitDone = unit.every(ui => (ui === idx ? e : A.entries[ui]).sets.every(x => x.done))
- if (isLastExInUnit && !unitDone) startRest(S.restSec)
- else if (unitDone) stopRest()
if (unitDone && isLastUnit) workoutDone = true // last exercise's last set โ done
// Only loaded reps training has a "working weight" worth confirming โ a bodyweight
// plank has nothing to put in that slider, and neither does a set of push-ups
@@ -305,6 +313,43 @@ function ActiveWorkout() {
else if (workoutDone) workoutCompleteSheet()
else if (exJustDone && cardioEntry) useUI.getState().toast(t('Cardio logged'))
else if (exJustDone && m === 'time') useUI.getState().toast(t('Hold logged'))
+
+ // Only progress beyond this exercise's high-water mark may navigate or change rest. This
+ // prevents an uncheck/re-check of finished work from replaying the flow side effects.
+ const fresh = useStore.getState().S.active
+ 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))
+ const freshUnitIdx = freshUnits.indexOf(freshUnit)
+ const freshLastUnit = freshUnitIdx >= freshUnits.length - 1
+ const freshUnitDone = freshUnit?.every(ui => fresh.entries[ui].sets.every(x => x.done))
+
+ // Singleton units are ordinary exercises: preserve their historical between-set rest,
+ // while final sets finish quietly and never enter superset navigation.
+ if (freshUnitDone) stopRest()
+ if (!freshUnit || freshUnit.length <= 1) {
+ if (!freshUnitDone) startRest(S.restSec)
+ return
+ }
+
+ const step = supersetFlowStep(fresh.entries, freshUnit, idx)
+ if (!step) return
+ if (step.unitDone) {
+ if (!freshLastUnit) {
+ 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)
+ }
+ } else {
+ if (step.nextIdx != null) update(s => { if (s.active) s.active.cur = step.nextIdx })
+ if (step.roundDone) startRest(S.restSec)
+ }
+ }
}
// Live-presence heartbeat so the admin dashboard can show who's training now. Signed-in only โ
@@ -350,7 +395,7 @@ function ActiveWorkout() {