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
Sync: the changes a forced sign-out kept can be listed, so the screens can say they are waiting
Duarte Santos7b3165c5e945
diff --git a/frontend/src/store/useStore.js b/frontend/src/store/useStore.jsindex e020eb786..d0b3283be 100644--- a/frontend/src/store/useStore.js+++ b/frontend/src/store/useStore.js@@ -717,6 +717,14 @@ export const useStore = create((set, get) => {return { owed: count !== 0, count }},+ // 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.+ async keptChanges() {+ const all = await readStashes()+ return Object.values(all).map(({ server, uid, name, at }) => ({ server: server || null, uid, name, at }))+ },+// Sign-in (and pairing a phone) takes the server's profile as this device's copy — the// profile is the truth for a signed-in user, whatever the timestamps say. The only thing// the device may add are the entries it logged while signed out: `ask(extras)` (a dialog,diff --git a/frontend/src/store/useStore.sync-status.test.jsx b/frontend/src/store/useStore.sync-status.test.jsxindex e262a5666..8c4ec7cf9 100644--- a/frontend/src/store/useStore.sync-status.test.jsx+++ b/frontend/src/store/useStore.sync-status.test.jsx@@ -1,7 +1,7 @@// @vitest-environment happy-dom/* What the store tells the screens about the server (`sync`, `syncNow`, `unsyncedChanges`), and- the owner's rule that signing out never loses a change silently: it refuses while anything is+ the rule that signing out never loses a change silently: it refuses while anything isowed, keeps the owed copy aside when told to go ahead anyway, and brings it back on the nextsign-in to the same server and account. Signing in again to the account this copy alreadybelongs to merges instead of asking. */@@ -25,8 +25,6 @@ const paths = () => api.mock.calls.map(([p, o]) => (o?.method || 'GET') + ' ' +const USER = { id: 'user-1', name: 'One' }const fresh = { offline: false, pending: false, auth: false, lastError: null, lastSynced: 0, server: null }const signedIn = (S, extra = {}) => useStore.setState({ S, user: USER, ready: true, sync: { ...fresh }, ...extra })-// The server, in step with this device at rev 1.-const serverAt = (S, rev = 1) => ({ state: { ...clone(S), _rev: rev }, rev })beforeEach(() => {localStorage.clear()@@ -199,6 +197,7 @@ describe('signing out never loses a change silently', () => {expect(useStore.getState().S.workouts).toEqual([])const stash = JSON.parse(localStorage.getItem('gym_stash'))expect(Object.values(stash).map(e => [e.uid, ids(e.state.workouts)])).toEqual([[USER.id, ['w1', 'w2']]])+ expect(await useStore.getState().keptChanges()).toEqual([{ server: location.origin, uid: USER.id, name: 'One', at: expect.any(Number) }])// Another account signs in here first: the stash is not theirs.api.mockReset()@@ -219,6 +218,7 @@ describe('signing out never loses a change silently', () => {expect(puts().at(-1).baseRev).toBe(2)expect(ids(puts().at(-1).state.workouts)).toEqual(['w1', 'w2', 'w-phone'])expect(localStorage.getItem('gym_stash')).toBeNull()+ expect(await useStore.getState().keptChanges()).toEqual([])})it('"sign out everywhere" follows the same rule, before it asks the server for anything', async () => {