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: the Passkeys, Add another device and Password rows come back once the server answers again, instead of staying missing until Settings is opened again (#95, #118)
Duarte Santose80d94c5fe88
diff --git a/frontend/src/components/Passkeys.jsx b/frontend/src/components/Passkeys.jsxindex 512fbd831..2c06c830a 100644--- a/frontend/src/components/Passkeys.jsx+++ b/frontend/src/components/Passkeys.jsx@@ -12,7 +12,7 @@ import { api, webauthnOK, passkeyAssertion, createPasskey } from '../lib/api.js'import { copyText } from '../lib/clipboard.js'import { deviceLinkUrl, deviceLabel } from '../lib/device-link.js'import { askAddDeviceData, confirmSheet } from '../sheets.jsx'-import { passwordError } from './PasswordAuth.jsx'+import { passwordError, notReached, useAgainOnceReached } from './PasswordAuth.jsx'import QrCanvas from './QrCanvas.jsx'import { Row, Button } from './ui.jsx'@@ -59,8 +59,10 @@ export function passkeyError(e) {const listOf = r => (Array.isArray(r?.passkeys) ? r : null)export function usePasskeys(on) {const [st, setSt] = useState(null)- const load = () => api('/api/account/passkeys').then(r => setSt(listOf(r))).catch(() => {})+ const [unreached, setUnreached] = useState(false)+ const load = () => api('/api/account/passkeys').then(r => { setSt(listOf(r)); setUnreached(false) }).catch(e => setUnreached(notReached(e)))useEffect(() => { if (on) load() }, [on])+ useAgainOnceReached(on && unreached, load)return { st, load, set: setSt }}diff --git a/frontend/src/components/PasswordAuth.jsx b/frontend/src/components/PasswordAuth.jsxindex a6c309b83..e559324a3 100644--- a/frontend/src/components/PasswordAuth.jsx+++ b/frontend/src/components/PasswordAuth.jsx@@ -197,6 +197,18 @@ function PasswordRegisterSheet({ close }) {}export const openPasswordRegister = () => ui().openSheet(close => <PasswordRegisterSheet close={close} />)+/* Settings' account rows read the server as the screen opens. One that found the server down+ has nothing to show, and stayed missing until Settings was left and opened again, while the+ block above it already said "All synced". It asks again whenever the store hears from the+ server — a push or pull that landed, a check that found both sides in step — until it gets+ an answer. A refusal (a server from before the route, a 403) is an answer: asking again+ would only get the same one. */+export const notReached = e => e?.status == null || e.status >= 500+export function useAgainOnceReached(unreached, load) {+ const reachedAt = useStore(s => s.sync?.lastSynced)+ useEffect(() => { if (unreached) load() }, [reachedAt])+}+/* ------------------------------------------------------------------- Settings -------------Settings → Account → Password, for a signed-in browser. A first password needs a passkeyceremony right now (a session on its own could be a copied cookie); a change needs the@@ -206,8 +218,10 @@ export const openPasswordRegister = () => ui().openSheet(close => <PasswordRegis// password may be removed depends on them, so the row asks again.export function PasswordRow({ version = 0 }) {const [st, setSt] = useState(null) // GET /api/account/password- const load = () => api('/api/account/password').then(setSt).catch(() => {})+ const [unreached, setUnreached] = useState(false)+ const load = () => api('/api/account/password').then(r => { setSt(r); setUnreached(false) }).catch(e => setUnreached(notReached(e)))useEffect(() => { load() }, [version])+ useAgainOnceReached(unreached, load)if (!st) return null// Nothing here could set a first password without a passkey ceremony.if (!st.set && (!webauthnOK() || !st.passkeys)) return nulldiff --git a/frontend/src/views/Settings.passkeys.test.jsx b/frontend/src/views/Settings.passkeys.test.jsxindex 442f4c3ea..1d07e27e4 100644--- a/frontend/src/views/Settings.passkeys.test.jsx+++ b/frontend/src/views/Settings.passkeys.test.jsx@@ -115,6 +115,51 @@ describe('Settings: passkeys and another device', () => {} finally { mocks.list = list }})+ // Settings opened while the server was down: both reads failed, and the rows stayed missing+ // until Settings was opened again, even with the block above saying "All synced".+ it('rows that found the server down come back once the store hears from it, and rows that loaded are not asked again', async () => {+ const answer = mocks.api.getMockImplementation()+ mocks.api.mockImplementation(async path => {+ if (path === '/api/account/passkeys' || path === '/api/account/password') throw Object.assign(new Error('HTTP 502'), { status: 502, data: {} })+ return answer(path)+ })+ const page = mount(<Settings />)+ await settle()+ expect(titles(section(page, 'Account'))).not.toEqual(expect.arrayContaining(['Passkeys']))+ expect(titles(section(page, 'Account'))).not.toContain('Password')++ mocks.api.mockImplementation(answer)+ mocks.sync = { ...mocks.sync, lastSynced: mocks.sync.lastSynced + 30000 } // a check that found both sides in step+ act(() => mounted.at(-1).root.render(<Settings />))+ await settle()+ expect(titles(section(page, 'Account'))).toEqual(expect.arrayContaining(['Passkeys', 'Add another device', 'Password']))+ expect(asked('/api/account/passkeys')).toBe(2)+ expect(asked('/api/account/password')).toBe(2)++ mocks.sync = { ...mocks.sync, lastSynced: mocks.sync.lastSynced + 30000 }+ act(() => mounted.at(-1).root.render(<Settings />))+ await settle()+ expect(asked('/api/account/passkeys')).toBe(2)+ expect(asked('/api/account/password')).toBe(2)+ })++ it('a refusal is an answer: a row the server turned down is not asked for on every sync', async () => {+ const answer = mocks.api.getMockImplementation()+ mocks.api.mockImplementation(async path => {+ if (path === '/api/account/passkeys') throw Object.assign(new Error('HTTP 404'), { status: 404, data: {} })+ return answer(path)+ })+ try {+ const page = mount(<Settings />)+ await settle()+ mocks.sync = { ...mocks.sync, lastSynced: mocks.sync.lastSynced + 30000 }+ act(() => mounted.at(-1).root.render(<Settings />))+ await settle()+ expect(titles(page)).not.toContain('Passkeys')+ expect(asked('/api/account/passkeys')).toBe(1)+ } finally { mocks.api.mockImplementation(answer) }+ })+it('a change to the passkeys reads the list and the password row again', async () => {const page = mount(<Settings />)await settle()