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 connection line says offline as soon as the device goes offline, not at the next sync attempt
Duarte Santos1498f1a2a165
diff --git a/frontend/src/components/ServerSync.jsx b/frontend/src/components/ServerSync.jsxindex b4df3bc1e..b7236b8a4 100644--- a/frontend/src/components/ServerSync.jsx+++ b/frontend/src/components/ServerSync.jsx@@ -57,7 +57,11 @@ export function useOnline() {export function connectionView(sync, { mobile = MOBILE, online = isOnline() } = {}) {if (!sync) return nullconst err = sync.lastError || {}- switch (sync.status) {+ // A device that says it has no network is offline whatever the last request found: said the+ // moment it goes, not at the next sync attempt, which may be a poll away. Only the states that+ // claim a working connection give way; a refusal or an error keeps its own words.+ const status = !online && (sync.status === 'ok' || sync.status === 'pending') ? 'offline' : sync.status+ switch (status) {case 'ok':return { tone: 'ok', icon: 'cloud', line: t('All synced'), banner: null, action: null }case 'pending': // the sentence already says "tap to retry": no second word for itdiff --git a/frontend/src/components/SyncBanner.test.jsx b/frontend/src/components/SyncBanner.test.jsxindex 869473ee3..f768d2c4c 100644--- a/frontend/src/components/SyncBanner.test.jsx+++ b/frontend/src/components/SyncBanner.test.jsx@@ -3,6 +3,7 @@ import React, { act } from 'react'import { createRoot } from 'react-dom/client'import { afterEach, beforeEach, describe, expect, it, vi } from 'vitest'import SyncBanner, { PENDING_GRACE_MS } from './SyncBanner.jsx'+import { connectionView } from './ServerSync.jsx'globalThis.IS_REACT_ACT_ENVIRONMENT = true@@ -83,6 +84,30 @@ describe('connected and in step', () => {expect(bar()).toBeNull()expect(conn()).toBe('')})++ // QA, v1.3.9: with nothing waiting, the line came only with the next sync attempt, some 17 s+ // after the browser said it was offline, and Settings said "All synced" until then.+ it('the device going offline is said at once, not at the next sync attempt, and goes when it is back', async () => {+ render()+ expect(bar()).toBeNull()+ act(() => network(false))+ expect(text()).toBe('Offline — showing the last copy synced with the server.')+ expect(bar().className).toContain('off')+ expect(label()).toBe('Try again')+ expect(connectionView(sync('ok'), { online: false }).line).toBe('Offline — the server cannot be reached')+ act(() => network(true))+ expect(bar()).toBeNull()+ })++ it('a change waiting while the device is offline says it is kept here, after the same grace as ever', () => {+ vi.useFakeTimers()+ network(false)+ mocks.sync = sync('pending', { pending: true })+ render()+ expect(bar()).toBeNull()+ act(() => { vi.advanceTimersByTime(PENDING_GRACE_MS) })+ expect(text()).toBe('Offline — your changes are saved on this device and sync when you are back online.')+ })})describe('not connected — it says so, and what to do', () => {