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.

Settings: changes kept for an account whose session had ended carry its name, and the list follows them when they are handed back

Duarte Santos82b173c40f66
diff --git a/frontend/src/components/ServerSync.jsx b/frontend/src/components/ServerSync.jsx
index 80456f921..d3a37c467 100644
--- a/frontend/src/components/ServerSync.jsx
+++ b/frontend/src/components/ServerSync.jsx
@@ -218,13 +218,16 @@ export function ServerSyncSection({ children }) {
// account — so a device that went ahead anyway still says what it holds and for whom.
export function KeptChangesRows() {
const kept = useStore(s => s.keptChanges)
+ const rev = useStore(s => s.keptRev)
const user = useStore(s => s.user)
const [rows, setRows] = useState([])
+ // Asked again when the account changes and whenever the kept changes do — the ones handed
+ // back on a sign-in go some moments after it.
useEffect(() => {
let gone = false
if (typeof kept === 'function') kept().then(r => { if (!gone) setRows(r || []) }).catch(() => {})
return () => { gone = true }
- }, [kept, user?.id])
+ }, [kept, user?.id, rev])
if (DEMO) return null
return rows.map(k => <Row key={(k.server || '') + '|' + k.uid} icon="history" iconTint="var(--orange)"
title={t('Changes kept for {0}', k.name || k.uid)}
diff --git a/frontend/src/store/useStore.js b/frontend/src/store/useStore.js
index 1532fa8e4..f3449c121 100644
--- a/frontend/src/store/useStore.js
+++ b/frontend/src/store/useStore.js
@@ -487,6 +487,7 @@ export const useStore = create((set, get) => {
forgetSync()
localStorage.removeItem(KEY)
persist(clone(DEF), false)
+ localStorage.removeItem('gym_owner_name')
localStorage.removeItem('gym_owner')
setSync({ offline: false, auth: false, lastError: null, pending: false, lastSynced: 0 })
// On a phone the file is wiped with it, now rather than after the usual wait: a start in
@@ -516,6 +517,7 @@ export const useStore = create((set, get) => {
const back = await readJsonFile(STASH_FILE)
ok = ok || (!!back && Object.keys(back).length === Object.keys(all).length)
}
+ set({ keptRev: get().keptRev + 1 })
return ok || empty
}
// A different account signing in on a copy that still owes its own: the copy goes, as it always
@@ -533,7 +535,11 @@ export const useStore = create((set, get) => {
const prev = all[key]?.state
const state = prev ? mergeStates(S, prev) : clone(S)
state.active = S.active || prev?.active || null
- const entry = { server: server || null, uid, name: get().user?.id === uid ? get().user.name || '' : '', at: Date.now(), state }
+ // The name comes from beside the owner when the account is no longer signed in here (its
+ // session ended), so the screens say whose changes these are rather than an id.
+ let name = get().user?.id === uid ? get().user.name || '' : ''
+ if (!name) { try { name = localStorage.getItem('gym_owner_name') || '' } catch { /* the id then */ } }
+ const entry = { server: server || null, uid, name, at: Date.now(), state }
all[key] = entry
// A second full copy beside the first may not fit (a profile near the size limit): the copy
// in storage is wiped next anyway, so it makes the room.
@@ -542,6 +548,7 @@ export const useStore = create((set, get) => {
catch {
try { localStorage.removeItem(KEY); localStorage.setItem(STASH_KEY, v) } catch { /* still full — the file may still take it */ }
}
+ set({ keptRev: get().keptRev + 1 })
if (MOBILE) keeping = readStashes().then(f => writeStashes({ ...f, [key]: entry })).catch(() => {})
}
const stashOwed = async () => {
@@ -691,6 +698,7 @@ export const useStore = create((set, get) => {
persist(clone(DEF), false)
setSync({ pending: false, lastSynced: 0, lastError: null })
}
+ localStorage.setItem('gym_owner_name', u.name || '')
localStorage.setItem('gym_owner', u.id)
localStorage.setItem('gym_user', JSON.stringify(u)); localStorage.removeItem('gym_guest')
// The file follows at once, as the new account's: until then it holds the previous one's.
@@ -786,7 +794,9 @@ export const useStore = create((set, get) => {
// The changes a forced sign-out or disconnect kept on this device, waiting for their server
// and account: [{ server, uid, name, at }] — server null for a phone whose pairing was lost
- // with its address. The copies themselves stay inside the store.
+ // with its address. The copies themselves stay inside the store. `keptRev` moves whenever
+ // they change, for a screen listing them to ask again.
+ keptRev: 0,
async keptChanges() {
const all = await readStashes()
return Object.values(all).map(({ server, uid, name, at }) => ({ server: server || null, uid, name, at }))
diff --git a/frontend/src/store/useStore.sync-status.test.jsx b/frontend/src/store/useStore.sync-status.test.jsx
index 5750018cc..f11f7a31b 100644
--- a/frontend/src/store/useStore.sync-status.test.jsx
+++ b/frontend/src/store/useStore.sync-status.test.jsx
@@ -358,6 +358,29 @@ describe('another account signing in on a copy that still owes the first', () =>
expect(ids(JSON.parse(localStorage.getItem('gym_stash'))[location.origin + '|' + USER.id].state.workouts)).toEqual(['w1', 'w-week'])
})
+ it('names the first account, also when its session had already ended, and says when the kept changes move', async () => {
+ useStore.getState().setUser(USER)
+ useStore.setState({ S: { ...clone(DEF), _ts: 300, workouts: [workout('w1'), workout('w-week', '2026-09-18')] }, ready: true })
+ localStorage.setItem('gym_sync', JSON.stringify({ rev: 1, ts: 100 }))
+ localStorage.setItem('gym_dirty', '1')
+ useStore.getState().setUser(null) // what the boot does when the server ended the session
+
+ const before = useStore.getState().keptRev
+ api.mockImplementation(twosServer)
+ useStore.getState().setUser({ id: 'user-2', name: 'Two' })
+ await useStore.getState().adoptProfile(async () => false)
+ expect(await useStore.getState().keptChanges()).toEqual([{ server: location.origin, uid: USER.id, name: 'One', at: expect.any(Number) }])
+ expect(useStore.getState().keptRev).toBeGreaterThan(before)
+
+ const listed = useStore.getState().keptRev
+ api.mockReset()
+ api.mockImplementation(async (path, o) => (o?.method === 'PUT' ? { ok: true, rev: 3 } : { state: { ...clone(DEF), _ts: 200, workouts: [workout('w1')], _rev: 2 }, rev: 2 }))
+ useStore.getState().setUser(USER)
+ await useStore.getState().adoptProfile(async () => false)
+ expect(await useStore.getState().keptChanges()).toEqual([])
+ expect(useStore.getState().keptRev).toBeGreaterThan(listed)
+ })
+
it('a copy that owes nothing is replaced as before, with nothing kept', async () => {
signedIn({ ...clone(DEF), _ts: 100, workouts: [workout('w1')] })
localStorage.setItem('gym_sync', JSON.stringify({ rev: 1, ts: 100 }))