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(focus): the speed stepper reads, steps and stores in the profile's speed unit

Duarte Santos6ec6e5610c09
diff --git a/frontend/src/views/FocusView.jsx b/frontend/src/views/FocusView.jsx
index 9239056c7..64af52dd9 100644
--- a/frontend/src/views/FocusView.jsx
+++ b/frontend/src/views/FocusView.jsx
@@ -13,6 +13,7 @@ import {
setDropAt, setSideClusterAt, setSideDropAt, setSideField,
} from '../lib/workout-model.js'
import { weightIncrement, stepWeight } from '../lib/progression.js'
+import { speedUnitOf, toSpeed, fromSpeed } from '../lib/speed.js'
import { effortPickerSheet, exerciseDetailSheet, exerciseHistorySheet, exerciseNoteSheet, menuSheet, barWeightSheet } from '../sheets.jsx'
import { baseWeightFor, inventoryFor, loadKindFor, rowLoad } from '../lib/plates.js'
import Icon from '../components/Icon.jsx'
@@ -104,6 +105,7 @@ export default function FocusView({
onNoProg, busy, onSelectEntry, onAdvanceUnit, onPairPrev, onPairNext, onUnpair, pointerEpoch,
}) {
const S = useStore(state => state.S)
+ const speedUnit = speedUnitOf(S)
const entry = S.active.entries[entryIdx]
const ex = exOr(entry.id)
const last = lastEntryFor(S, entry.id)
@@ -277,8 +279,10 @@ export default function FocusView({
{mode === 'cardio' ? <>
<Stepper label={t('Duration (min)')} ariaLabel="duration" value={set.min || 0} step={1} decimal={false} disabled={readOnly}
onChange={value => onField(setIdx, 'min', value)} />
- <Stepper label={t('Speed (km/h)')} ariaLabel="speed" value={set.speed || 0} step={0.5} disabled={readOnly}
- onChange={value => onField(setIdx, 'speed', value)} />
+ {/* Stored in km/h, shown and typed in the profile's speed unit, as on every other
+ cardio input (lib/speed.js). */}
+ <Stepper label={speedUnit === 'mph' ? t('Speed (mph)') : t('Speed (km/h)')} ariaLabel="speed" value={toSpeed(set.speed || 0, speedUnit)} step={0.5} disabled={readOnly}
+ onChange={value => onField(setIdx, 'speed', fromSpeed(value, speedUnit))} />
</> : <>
<Stepper label={t('Load ({0})', S.unit)} ariaLabel="load" value={set.w || 0} step={loadStep} onStep={stepWeight} disabled={readOnly}
onChange={value => onField(setIdx, 'w', value)} />
diff --git a/frontend/src/views/FocusView.test.jsx b/frontend/src/views/FocusView.test.jsx
index fde8625e0..a39bafba2 100644
--- a/frontend/src/views/FocusView.test.jsx
+++ b/frontend/src/views/FocusView.test.jsx
@@ -16,9 +16,10 @@ const SQUAT = '0043'
let root, container, sheetRoot, sheetContainer
-function mount(entry) {
+function mount(entry, over = {}) {
const S = clone(DEF)
S.unit = 'lb'
+ Object.assign(S, over)
S.active = {
id: 'focus-test', d: '2026-09-28', start: Date.now(), routineId: null,
name: 'Focus', bw: null, cur: 0, workoutView: 'focus', entries: [entry],
@@ -123,3 +124,40 @@ describe('Focus workout view', () => {
expect(useStore.getState().S.active.entries[0].sets[0].clusters[0].restSec).toBe(7)
})
})
+
+// The speed stepper follows the profile's speed unit like the set row does (lib/speed.js): shown,
+// stepped and typed in mph, stored in km/h. It used to say km/h whatever the setting.
+describe('Focus view cardio speed', () => {
+ const BIKE = '2138' // stationary bike, cardio
+ const bike = () => ({ id: BIKE, target: { sets: 1, min: 20, speed: 8 }, sets: [{ min: 20, speed: 8, done: false }] })
+ const cell = () => container.querySelector('button[aria-label="Increase speed"]').closest('.stp-w')
+ const stored = () => useStore.getState().S.active.entries[0].sets[0].speed
+ const type = value => {
+ const input = cell().querySelector('input')
+ act(() => {
+ Object.getOwnPropertyDescriptor(input.constructor.prototype, 'value').set.call(input, value)
+ input.dispatchEvent(new Event('input', { bubbles: true }))
+ })
+ }
+
+ it('reads, steps and takes typing in mph for a profile in pounds, and stores km/h', () => {
+ mount(bike())
+ expect(cell().querySelector('.stp-l').textContent).toBe('Speed (mph)')
+ expect(cell().querySelector('input').value).toBe('4.97') // 8 km/h
+ act(() => container.querySelector('button[aria-label="Increase speed"]').click())
+ expect(stored()).toBe(8.8)
+ type('6')
+ expect(stored()).toBe(9.66)
+ })
+
+ it('follows a chosen unit over the weight unit, and leaves km/h as it was', () => {
+ mount(bike(), { unit: 'kg', speedUnit: 'mph' })
+ expect(cell().querySelector('.stp-l').textContent).toBe('Speed (mph)')
+ act(() => root.unmount()); container.remove()
+ mount(bike(), { speedUnit: 'kmh' })
+ expect(cell().querySelector('.stp-l').textContent).toBe('Speed (km/h)')
+ expect(cell().querySelector('input').value).toBe('8')
+ act(() => container.querySelector('button[aria-label="Increase speed"]').click())
+ expect(stored()).toBe(8.5)
+ })
+})