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
Settings: a sign-out clears the photo and video store even when the copy no longer refers to any
Duarte Santosd8e2c4b20d76
diff --git a/frontend/src/store/useStore.js b/frontend/src/store/useStore.jsindex 48668c174..99fbd1e20 100644--- a/frontend/src/store/useStore.js+++ b/frontend/src/store/useStore.js@@ -569,7 +569,6 @@ export const useStore = create((set, get) => {// Everything a sign-out leaves behind on this device, whichever way it was triggered. The owner// goes last, after the wiped copy is written — the storage listener above relies on the order.const clearLocalSession = () => {- const hadMedia = referencedHashes(get().S).size > 0get().setUser(null)localStorage.removeItem('gym_guest')forgetSync()@@ -585,15 +584,14 @@ export const useStore = create((set, get) => {// The account's photos and videos go with its copy (a shared device keeps nothing of it),// except the ones a stash still refers to — whatever was pending is in a stash by now// (signOut refuses otherwise) and comes back with it. A file picked from here on is kept.- // After the state file, which is the one write a sign-out must not be kept waiting for. A- // copy that referred to no media leaves the store alone; files of exercises deleted earlier- // are the local clean-up's (lib/media-sync.js localMediaGc).- if (hadMedia) {- const since = Date.now()- Promise.resolve(wiped).then(() => readStashes())- .then(all => mediaStore.retainOnly(new Set(Object.values(all).flatMap(e => [...referencedHashes(e?.state)])), { keepPutAfter: since }))- .catch(() => {})- }+ // After the state file, which is the one write a sign-out must not be kept waiting for. Even+ // when the copy refers to no media any more: a photo removed in the last hour, or one whose+ // exercise was deleted, is still in the store until the local clean-up's grace has passed,+ // and on a shared device it must not outlast the sign-out.+ const since = Date.now()+ Promise.resolve(wiped).then(() => readStashes())+ .then(all => mediaStore.retainOnly(new Set(Object.values(all).flatMap(e => [...referencedHashes(e?.state)])), { keepPutAfter: since }))+ .catch(() => {})return wiped}diff --git a/frontend/src/store/useStore.media.test.jsx b/frontend/src/store/useStore.media.test.jsxindex 032e8253f..154ea977d 100644--- a/frontend/src/store/useStore.media.test.jsx+++ b/frontend/src/store/useStore.media.test.jsx@@ -85,6 +85,17 @@ describe('owed photos and videos', () => {expect(await media.has('c'.repeat(64))).toBe(false)})+ it('a sign-out takes the account\'s files even when its copy no longer refers to any (a photo removed a moment ago)', async () => {+ await media.put(A, new Blob(['abc']), { mime: 'image/webp', pending: false })+ await new Promise(r => setTimeout(r, 5)) // put before the sign-out, not during it+ useStore.setState({ S: { ...clone(DEF), _ts: 100 }, user: USER, ready: true, sync: { ...fresh } })+ localStorage.setItem('gym_sync', JSON.stringify({ rev: 1, ts: 100 }))+ api.mockImplementation(async (path, o) => (o?.method === 'PUT' ? { ok: true, rev: 2 } : { ok: true }))+ expect(await useStore.getState().signOut()).toEqual({ owed: false })+ await new Promise(r => setTimeout(r, 20)) // the purge runs after the wiped copy is written+ expect(await media.has(A)).toBe(false)+ })+it('a different account signing in keeps the previous one\'s waiting photo aside, even with no workouts', async () => {await media.put(A, new Blob(['abc']), { mime: 'image/webp', pending: true })// The copy owes nothing else: no workouts, no routines — only the custom exercise and its photo.