From 33317dac914c0d6a66d5dede2c8bb7ae1009fa79 Mon Sep 17 00:00:00 2001 From: Duarte Santos Date: Wed, 22 Jul 2026 14:44:15 +0200 Subject: [PATCH] Fix rest timer freezing at 0:01 (#14) MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit The tick callback shadowed the imported i18n helper `t` with the timer object, so the final tick threw a TypeError on t('Rest over — next set!') before reaching stopRest(). The interval kept running and re-throwing, the display stayed on the last value it wrote, and the pending server-side 'rest over' push was never cancelled. Closes #14 --- frontend/src/store/useUI.js | 18 +++++++++--------- 1 file changed, 9 insertions(+), 9 deletions(-) diff --git a/frontend/src/store/useUI.js b/frontend/src/store/useUI.js index b952931..4df1d0e 100644 --- a/frontend/src/store/useUI.js +++ b/frontend/src/store/useUI.js @@ -40,26 +40,26 @@ export const useUI = create((set, get) => ({ set({ timer: { left: sec, total: sec, endsAt } }) pushRestTimer(sec) timerTick = () => { - const t = get().timer - if (!t) return - const left = Math.max(0, Math.round((t.endsAt - Date.now()) / 1000)) - if (left === t.left) return + const tm = get().timer + if (!tm) return + const left = Math.max(0, Math.round((tm.endsAt - Date.now()) / 1000)) + if (left === tm.left) return const snd = useStore.getState().S.sound if (left <= 0) { beep(snd, 880, 0.15); beep(snd, 880, 0.15, 0.25); beep(snd, 1320, 0.4, 0.5) vibrate([200, 100, 200]); get().toast(t('Rest over — next set! 💪')); get().stopRest(); return } if (left <= 3) beep(snd, 660, 0.1) - set({ timer: { ...t, left } }) + set({ timer: { ...tm, left } }) } timerInt = setInterval(timerTick, 1000) document.addEventListener('visibilitychange', timerTick) }, addRest(sec) { - const t = get().timer - if (!t) return - const left = t.left + sec - set({ timer: { ...t, left, total: t.total + sec, endsAt: t.endsAt + sec * 1000 } }) + const tm = get().timer + if (!tm) return + const left = tm.left + sec + set({ timer: { ...tm, left, total: tm.total + sec, endsAt: tm.endsAt + sec * 1000 } }) pushRestTimer(left) }, stopRest() {