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 chips: in the list a chip tap lights its chip and scrolls, Current stays put (#323, #622)

Duarte Santos58781ba0cc86
diff --git a/frontend/src/views/Workout.jsx b/frontend/src/views/Workout.jsx
index d79809369..1457b2040 100644
--- a/frontend/src/views/Workout.jsx
+++ b/frontend/src/views/Workout.jsx
@@ -1916,11 +1916,13 @@ function ActiveWorkout() {
const still = typeof window.matchMedia === 'function' && window.matchMedia('(prefers-reduced-motion: reduce)').matches
el.scrollIntoView(glide && !still ? { block: 'start', behavior: 'smooth' } : { block: 'start' })
}
- // Explicit chip selection moves the marker in every view; list views also reveal the unit.
+ // A tap on a chip at the top (#323). Cards and Focus show one unit, so the chip makes it the one
+ // on screen: the marker moves because you asked it to, never on its own. The list already shows
+ // every unit, so there the chip scrolls to it and lights up, and "Current" stays where it was,
+ // the same as scrolling there by hand; the frame wait is the one opening the list uses (above).
const pickChip = chip => {
- setVisibleExercise(chip.unit[0])
- if (!chip.unit.includes(cur)) update(s => { if (s.active) s.active.cur = chip.unit[0] })
if (listMode) {
+ setVisibleExercise(chip.unit[0])
// A folded unit opens as you jump to it: you tapped it to see it.
if (collapsed.has(chip.key)) setUnitOpen(chip.key, true)
const go = () => scrollToUnit(listRef.current?.querySelector(`.wl-unit[data-unit-key="${chip.key}"]`), true)
@@ -1928,6 +1930,8 @@ function ActiveWorkout() {
else window.setTimeout(go, 0)
return
}
+ if (chip.unit.includes(cur)) return
+ update(s => { if (s.active) s.active.cur = chip.unit[0] })
}
const chipRow = wc.exerciseChips && A.entries.length > 0
? <WorkoutChips entries={A.entries} cur={listMode ? visibleExercise : cur} onPick={pickChip} />
diff --git a/frontend/src/views/Workout.keys.test.jsx b/frontend/src/views/Workout.keys.test.jsx
index d419a30b1..64c6bf0d3 100644
--- a/frontend/src/views/Workout.keys.test.jsx
+++ b/frontend/src/views/Workout.keys.test.jsx
@@ -105,7 +105,10 @@ describe('workout keys (issue #133)', () => {
const chips = () => [...container.querySelectorAll('.wchip')]
expect(chips()[0].getAttribute('aria-current')).toBe('step')
act(() => chips()[1].click())
- expect(active().cur).toBe(1)
+ // Cards and Focus show the tapped unit, so it becomes Current; the list scrolls to it and
+ // lights its chip, and Current stays where it was (#323).
+ const listy = workoutView === 'compact' || workoutView === 'list'
+ expect(active().cur).toBe(listy ? 0 : 1)
expect(chips()[1].getAttribute('aria-current')).toBe('step')
expect(chips()[0].hasAttribute('aria-current')).toBe(false)
act(() => chips()[0].click())