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.

Reset everything and an account switch start a new profile: weigh-in off, small animations, same language

Duarte Santos0a520a8e1f1a
diff --git a/frontend/src/store/useStore.js b/frontend/src/store/useStore.js
index cfb2e2a8f..c5abff5d7 100644
--- a/frontend/src/store/useStore.js
+++ b/frontend/src/store/useStore.js
@@ -223,6 +223,15 @@ export function freshState() {
return s
}
+// A copy that starts over on this device: Reset everything, or another account signing in here.
+// It is a new profile like freshState's (weigh-in off, small animations), but in the language
+// already on screen, and still marked as never picked when it never was.
+export function restartedState(cur) {
+ const s = freshState()
+ if (cur?.lang) { s.lang = cur.lang; s.langAuto = cur.langAuto === true }
+ return s
+}
+
function loadState() {
try {
const raw = localStorage.getItem(KEY)
@@ -1017,10 +1026,10 @@ export const useStore = create((set, get) => {
persist(S, true)
return convert && get().ready ? get().pushState() : null
},
- // Settings → Reset everything: the empty copy, stamped with when (`resetAt`). Pushed as a
- // replace, and the stamp is what makes it hold: a device that has not seen the reset and
- // still pushes a change of its own gets the 409, and its merge keeps only what that device
- // made after the reset instead of bringing the whole profile back (lib/sync-merge.js).
+ // Settings → Reset everything: a new profile (restartedState), stamped with when (`resetAt`).
+ // Pushed as a replace, and the stamp is what makes it hold: a device that has not seen the
+ // reset and still pushes a change of its own gets the 409, and its merge keeps only what that
+ // device made after the reset instead of bringing the whole profile back (lib/sync-merge.js).
//
// With it goes `resetIds`, the names of every entry the reset wiped: this copy's, the earlier
// resets' (a copy older than those too is still judged right), and the server's once it
@@ -1029,7 +1038,7 @@ export const useStore = create((set, get) => {
// Resolves once the server's names are in (or could not be had).
resetEverything() {
const cur = get().S
- const S = clone(DEF)
+ const S = restartedState(cur)
S.resetAt = Math.max(Date.now(), (Number(cur.resetAt) || 0) + 1)
S.resetIds = mergeResetIds(cur.resetIds, resetIdsOf(cur))
get().replaceState(S, !!get().user)
@@ -1149,7 +1158,7 @@ export const useStore = create((set, get) => {
keepForPrevious(owner)
forgetSync()
localStorage.removeItem(KEY)
- persist(clone(DEF), false)
+ persist(restartedState(get().S), false)
setSync({ pending: false, lastSynced: 0, lastError: null })
}
// The mark, with the names of what this copy holds now (`pre`) — what the question is
diff --git a/frontend/src/store/useStore.weighin-default.test.jsx b/frontend/src/store/useStore.weighin-default.test.jsx
index 1fe34a1da..b622396d4 100644
--- a/frontend/src/store/useStore.weighin-default.test.jsx
+++ b/frontend/src/store/useStore.weighin-default.test.jsx
@@ -2,12 +2,12 @@
// v1.3.11: "Weigh in before workouts" starts off for a profile created from nothing. A profile
// that already exists keeps what it had: one saved with the switch on stays on, and one saved
// before the setting existed (no key) still reads as on through DEF and `!== false`.
-import { describe, expect, it, vi } from 'vitest'
+import { afterEach, describe, expect, it, vi } from 'vitest'
vi.mock('../lib/api.js', () => ({ api: vi.fn() }))
vi.mock('./useUI.js', () => ({ useUI: { getState: () => ({ toast: vi.fn() }) } }))
-import { freshState, DEF, restoredStateFor } from './useStore.js'
+import { freshState, DEF, restoredStateFor, restartedState, useStore } from './useStore.js'
describe('weigh-in default', () => {
it('a fresh profile starts with the weigh-in off', () => {
@@ -35,3 +35,38 @@ describe('exercise animations default', () => {
expect(S.gifSize).toBe('full')
})
})
+
+// A reset, or another account signing in on this device, starts a new profile: the same new
+// defaults as a first run, in the language already on screen, and the reset keeps its stamps.
+describe('starting over', () => {
+ const old = () => ({ ...JSON.parse(JSON.stringify(DEF)), lang: 'de', weighIn: true, gifSize: 'full', resetAt: 5, resetIds: { workouts: ['w-old'] }, workouts: [{ id: 'w1', d: '2026-09-01', entries: [] }] })
+ afterEach(() => { localStorage.clear(); useStore.setState({ S: JSON.parse(JSON.stringify(DEF)), user: null, ready: false }) })
+
+ it('Reset everything gives weigh-in off and small animations, in the same language', async () => {
+ useStore.setState({ S: old(), user: null })
+ await useStore.getState().resetEverything()
+ const S = useStore.getState().S
+ expect(S.weighIn).toBe(false)
+ expect(S.gifSize).toBe('mini')
+ expect(S.lang).toBe('de')
+ expect(S.langAuto).toBe(false)
+ expect(S.workouts).toEqual([])
+ expect(S.resetAt).toBeGreaterThan(5)
+ expect(S.resetIds.workouts).toEqual(expect.arrayContaining(['w-old', 'w1']))
+ })
+
+ it('restartedState keeps a language nobody picked yet marked as such', () => {
+ expect(restartedState({ lang: 'ar', langAuto: true })).toMatchObject({ lang: 'ar', langAuto: true, weighIn: false, gifSize: 'mini' })
+ })
+
+ it('another account signing in on this device starts from the same new profile', () => {
+ localStorage.setItem('gym_owner', 'user-1')
+ useStore.setState({ S: old(), user: { id: 'user-1' } })
+ useStore.getState().setUser({ id: 'user-2', name: 'Two' })
+ const S = useStore.getState().S
+ expect(S.workouts).toEqual([])
+ expect(S.weighIn).toBe(false)
+ expect(S.gifSize).toBe('mini')
+ expect(S.lang).toBe('de')
+ })
+})