List view opens at the current exercise instead of the top of the session (#224)

This commit is contained in:
Duarte Santos committed 2026-09-17 11:32:31 +02:00
1 parent a41b0ca60f
commit 69fd4a8344
3 files changed
+20 -1

No files matched your search

+2
View File
@@ -1149,6 +1149,8 @@ body.chips-dragging *{cursor:inherit}
border-radius:var(--r-lg);padding:14px 14px 4px;
background:var(--surface-2);
}
/* scrolled to when the list opens (#224): clear the sticky header above it */
.wl-unit{scroll-margin-top:calc(var(--sat) + 96px)}
.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}
@media (max-width:400px){
+11 -1
View File
@@ -578,6 +578,16 @@ function ActiveWorkout() {
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, listMode, A.entries.length])
// The list opens at the exercise you are on, not at the top of the session (issue #224): you
// switch to it mid-workout to look at what comes before and after. Only on the way in — once
// the list is open, "current" moves because you tick rows in it, and a list that scrolls
// itself under your thumb is worse than one that stays put.
const listRef = useRef(null)
useEffect(() => {
if (!listMode) return
const el = listRef.current?.querySelector('.wl-unit.cur')
if (el && typeof el.scrollIntoView === 'function') el.scrollIntoView({ block: 'start' })
}, [listMode])
const total = setUnitsTotal(A.entries)
const done = setsDoneActive(A)
@@ -946,7 +956,7 @@ function ActiveWorkout() {
{A.backfill && <div className="muted small" style={{ marginBottom: 8 }}>{t('Logging a past workout — no rest timers.')}</div>}
{A.entries.length ? (listMode ? (
<div className="workout-list" data-testid="workout-list">
<div className="workout-list" data-testid="workout-list" ref={listRef}>
{units.map((u, ui) => {
const multi = u.length > 1
const isCur = u.includes(cur)
+7
View File
@@ -1012,6 +1012,13 @@ describe('workout list view', () => {
const units = () => [...container.querySelectorAll('.wl-unit')]
const focusButton = unit => [...unit.querySelectorAll('button')].find(b => b.textContent.trim() === 'Set current')
it('opens at the current exercise instead of the top of the session (#224)', async () => {
await mount([exercise('plain-bench', [true]), exercise('plain-row', [true]), exercise('plain-curl', [false])], 2, { workoutView: 'list' })
expect(mocks.scrollCalls.length).toBe(1)
expect(mocks.scrollCalls[0].node).toBe(units()[2])
expect(mocks.scrollCalls[0].node.classList.contains('cur')).toBe(true)
})
it('stacks every exercise, labels each unit, and hides card navigation', async () => {
await mount([exercise('plain-bench', [false, false]), exercise('plain-row', [false])], 0, { workoutView: 'list' })