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.

Connection line: the quiet "no server" line can be closed (#454)

Anshuman Nayan98bc3e36b62a
diff --git a/frontend/src/components/SyncBanner.jsx b/frontend/src/components/SyncBanner.jsx
index 82cf00b1f..06bdece13 100644
--- a/frontend/src/components/SyncBanner.jsx
+++ b/frontend/src/components/SyncBanner.jsx
@@ -2,6 +2,7 @@ import { useEffect, useLayoutEffect, useRef, useState } from 'react'
import { useNavigate } from 'react-router-dom'
import { useStore } from '../store/useStore.js'
import { DEMO } from '../lib/demo.js'
+import { t } from '../lib/i18n.js'
import { connectionView, actionLabel, syncNowWithToast, pairAgain, connectServer, signInAgain, useOnline } from './ServerSync.jsx'
import Icon from './Icon.jsx'
@@ -13,8 +14,9 @@ export const PENDING_GRACE_MS = 5000
/* The connection, always in view while the app is not connected to a server: offline, the server
unreachable or answering with an error (its HTTP code, for whoever runs it), a server that no
longer accepts this device, an answer that is not openGym's, and no server at all — a phone
- kept local, a guest in a browser. It cannot be dismissed; it goes when the condition does — or
- when Settings → "Show connection status" is off, and then a dot on Home says a problem is there.
+ kept local, a guest in a browser. A problem cannot be dismissed; it goes when the condition does
+ — or when Settings → "Show connection status" is off, and then a dot on Home says a problem is
+ there. The no-server line alone has an ×, which hides it for good (#454).
The first ones say what is wrong and that the changes are kept here, with the one thing to do
about it (retry, pair again, sign in); the deliberate local setup only says so, quietly.
@@ -51,6 +53,11 @@ function useConnection() {
// goes — but a sync that is stuck still has to be noticed somewhere.
export const showsConnection = S => S?.connStatus !== false
+// The quiet "no server" line (#454): a phone kept local or a guest has chosen that, and a line
+// saying so on every screen, for good, is a nag. Its × sets this off; offline, an error or a
+// refusal still show, since only the 'quiet' tone is ever hidden by it.
+export const showsLocalLine = S => S?.connLocal !== false
+
/* True while the banner is switched off and the connection has a problem worth seeing: offline,
the server unreachable or answering with an error, refusing this device, a sign-in question
still open, or changes waiting past the grace period. Never for a device with no server at all
@@ -65,9 +72,12 @@ export function useConnectionTrouble() {
export default function SyncBanner() {
const nav = useNavigate()
const on = useStore(s => showsConnection(s.S))
+ const local = useStore(s => showsLocalLine(s.S))
+ const update = useStore(s => s.update)
const conn = useConnection()
const { view, user, status } = conn
- const show = conn.show && on
+ const quiet = view?.tone === 'quiet'
+ const show = conn.show && on && (!quiet || local)
const row = useRef(null)
useLayoutEffect(() => {
@@ -99,6 +109,8 @@ export default function SyncBanner() {
return <div className={'conn-bar ' + view.tone}>
<div className="conn-row" ref={row} role="status" aria-live="polite">
{act ? <button className="conn" onClick={act}>{inner}</button> : <div className="conn">{inner}</div>}
+ {/* Connecting or signing in is still in Settings, so hiding the line takes nothing away. */}
+ {quiet && <button type="button" className="conn-x" aria-label={t('Close')} onClick={() => update(s => { s.connLocal = false })}><Icon name="xmark" /></button>}
</div>
</div>
}
diff --git a/frontend/src/components/SyncBanner.test.jsx b/frontend/src/components/SyncBanner.test.jsx
index 0ed7d8265..1f6a6ff48 100644
--- a/frontend/src/components/SyncBanner.test.jsx
+++ b/frontend/src/components/SyncBanner.test.jsx
@@ -18,9 +18,10 @@ const mocks = vi.hoisted(() => {
state.toast = vi.fn()
state.syncNow = vi.fn(async () => state.sync)
state.passkeyLogin = vi.fn(async () => ({ id: 'u1', name: 'andi' }))
+ state.update = vi.fn(mut => { state.S = { ...state.S }; mut(state.S) })
state.snapshot = () => ({
S: state.S, user: state.user, sync: state.sync, needsMobileOnboarding: state.onboarding,
- isGuest: () => state.guest, syncNow: state.syncNow,
+ isGuest: () => state.guest, syncNow: state.syncNow, update: state.update,
setUser: vi.fn(), adoptProfile: vi.fn(async () => ({})),
})
return state
@@ -59,7 +60,7 @@ beforeEach(() => {
Object.assign(mocks, { MOBILE: false, DEMO: false, webauthn: true, user: { id: 'u1', name: 'andi' }, guest: false, onboarding: false, sync: sync('ok'), S: {} })
mocks.sheets.length = 0
mocks.navs.length = 0
- mocks.toast.mockClear(); mocks.syncNow.mockClear(); mocks.passkeyLogin.mockClear()
+ mocks.toast.mockClear(); mocks.syncNow.mockClear(); mocks.passkeyLogin.mockClear(); mocks.update.mockClear()
host = document.createElement('div')
document.body.appendChild(host)
root = createRoot(host)
@@ -248,6 +249,56 @@ describe('no server at all', () => {
})
})
+// #454: a device kept local on purpose read "not connected to a server" on every screen, for good.
+// The quiet line has an × that hides it; a problem with a server never gets one.
+describe('hiding the no-server line', () => {
+ const close = () => host.querySelector('.conn-x')
+
+ it('a phone kept local: the × hides the line for good and gives the page its height back, without connecting', () => {
+ mocks.MOBILE = true
+ mocks.user = null
+ mocks.guest = true
+ mocks.sync = sync('local', { server: null })
+ render()
+ expect(text()).toBe('On this phone only, not connected to a server')
+ expect(close().getAttribute('aria-label')).toBe('Close')
+ act(() => close().click())
+ expect(mocks.update).toHaveBeenCalledTimes(1)
+ expect(mocks.S.connLocal).toBe(false)
+ expect(mocks.sheets).toHaveLength(0)
+ render()
+ expect(bar()).toBeNull()
+ expect(conn()).toBe('')
+ })
+
+ it('a guest in a browser: the same ×, and Settings is not opened by it', () => {
+ mocks.user = null
+ mocks.guest = true
+ mocks.sync = sync('local')
+ render()
+ act(() => close().click())
+ expect(mocks.navs).toEqual([])
+ render()
+ expect(bar()).toBeNull()
+ })
+
+ it('a profile without the key still shows the line', () => {
+ Object.assign(mocks, { user: null, guest: true, sync: sync('local'), S: {} })
+ render()
+ expect(bar()).not.toBeNull()
+ })
+
+ it('hidden, a problem with a server still shows, and has no × of its own', () => {
+ mocks.S = { connLocal: false }
+ for (const [st, extra] of [['offline', { pending: true }], ['error', { lastError: { status: 502 } }], ['auth', {}], ['held', {}]]) {
+ mocks.sync = sync(st, extra)
+ render()
+ expect(bar(), st).not.toBeNull()
+ expect(close(), st).toBeNull()
+ }
+ })
+})
+
// Review of 771184c9: while a sign-in's question held sync, the screens said nothing at all.
describe('a sign-in waiting for its question', () => {
it('says nothing syncs until it is answered, and the tap runs Sync now, which asks it', () => {
diff --git a/frontend/src/index.css b/frontend/src/index.css
index f412a83b0..8cc623c84 100644
--- a/frontend/src/index.css
+++ b/frontend/src/index.css
@@ -211,6 +211,10 @@ button.conn:active{filter:brightness(1.12)}
.conn-bar.quiet .conn{min-height:26px;padding-block:2px;padding-inline:4px 2px;background:none;color:var(--label-2);font-size:12px;gap:6px}
.conn-bar.quiet .conn .icn{font-size:13px;color:var(--label-3)}
.conn-bar.quiet .conn-a{padding:2px 9px;font-size:12px;color:var(--acc);background:var(--acc-soft)}
+/* its × (#454): beside the line, not inside its button, so hiding it never also connects */
+.conn-bar.quiet .conn-row{display:flex;align-items:center;gap:2px}
+.conn-x{flex:none;display:grid;place-items:center;width:26px;height:26px;border-radius:99px;color:var(--label-3);font-size:12px}
+.conn-x:active{background:var(--surface-2)}
:root[data-theme="light"] .conn-bar:not(.quiet) .conn-a{background:var(--surface)}
@supports not ((backdrop-filter:blur(1px)) or (-webkit-backdrop-filter:blur(1px))){
.conn-bar{background:var(--bg)}
diff --git a/frontend/src/store/useStore.js b/frontend/src/store/useStore.js
index 96842677b..931621cdc 100644
--- a/frontend/src/store/useStore.js
+++ b/frontend/src/store/useStore.js
@@ -183,6 +183,10 @@ export const DEF = {
// stuck sync then shows as a dot on Home instead. Defaults on; an older profile without the
// key reads as on (`!== false`).
connStatus: true,
+ // The quiet line a device with no server shows ("On this phone only…", "Guest mode…", #454).
+ // That is a choice, not a fault, so its × hides it for good; a real problem still shows the bar.
+ // Defaults on; an older profile without the key reads as on (`!== false`).
+ connLocal: true,
// Where a planned session's reps come from (Settings → During a workout, lib/session-start.js):
// 'plan' opens at the routine's own sets × reps and lets history and progression decide the
// weight; 'last' carries the reps over from the last session, the way it always worked before.
diff --git a/frontend/src/views/Settings.connstatus.test.jsx b/frontend/src/views/Settings.connstatus.test.jsx
index e56f3e667..f8e8588d1 100644
--- a/frontend/src/views/Settings.connstatus.test.jsx
+++ b/frontend/src/views/Settings.connstatus.test.jsx
@@ -94,6 +94,15 @@ describe('Show connection status', () => {
act(() => { row().querySelector('[role="switch"]').click() })
expect(mocks.S.connStatus).toBe(true)
})
+
+ // #454: the no-server line's × sets connLocal off; switching the status on is the way back.
+ it('switching it on brings back the no-server line its × hid', () => {
+ mocks.S = { ...mocks.S, connStatus: false, connLocal: false }
+ mount()
+ act(() => { row().querySelector('[role="switch"]').click() })
+ expect(mocks.S.connStatus).toBe(true)
+ expect(mocks.S.connLocal).toBe(true)
+ })
})
describe('guest footers', () => {
@@ -114,4 +123,10 @@ describe('guest footers', () => {
act(() => root.render(<Settings key="off" page="account" />))
expect(footers().filter(f => f.includes('Guest mode'))).toHaveLength(1)
})
+
+ it('Account says guest mode in the footer once the banner\'s × hid it (#454)', () => {
+ mocks.S = { ...mocks.S, connLocal: false }
+ act(() => root.render(<Settings page="account" />))
+ expect(footers().filter(f => f.includes('Guest mode'))).toHaveLength(1)
+ })
})
diff --git a/frontend/src/views/Settings.jsx b/frontend/src/views/Settings.jsx
index fd5770fce..d3fbbf4a9 100644
--- a/frontend/src/views/Settings.jsx
+++ b/frontend/src/views/Settings.jsx
@@ -32,7 +32,7 @@ import { REST_MAX, REST_PAUSE_MIN, REST_PAUSE_MAX, fmtRest, fmtDuration } from '
import { starterPlanSheet, confirmSheet, importFromApp, importFromHevy, equipmentProfileSheet, plateInventorySheet, menuSheet } from '../sheets.jsx'
import Icon from '../components/Icon.jsx'
import { durationSheet } from '../components/DurationWheel.jsx'
-import { showsConnection } from '../components/SyncBanner.jsx'
+import { showsConnection, showsLocalLine } from '../components/SyncBanner.jsx'
import BackupFolderRow, { useBackupFolder, autoBackupSubtitle } from '../components/BackupFolderRow.jsx'
import { ServerSyncSection, KeptChangesRows, leaveServer, connectServer, passkeySignIn } from '../components/ServerSync.jsx'
import { passwordOn, PasswordRow, openPasswordSignIn, openPasswordRegister } from '../components/PasswordAuth.jsx'
@@ -727,10 +727,11 @@ export default function Settings({ page = null, find = null, via = null }) {
<Switch checked={S.showWeightCard !== false} onChange={v => update(s => { s.showWeightCard = v })} />
</Row>
{/* The bar at the top that says the app is offline, kept local, or not synced (#369, #330).
- Here and not under Server & sync, which a phone kept local never shows. */}
+ Here and not under Server & sync, which a phone kept local never shows. Switching it on
+ also brings back the no-server line its × hid (#454). */}
{!DEMO && <Row icon="cloud" iconTint="var(--blue)" title={t('Show connection status')}
subtitle={t('Off: the bar at the top is hidden. A dot on Home still warns when syncing is stuck.')}>
- <Switch checked={S.connStatus !== false} onChange={v => update(s => { s.connStatus = v })} />
+ <Switch checked={S.connStatus !== false} onChange={v => update(s => { s.connStatus = v; if (v) s.connLocal = true })} />
</Row>}
</Section>
</>,
@@ -851,8 +852,9 @@ export default function Settings({ page = null, find = null, via = null }) {
<KeptChangesRows />
</>}
</Section>}
- {/* The connection banner already says this to a guest; the line is for when it is switched off. */}
- {!user && !DEMO && !MOBILE && !showsConnection(S) && <p className="sect-f" style={{ marginTop: -18, marginBottom: 22 }}>{t('Guest mode: your data lives only in this browser.')}</p>}
+ {/* The connection banner already says this to a guest; the line is for when it is switched
+ off, or its × hid it (#454). */}
+ {!user && !DEMO && !MOBILE && !(showsConnection(S) && showsLocalLine(S)) && <p className="sect-f" style={{ marginTop: -18, marginBottom: 22 }}>{t('Guest mode: your data lives only in this browser.')}</p>}
</>,
}