{cell(s, i, col1, 'w')}
{col2 && cell(s, i, col2, 'r')}
@@ -282,9 +282,28 @@ 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({})
+ // Superset flow: center the actionable row when completing a set moves to the partner or
+ // back to the first exercise of the next round. Entry-bound maps keep repeated exercise IDs
+ // distinct, while each rendered set index identifies the existing row within that entry.
+ const exRefs = useRef(new Map())
+ const setRefs = useRef(new Map())
+ const bindExRef = (entry, el) => {
+ if (el) exRefs.current.set(entry, el)
+ else {
+ exRefs.current.delete(entry)
+ setRefs.current.delete(entry)
+ }
+ }
+ const bindSetRef = (entry, setIdx, el) => {
+ let refs = setRefs.current.get(entry)
+ if (el) {
+ if (!refs) { refs = new Map(); setRefs.current.set(entry, refs) }
+ refs.set(setIdx, el)
+ } else if (refs) {
+ refs.delete(setIdx)
+ if (!refs.size) setRefs.current.delete(entry)
+ }
+ }
const progressHighWater = useRef(A.entries.map(e => e.sets.filter(s => s.done).length))
// The marks are index-keyed, and removing an exercise shifts every index above it down
// (removeActiveExercise splices). Re-baseline whenever the list length changes, otherwise a
@@ -292,10 +311,22 @@ function ActiveWorkout() {
useEffect(() => {
progressHighWater.current = A.entries.map(e => e.sets.filter(s => s.done).length)
}, [A.entries.length])
+ useEffect(() => {
+ const liveEntries = new Set(A.entries)
+ for (const entry of exRefs.current.keys()) {
+ if (!liveEntries.has(entry)) exRefs.current.delete(entry)
+ }
+ for (const entry of setRefs.current.keys()) {
+ if (!liveEntries.has(entry)) setRefs.current.delete(entry)
+ }
+ })
useEffect(() => {
if (!isSuperset) return
- const el = exRefs.current[cur]
- if (el && typeof el.scrollIntoView === 'function') el.scrollIntoView({ behavior: 'smooth', block: 'nearest' })
+ const entry = A.entries[cur]
+ const firstIncomplete = entry?.sets.findIndex(s => !s.done) ?? -1
+ const setIdx = firstIncomplete >= 0 ? firstIncomplete : (entry?.sets.length ?? 0) - 1
+ const el = (setIdx >= 0 && setRefs.current.get(entry)?.get(setIdx)) || exRefs.current.get(entry)
+ if (el && typeof el.scrollIntoView === 'function') el.scrollIntoView({ behavior: 'smooth', block: 'center' })
}, [cur, isSuperset, A.entries.length])
const total = A.entries.reduce((n, e) => n + e.sets.length, 0)
@@ -493,11 +524,14 @@ function ActiveWorkout() {
{t('Superset · do these back-to-back, rest when done')}