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.
JavaScript apple-watchbodyweightdockerfitnessfitness-trackergymhealthiosmcpnodejspasskeysprogressive-web-applicationspwareactself-hostedself-hostingvitewebauthnweightliftingworkout-tracker
fix(workout): stop work timer on discard
Space_Hermese47a5418dcec
diff --git a/frontend/src/views/Workout.jsx b/frontend/src/views/Workout.jsxindex d0a627977..c7766b199 100644--- a/frontend/src/views/Workout.jsx+++ b/frontend/src/views/Workout.jsx@@ -275,7 +275,7 @@ function ActiveWorkout() {const nav = useNavigate()const S = useStore(s => s.S)const update = useStore(s => s.update)- const { startRest, stopRest, work } = useUI()+ const { startRest, stopRest, stopWork, work } = useUI()const A = S.activeconst units = supersetUnits(A.entries)const cur = Math.min(A.cur, Math.max(0, A.entries.length - 1))@@ -479,7 +479,7 @@ function ActiveWorkout() {return <div className="narrow"><div className="hdr">- <button className="iconbtn" aria-label={t('Discard')} onClick={() => confirmSheet({ title: t('Discard workout?'), message: t('The sets you logged in this session will be lost.'), confirmText: t('Discard'), danger: true, onConfirm: () => { update(s => { s.active = null }); stopRest(); nav('/home') } })}><Icon name="xmark" /></button>+ <button className="iconbtn" aria-label={t('Discard')} onClick={() => confirmSheet({ title: t('Discard workout?'), message: t('The sets you logged in this session will be lost.'), confirmText: t('Discard'), danger: true, onConfirm: () => { update(s => { s.active = null }); stopRest(); stopWork(); nav('/home') } })}><Icon name="xmark" /></button><div style={{ textAlign: 'center' }}><div style={{ fontWeight: 600 }}>{A.name}</div><div className="sub"><Elapsed start={A.start} /> · {t('{0} sets', done + '/' + total)}</div></div><button className="iconbtn" style={{ color: 'var(--acc)' }} aria-label={t('Finish')} onClick={finishWorkout}><Icon name="check" /></button></div>diff --git a/frontend/src/views/Workout.test.jsx b/frontend/src/views/Workout.test.jsxindex 0564b8a68..18ac7bfb1 100644--- a/frontend/src/views/Workout.test.jsx+++ b/frontend/src/views/Workout.test.jsx@@ -7,19 +7,27 @@ import Workout from './Workout.jsx'const mocks = vi.hoisted(() => {const state = {S: null,+ timer: null,+ work: null,startRest: vi.fn(),- stopRest: vi.fn(),+ stopRest: null,+ stopWork: null,+ confirmSheet: vi.fn(),topWeightSheet: vi.fn(),}+ state.stopRest = vi.fn(() => { state.timer = null })+ state.stopWork = vi.fn(() => { state.work = null })state.storeSnapshot = () => ({S: state.S,user: null,update: mut => mut(state.S),})state.uiSnapshot = () => ({- work: null,+ timer: state.timer,+ work: state.work,startRest: state.startRest,stopRest: state.stopRest,+ stopWork: state.stopWork,startWork: vi.fn(),toast: vi.fn(),})@@ -45,7 +53,7 @@ vi.mock('../sheets.jsx', () => ({topWeightSheet: mocks.topWeightSheet,finishWorkout: vi.fn(),workoutCompleteSheet: vi.fn(),- confirmSheet: vi.fn(),+ confirmSheet: mocks.confirmSheet,// Both note sheets belong here even though the tests never open one: Workout.jsx reads// sessionNoteSheet during render, so a missing export is a render crash, not a no-op.exerciseNoteSheet: vi.fn(),@@ -112,8 +120,16 @@ async function toggleSet(index) {await act(async () => { checkbox.dispatchEvent(new dom.Event('click', { bubbles: true })) })}+async function requestDiscard() {+ const button = container.querySelector('button[aria-label="Discard"]')+ expect(button).toBeTruthy()+ await act(async () => { button.dispatchEvent(new dom.Event('click', { bubbles: true })) })+}+beforeEach(() => {vi.clearAllMocks()+ mocks.timer = null+ mocks.work = null})afterEach(async () => {@@ -155,6 +171,40 @@ describe('Workout set completion flow', () => {})})+describe('Workout discard timer lifecycle', () => {+ it('preserves active timers while discard is awaiting confirmation', async () => {+ const timer = { left: 30, total: 90, endsAt: Date.now() + 30_000 }+ const work = { left: 20, total: 45, endsAt: Date.now() + 20_000, label: 'Plank' }+ mocks.timer = timer+ mocks.work = work+ await mount([exercise('timed-plank', [false])])++ await requestDiscard()++ expect(mocks.confirmSheet).toHaveBeenCalledOnce()+ expect(mocks.timer).toBe(timer)+ expect(mocks.work).toBe(work)+ expect(mocks.stopRest).not.toHaveBeenCalled()+ expect(mocks.stopWork).not.toHaveBeenCalled()+ expect(mocks.S.active).not.toBeNull()+ })++ it('clears rest and work timers only after discard is confirmed', async () => {+ mocks.timer = { left: 30, total: 90, endsAt: Date.now() + 30_000 }+ mocks.work = { left: 20, total: 45, endsAt: Date.now() + 20_000, label: 'Plank' }+ await mount([exercise('timed-plank', [false])])+ await requestDiscard()++ await act(async () => { mocks.confirmSheet.mock.calls[0][0].onConfirm() })++ expect(mocks.S.active).toBeNull()+ expect(mocks.timer).toBeNull()+ expect(mocks.work).toBeNull()+ expect(mocks.stopRest).toHaveBeenCalledOnce()+ expect(mocks.stopWork).toHaveBeenCalledOnce()+ })+})+describe('superset flow survives an exercise being removed mid-session', () => {// removeActiveExercise splices A.entries, shifting every index above the removal down.// The high-water marks are index-keyed, so without re-baselining the shifted exercise