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.

Rest wheel: Done without scrolling leaves the rest alone, +15 s stops at 15:00

Duarte Santosdb42c55d9b3e
diff --git a/frontend/src/components/RestTimer.dock.test.jsx b/frontend/src/components/RestTimer.dock.test.jsx
index a59990c51..041114e7e 100644
--- a/frontend/src/components/RestTimer.dock.test.jsx
+++ b/frontend/src/components/RestTimer.dock.test.jsx
@@ -89,6 +89,50 @@ describe('the docked rest bar', () => {
expect(useUI.getState().timer.ready).toBeUndefined()
})
+ it('Done on an untouched wheel leaves the rest alone', () => {
+ // still counting: the seconds that passed while the wheel was open are not given back
+ act(() => useUI.getState().startRest(60, 0))
+ mount()
+ act(() => host.querySelector('#timer .tclock').click())
+ act(() => vi.advanceTimersByTime(10_000))
+ let { el, r } = sheetHost()
+ act(() => { [...el.querySelectorAll('button')].find(b => b.textContent === 'Done').click() })
+ act(() => r.unmount()); el.remove()
+ expect(useUI.getState().timer.left).toBe(50)
+
+ // ran out meanwhile: no fresh rest nobody asked for
+ act(() => useUI.getState().startRest(5, 2))
+ act(() => host.querySelector('#timer .tclock').click())
+ act(() => vi.advanceTimersByTime(5000))
+ expect(useUI.getState().timer.ready).toBe(true);
+ ({ el, r } = sheetHost())
+ act(() => { [...el.querySelectorAll('button')].find(b => b.textContent === 'Done').click() })
+ act(() => r.unmount()); el.remove()
+ expect(useUI.getState().timer).toMatchObject({ ready: true, left: 0 })
+
+ // a switch-sides pause that ended does not turn into a plain rest
+ act(() => useUI.getState().startRest(5, 1, { kind: 'switch' }))
+ act(() => host.querySelector('#timer .tclock').click())
+ act(() => vi.advanceTimersByTime(5000))
+ expect(useUI.getState().timer).toBeNull();
+ ({ el, r } = sheetHost())
+ act(() => { [...el.querySelectorAll('button')].find(b => b.textContent === 'Done').click() })
+ act(() => r.unmount()); el.remove()
+ expect(useUI.getState().timer).toBeNull()
+ })
+
+ it('+15 s stops at the wheel maximum of 15:00', () => {
+ act(() => useUI.getState().startRest(890, 0))
+ mount()
+ act(() => useUI.getState().addRest(15))
+ expect(useUI.getState().timer).toMatchObject({ left: 900, total: 900 })
+ act(() => useUI.getState().addRest(15))
+ expect(useUI.getState().timer.left).toBe(900)
+ expect(host.querySelectorAll('#timer .adj')[1].disabled).toBe(true)
+ act(() => useUI.getState().addRest(-15))
+ expect(useUI.getState().timer.left).toBe(885)
+ })
+
it('keeps a paused rest paused at the new time', () => {
act(() => useUI.getState().startRest(90, 0))
act(() => useUI.getState().pauseRest())
diff --git a/frontend/src/components/RestTimer.jsx b/frontend/src/components/RestTimer.jsx
index 6137dfeb8..546eca811 100644
--- a/frontend/src/components/RestTimer.jsx
+++ b/frontend/src/components/RestTimer.jsx
@@ -10,20 +10,24 @@ const clock = sec => Math.floor(sec / 60) + ':' + String(sec % 60).padStart(2, '
// The clock is a button: a tap opens the wheel at the time that is left, for a rest that wants
// to be a round 2:00 rather than eight taps of +15. 0:00 ends the rest, like Skip. What is left
-// is read again at Done, since the rest kept counting while the wheel was open.
+// is read again at Done, since the rest kept counting while the wheel was open. Done on a wheel
+// nobody turned changes nothing: the rest keeps the seconds it counted down meanwhile, and one
+// that ran out (or a switch-sides pause that ended) is not started again.
export function adjustRestSheet() {
const tm = useUI.getState().timer
if (!tm) return
+ const opened = tm.ready ? 0 : Math.min(tm.left, REST_MAX)
durationSheet({
- title: t('Time left'), value: tm.ready ? 0 : tm.left, max: REST_MAX, off: t('Skip'),
+ title: t('Time left'), value: opened, max: REST_MAX, off: t('Skip'),
footer: t('Scroll to 0:00 to end the rest now.'),
- onDone: v => applyRestLeft(v),
+ onDone: v => applyRestLeft(v, opened),
})
}
// What the wheel's Done does to the rest as it is by then: a new time left, the rest ended at
// 0:00, or a fresh rest when the old one has run out (Ready) or was skipped meanwhile.
-export function applyRestLeft(v) {
+export function applyRestLeft(v, opened) {
+ if (opened !== undefined && v === opened) return
const ui = useUI.getState()
const now = ui.timer
if (!now) { if (v > 0) ui.startRest(v); return }
@@ -83,7 +87,7 @@ export default function RestTimer() {
</button>
<div className="acts">
<Button size="sm" className="adj" icon="minus" onClick={() => addRest(-15)}>15s</Button>
- <Button size="sm" className="adj" icon="plus" onClick={() => addRest(15)}>15s</Button>
+ <Button size="sm" className="adj" icon="plus" disabled={!timer.ready && timer.left >= REST_MAX} onClick={() => addRest(15)}>15s</Button>
{!timer.ready && <Button size="sm" className="pause" icon={timer.paused ? 'play' : 'pause'}
aria-label={t(timer.paused ? 'Resume' : 'Pause')} aria-pressed={!!timer.paused}
onClick={timer.paused ? resumeRest : pauseRest} />}
diff --git a/frontend/src/store/useUI.js b/frontend/src/store/useUI.js
index a244fc913..a481117ab 100644
--- a/frontend/src/store/useUI.js
+++ b/frontend/src/store/useUI.js
@@ -7,6 +7,7 @@ import { deviceId } from '../lib/push.js'
import { MOBILE } from '../lib/mobile.js'
import { armRestAlert, bindNativeRest, disarmRestAlert, holdRestAlert } from '../lib/rest-alert.js'
import { useStore } from './useStore.js'
+import { REST_MAX } from '../lib/duration.js'
// Fire-and-forget: lets the server push a "rest over" alert if this tab gets suspended
// before the local timer completes. No-ops for guests / offline. The device id keeps the
@@ -216,7 +217,10 @@ export const useUI = create((set, get) => ({
addRest(sec) {
const tm = get().timer
if (!tm) return
- if (tm.ready) { if (sec > 0) get().startRest(sec, tm.forIdx); else get().stopRest(); return }
+ if (tm.ready) { if (sec > 0) get().startRest(Math.min(sec, REST_MAX), tm.forIdx); else get().stopRest(); return }
+ // +15 s stops where the wheel does (15:00), so the two never disagree about a rest's length.
+ if (sec > 0) sec = Math.min(sec, Math.max(0, REST_MAX - tm.left))
+ if (!sec) return
const left = tm.left + sec
// taking off more than is left means "I'm ready now" — same as skipping, and it keeps a
// negative duration out of both the progress bar and the server-side push schedule