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
Sign-in: a kept running workout comes back in the profile's unit
Duarte Santos8c4756a0ad89
diff --git a/frontend/src/store/useStore.js b/frontend/src/store/useStore.jsindex e7e84cd8b..2f89f961b 100644--- a/frontend/src/store/useStore.js+++ b/frontend/src/store/useStore.js@@ -883,7 +883,8 @@ export const useStore = create((set, get) => {const key = stashKey(server, user.id)const prev = all[key]?.stateconst state = prev ? mergeStates(get().S, prev) : clone(get().S)- state.active = get().S.active || prev?.active || null+ // Each running workout in the kept copy's unit (carryActive), never a kg session under lb.+ state.active = carryActive(get().S, state) || carryActive(prev, state) || null// Kept while a sign-in's question was open: a copy that was never this account's, added back// like an answered "Add them" (applyStash), the account's settings and history first.const adopt = adoptHold || !!all[key]?.adopt@@ -903,7 +904,7 @@ export const useStore = create((set, get) => {const key = stashKey(server, user.id)const prev = all[key]?.stateconst state = prev ? clone(prev) : Object.assign(clone(DEF), { _ts: 0, unit: get().S.unit || 'kg' })- state.active = clone(a)+ state.active = clone(carryActive(get().S, state))all[key] = { server: server || null, uid: user.id, name: user.name || '', at: Date.now(), state }return writeStashes(all)}@@ -932,7 +933,9 @@ export const useStore = create((set, get) => {let merged = Sfor (const k of keys) merged = all[k].adopt ? mergeStates(merged, all[k].state, { prefer: 'a' }) : mergeStates(merged, all[k].state)merged = Object.assign(clone(DEF), merged)- merged.active = S.active || keys.map(k => all[k].state?.active).find(Boolean) || null+ // A kept running workout comes back in the unit of the copy it joins: the account may have+ // switched to lb (converting every weight) since it was kept in kg.+ merged.active = S.active || keys.map(k => carryActive(all[k].state, merged)).find(Boolean) || nullpersist(merged, false)markOwed(true)if (MOBILE) await nativePersist(true) // the durable copy holds it before the stash goesdiff --git a/frontend/src/store/useStore.stash-unit.test.jsx b/frontend/src/store/useStore.stash-unit.test.jsxnew file mode 100644index 000000000..d49ba2f09--- /dev/null+++ b/frontend/src/store/useStore.stash-unit.test.jsx@@ -0,0 +1,35 @@+// @vitest-environment happy-dom++/* A workout kept aside by a sign-out comes back on the next sign-in in the unit of the profile it+ joins: switched to lb (converting) on another device meanwhile, its 100 kg sets came back as+ 100 lb, and finishing it logged the wrong weights. (QA 2026-10-06.) */+import { afterEach, beforeEach, describe, expect, it, vi } from 'vitest'++vi.mock('../lib/api.js', () => ({ api: vi.fn(), setRemoteAuth: vi.fn() }))+vi.mock('./useUI.js', () => ({ useUI: { getState: () => ({ toast: vi.fn(), stopRest: vi.fn(), abandonWork: vi.fn() }) } }))++import { api } from '../lib/api.js'+import { DEF, useStore } from './useStore.js'++const clone = v => JSON.parse(JSON.stringify(v))+const active = { id: 'run1', d: '2026-10-06', start: 1, name: 'Push', entries: [{ id: '0025', sets: [{ w: 100, r: 5, done: true }, { w: 100, r: 5, done: false }] }] }+beforeEach(() => { localStorage.clear(); api.mockReset() })+afterEach(() => { localStorage.clear(); useStore.setState({ S: clone(DEF), user: null, ready: false }) })++describe('a kept running workout and a unit switch elsewhere', () => {+ it('comes back converted into the profile\'s unit', async () => {+ const S = { ...clone(DEF), _ts: 100, unit: 'kg', workouts: [], active: clone(active) }+ localStorage.setItem('gym_owner', 'u1'); localStorage.setItem('gym_sync', JSON.stringify({ rev: 3, ts: 100 }))+ useStore.setState({ S, user: { id: 'u1', name: 'x' }, ready: true })+ api.mockResolvedValue({ ok: true })+ expect(await useStore.getState().signOut()).toEqual({ owed: false })+ const server = { ...clone(DEF), _ts: 500, unit: 'lb', unitSet: { at: 400, convert: true }, workouts: [], _rev: 4 }+ api.mockReset()+ api.mockImplementation(async (p, o) => (o?.method === 'PUT' ? { ok: true, rev: 5 } : { state: clone(server), rev: 4 }))+ useStore.getState().setUser({ id: 'u1', name: 'x' }, { adopt: true })+ await useStore.getState().adoptProfile(async () => true)+ const after = useStore.getState().S+ expect(after.unit).toBe('lb')+ expect(after.active.entries[0].sets[0].w).toBeCloseTo(220.5, 0)+ })+})