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.

fix(workout): scroll to the next superset member in list/compact

Sebastian Gcf1631d6290f
diff --git a/frontend/src/index.css b/frontend/src/index.css
index 875f25be3..68cea9523 100644
--- a/frontend/src/index.css
+++ b/frontend/src/index.css
@@ -1851,6 +1851,11 @@ body.no-tabbar.resting #toast{bottom:calc(100px + var(--sab))}
measures the header (--whdr-h on .workout-list, safe area included) because it grows when
the session name wraps; the fallback is the height of a one-line header. */
.wl-unit{scroll-margin-top:calc(var(--whdr-h, var(--sat) + var(--conn) + 80px) + 16px)}
+/* A superset is one unit, so finishing a member and moving to the next scrolls to that member's
+ own row (Workout.jsx), not the unit: the row needs the same clearance under the sticky header,
+ since scroll-margin does not inherit from the .wl-unit around it. Scoped to the list so Cards,
+ which has no pinned header, is untouched. */
+.workout-list .setrow,.workout-list .setrow-side{scroll-margin-top:calc(var(--whdr-h, var(--sat) + var(--conn) + 80px) + 16px)}
.wl-unit.cur{box-shadow:inset 0 0 0 1.5px var(--acc-line)}
.wl-hd{display:flex;align-items:center;justify-content:space-between;gap:8px;margin-bottom:10px}
.wl-summary{display:grid;gap:8px;padding-bottom:10px}
diff --git a/frontend/src/views/Workout.jsx b/frontend/src/views/Workout.jsx
index ab8f2d316..2b34fbd1c 100644
--- a/frontend/src/views/Workout.jsx
+++ b/frontend/src/views/Workout.jsx
@@ -1075,7 +1075,15 @@ function ActiveWorkout() {
const was = lastCur.current
lastCur.current = cur
const moved = was != null && was !== cur
- if (!isSuperset || listMode) return
+ if (!isSuperset) return
+ // A superset is one card in every layout, so moving the marker from one member to the next
+ // does not change which `.wl-unit` is current: the list's own scroll (to `.wl-unit.cur`)
+ // stands still, and the partner's row stays below the fold. The member rows carry their refs
+ // in the list too, so the next member's row is brought into view here the same way the cards
+ // view does it — but only when the marker moved WITHIN this superset (member → member). A
+ // move that leaves the unit (the next unit after a round, revealCur) is the list's own job,
+ // and mount/pairing/layout switches are not moves at all, where the list leaves "current" put.
+ if (listMode && (!moved || !unit.includes(was))) return
// A run the marker did not cause, with a sheet closing in the same tap, never scrolled: the
// restore undid it. Keep that by not asking at all. Asking after the restore and then judging
// the row would centre a first row that a tall first block (a note, "Last time", the
@@ -1094,7 +1102,17 @@ function ActiveWorkout() {
const el = (setIdx >= 0 && setRefs.current.get(entry)?.get(setIdx)) || exRefs.current.get(entry)
if (!el || typeof el.scrollIntoView !== 'function') return
if (!moved && rowOnScreen(el)) return
- el.scrollIntoView({ behavior: 'smooth', block: 'center' })
+ // In the list the header is pinned over the page: land the row below it (block:'start',
+ // fed the header's current height like scrollToUnit) rather than centred behind it. Cards
+ // has no pinned header, so the actionable row is centred as it was.
+ if (listMode) {
+ const hdrH = hdrRef.current?.offsetHeight
+ if (hdrH) listRef.current?.style.setProperty('--whdr-h', hdrH + 'px')
+ const still = typeof window.matchMedia === 'function' && window.matchMedia('(prefers-reduced-motion: reduce)').matches
+ el.scrollIntoView(still ? { block: 'start' } : { block: 'start', behavior: 'smooth' })
+ } else {
+ el.scrollIntoView({ behavior: 'smooth', block: 'center' })
+ }
})
}, [cur, isSuperset, listMode, A.entries.length])
// The list opens at the exercise you are on, not at the top of the session (issue #224): you
diff --git a/frontend/src/views/Workout.superset-list-scroll.test.jsx b/frontend/src/views/Workout.superset-list-scroll.test.jsx
new file mode 100644
index 000000000..c12c7c42b
--- /dev/null
+++ b/frontend/src/views/Workout.superset-list-scroll.test.jsx
@@ -0,0 +1,153 @@
+import React, { act } from 'react'
+import { createRoot } from 'react-dom/client'
+import { parseHTML } from 'linkedom'
+import { afterEach, beforeEach, describe, expect, it, vi } from 'vitest'
+import Workout from './Workout.jsx'
+import { makeSideSet } from '../lib/workout-model.js'
+
+// In list and compact view a superset is one `.wl-unit`, so moving the marker from one member to
+// the next does not change which unit is "current": scrolling to `.wl-unit.cur` is a no-op. The
+// member rows carry their own refs all the same, so completing a set still brings the next
+// member's actionable row into view — the same anchor the cards view gives (issue: supersets no
+// longer scroll to where you continue in list/compact, one-sided exercises most visibly).
+const mocks = vi.hoisted(() => {
+ const state = {
+ S: null, timer: null, work: null,
+ startRest: vi.fn(), startWork: vi.fn(), toast: vi.fn(), menuSheet: vi.fn(),
+ stopRest: null, stopWork: null,
+ afterScrollRestore: vi.fn(fn => { fn(); return () => {} }),
+ scrollRestorePending: vi.fn(() => false),
+ }
+ state.stopRest = vi.fn(() => { state.timer = null })
+ state.stopWork = vi.fn(() => { state.work = null })
+ state.storeSnapshot = () => ({
+ S: state.S, user: null,
+ update: mut => { const next = structuredClone(state.S); mut(next); state.S = next },
+ })
+ state.uiSnapshot = () => ({
+ timer: state.timer, work: state.work,
+ startRest: state.startRest, stopRest: state.stopRest, stopWork: state.stopWork,
+ shiftRestOwner: vi.fn(), startWork: state.startWork, toast: state.toast,
+ })
+ return state
+})
+
+vi.mock('../store/useStore.js', () => {
+ const useStore = selector => selector(mocks.storeSnapshot())
+ useStore.getState = mocks.storeSnapshot
+ return { useStore }
+})
+vi.mock('../store/useUI.js', () => {
+ const useUI = selector => selector ? selector(mocks.uiSnapshot()) : mocks.uiSnapshot()
+ useUI.getState = mocks.uiSnapshot
+ return { useUI }
+})
+vi.mock('react-router-dom', () => ({ useNavigate: () => () => {} }))
+vi.mock('../sheets.jsx', () => ({
+ startFlow: vi.fn(), exercisePicker: vi.fn(), exConfigSheet: vi.fn(), exerciseDetailSheet: vi.fn(),
+ finishWorkout: vi.fn(), finishWorkoutSheet: vi.fn(), exitWorkoutEdit: vi.fn(), workoutCompleteSheet: vi.fn(), confirmSheet: vi.fn(),
+ swapActiveWorkoutExercise: vi.fn(), menuSheet: mocks.menuSheet, barWeightSheet: vi.fn(),
+ exerciseNoteSheet: vi.fn(), sessionNoteSheet: vi.fn(), renameWorkoutSheet: vi.fn(),
+ effortPickerSheet: vi.fn(), exerciseHistorySheet: vi.fn(), addRoutineToSessionSheet: vi.fn(),
+}))
+vi.mock('../components/Media.jsx', () => ({ default: () => null }))
+vi.mock('../components/Modals.jsx', () => ({ afterScrollRestore: mocks.afterScrollRestore, scrollRestorePending: mocks.scrollRestorePending }))
+vi.mock('../lib/api.js', () => ({
+ api: vi.fn(() => Promise.resolve({})), IS_APPLE: false, IS_ANDROID: false, BIO: 'biometrics',
+}))
+
+let dom, root, container
+
+const normal = (id, sg) => ({
+ id, sg,
+ target: { mode: 'reps', sets: 2, reps: 8, weight: 60, restSec: 60 },
+ sets: Array.from({ length: 2 }, () => ({ r: 8, w: 60, done: false })),
+})
+const oneSided = (id, sg) => ({
+ id, sg,
+ target: { mode: 'reps', side: true, sets: 2, reps: 16, weight: 20, restSec: 60 },
+ sets: Array.from({ length: 2 }, () => makeSideSet({ r: 16, w: 20 })),
+})
+
+function installDom() {
+ const parsed = parseHTML('<!doctype html><html><body><div id="root"></div></body></html>')
+ dom = parsed.window
+ globalThis.window = dom
+ globalThis.document = dom.document
+ Object.defineProperty(globalThis, 'navigator', { configurable: true, value: dom.navigator })
+ for (const key of ['HTMLElement', 'Node', 'Element', 'Event', 'Blob']) globalThis[key] = dom[key]
+ dom.Element.prototype.scrollIntoView = vi.fn()
+ dom.requestAnimationFrame = cb => { cb(); return 0 }
+ dom.cancelAnimationFrame = () => {}
+ dom.matchMedia = () => ({ matches: false })
+ globalThis.IS_REACT_ACT_ENVIRONMENT = true
+ container = document.getElementById('root')
+ root = createRoot(container)
+}
+
+// The partner member's rows sit below the first member's in the one superset card. We watch the
+// element scrollIntoView was called on.
+async function mount(entries, cur = 0, view = 'list') {
+ mocks.S = {
+ unit: 'kg', restSec: 90, sound: false, effort: 'none', gifSize: 'full', collapseCompleted: false,
+ workouts: [], exWeights: {}, routines: [],
+ active: { id: 'active', name: 'Test', start: Date.now(), cur, entries, workoutView: view },
+ }
+ installDom()
+ dom.innerHeight = 659
+ // Everything on screen by default; a test overrides geometry where it matters.
+ dom.Element.prototype.getBoundingClientRect = () => ({ top: 400, bottom: 444, left: 0, right: 390, width: 390, height: 44 })
+ await act(async () => { root.render(React.createElement(Workout)) })
+}
+const rerender = () => act(async () => { root.render(React.createElement(Workout)) })
+async function press(button) { expect(button).toBeTruthy(); await act(async () => { button.dispatchEvent(new dom.Event('click', { bubbles: true })) }) }
+const watchScrolls = () => { const seen = []; dom.Element.prototype.scrollIntoView = vi.fn(function () { seen.push(this) }); return seen }
+const box = pred => [...container.querySelectorAll('[role="checkbox"]')].find(b => pred(b.getAttribute('aria-label') || ''))
+
+beforeEach(() => {
+ mocks.timer = null; mocks.work = null
+ mocks.afterScrollRestore.mockReset(); mocks.afterScrollRestore.mockImplementation(fn => { fn(); return () => {} })
+ mocks.scrollRestorePending.mockReset(); mocks.scrollRestorePending.mockImplementation(() => false)
+})
+afterEach(async () => {
+ if (root) await act(async () => { root.unmount() })
+ root = null; container = null; dom = null
+})
+
+for (const view of ['list', 'compact']) {
+ describe(`${view} view: a superset scrolls to the next member`, () => {
+ it('a normal member completing moves to the partner row', async () => {
+ await mount([normal('0025', 'g'), normal('0043', 'g'), normal('0001')], 0, view)
+ // The header has a height, so the list feeds it to --whdr-h and the row clears it.
+ Object.defineProperty(dom.HTMLElement.prototype, 'offsetHeight', { configurable: true, get() { return this.className?.includes('whdr') && !this.className.includes('whdr-') ? 120 : 0 } })
+ const seen = watchScrolls()
+ // first member A set 0 — its checkbox is the first on screen
+ await press(container.querySelector('[role="checkbox"]'))
+ await rerender()
+ expect(mocks.S.active.cur).toBe(1)
+ // The partner B's first row is the 3rd .setrow (A has 2, then B's first).
+ const partnerRow = container.querySelectorAll('.setrow')[2]
+ expect(seen).toContain(partnerRow)
+ // The row is scrolled to the top under the pinned header, with the header's height fed to
+ // --whdr-h so the row's scroll-margin (index.css) clears it rather than hiding behind it.
+ expect(container.querySelector('.workout-list').style.getPropertyValue('--whdr-h')).toBe('120px')
+ })
+
+ it('a one-sided member scrolls to the partner once both sides are ticked', async () => {
+ await mount([oneSided('0025', 'g'), normal('0043', 'g'), normal('0001')], 0, view)
+ const seen = watchScrolls()
+ // A set 0 Left — no advance, no scroll yet
+ await press(box(l => /Left/.test(l) && /Set 1/.test(l))); await rerender()
+ expect(mocks.S.active.cur).toBe(0)
+ expect(seen).toHaveLength(0)
+ // A set 0 Right — set done, advance to partner B, scroll to B's row
+ await press(box(l => /Right/.test(l) && /Set 1/.test(l))); await rerender()
+ expect(mocks.S.active.cur).toBe(1)
+ // A (one-sided) rows carry both `setrow` and `side`; B (normal) rows are a plain `.setrow`.
+ // The partner is B's first unticked plain row.
+ const partnerRow = [...container.querySelectorAll('.setrow:not(.side)')].find(el => !el.className.includes('done'))
+ expect(partnerRow).toBeTruthy()
+ expect(seen).toContain(partnerRow)
+ })
+ })
+}
diff --git a/frontend/src/views/Workout.superset-scroll.test.jsx b/frontend/src/views/Workout.superset-scroll.test.jsx
index 432ada107..f6c8b6334 100644
--- a/frontend/src/views/Workout.superset-scroll.test.jsx
+++ b/frontend/src/views/Workout.superset-scroll.test.jsx
@@ -221,15 +221,22 @@ describe('the superset card after a rating', () => {
})
// The marker moved while the List was up, where this scroll never runs; the switch back to
// Cards is not that move. The marker's position is remembered on every run, early return or not.
- it('a marker moved in the List does not scroll once Cards comes back', async () => {
+ // Ticking a set in the list now brings the next member into view there (a superset is one unit,
+ // so scrolling to `.wl-unit.cur` would not), but switching back to Cards is not itself a move
+ // and must not scroll again.
+ it('a marker moved in the List does not scroll again once Cards comes back', async () => {
await mount(superset(), 0, {}, () => rowsAt(400))
const seen = watchScrolls()
mocks.storeSnapshot().update(s => { s.active.workoutView = 'list' }); await rerender()
await press(container.querySelector('[role="checkbox"]'))
await rerender()
expect(mocks.S.active.cur).toBe(1)
+ // The tick in the list brought the partner's row into view once.
+ expect(seen).toHaveLength(1)
+ const afterListTick = seen.length
mocks.storeSnapshot().update(s => { s.active.workoutView = 'cards' }); await rerender()
- expect(seen).toEqual([])
+ // The switch back to Cards is not a marker move: no further scroll.
+ expect(seen).toHaveLength(afterListTick)
})
// A session started through the weigh-in sheet, its first block tall enough to push the first
// row partly under the tab bar: off screen by the rule above, but the sheet's restore is still