diff --git a/client/src/components/LogbookDashboard.tsx b/client/src/components/LogbookDashboard.tsx index b3acb49..43fa933 100644 --- a/client/src/components/LogbookDashboard.tsx +++ b/client/src/components/LogbookDashboard.tsx @@ -1,7 +1,6 @@ import React, { useState, useEffect, useRef } from 'react' import { useTranslation } from 'react-i18next' -import { useLiveQuery } from 'dexie-react-hooks' -import { db } from '../services/db.js' +import { useSyncIndicator } from '../hooks/useSyncIndicator.js' import { fetchLogbooks, createLogbook, deleteLogbook, updateLogbookTitle, type DecryptedLogbook } from '../services/logbook.js' import LogbookRoleBadge from './LogbookRoleBadge.tsx' import BetaBadge from './BetaBadge.tsx' @@ -32,8 +31,7 @@ export default function LogbookDashboard({ onSelectLogbook, onLogout, onOpenProf const [online, setOnline] = useState(navigator.onLine) const [username] = useState(localStorage.getItem('active_username') || 'Skipper') - // Reactive sync queue count - const pendingCount = useLiveQuery(() => db.syncQueue.count()) || 0 + const { pendingCount, showSpinner, showPendingWarning } = useSyncIndicator() // Listen to connectivity changes useEffect(() => { @@ -272,11 +270,27 @@ export default function LogbookDashboard({ onSelectLogbook, onLogout, onOpenProf
{/* Connection Indicator */} -
0 ? 'unsynced' : 'online') : 'offline'}`} title={online ? (pendingCount > 0 ? 'Pending Sync' : 'Synced') : 'Offline'}> +
0 ? 'unsynced' : 'online') : 'offline'}`} + title={ + online + ? showSpinner + ? 'Syncing' + : pendingCount > 0 + ? 'Pending Sync' + : 'Synced' + : 'Offline' + } + > {online ? ( - pendingCount > 0 ? ( + showSpinner ? ( <> + {t('sync.status_syncing')} + + ) : showPendingWarning ? ( + <> + {t('sync.status_unsynced')} ({pendingCount}) ) : ( diff --git a/client/src/components/UserProfilePage.tsx b/client/src/components/UserProfilePage.tsx index c5beb1a..3cc7317 100644 --- a/client/src/components/UserProfilePage.tsx +++ b/client/src/components/UserProfilePage.tsx @@ -1,6 +1,7 @@ import { useCallback, useEffect, useMemo, useState } from 'react' import { useTranslation } from 'react-i18next' import { useLiveQuery } from 'dexie-react-hooks' +import { useSyncIndicator } from '../hooks/useSyncIndicator.js' import { User, ChevronLeft, @@ -128,7 +129,7 @@ export default function UserProfilePage({ onBack, onLogout }: UserProfilePagePro const [pendingRecoveryPhrase, setPendingRecoveryPhrase] = useState(null) const [recoveryCopied, setRecoveryCopied] = useState(false) - const pendingSyncCount = useLiveQuery(() => db.syncQueue.count()) ?? 0 + const { pendingCount: pendingSyncCount, showSpinner, showPendingWarning } = useSyncIndicator() const sharedLogbookCount = useLiveQuery( () => db.logbooks.filter((lb) => lb.isShared === 1).count(), @@ -529,9 +530,14 @@ export default function UserProfilePage({ onBack, onLogout }: UserProfilePagePro

{t('profile.device_desc')}

0 ? 'warning' : 'online') : 'offline'}`}> {online ? ( - pendingSyncCount > 0 ? ( + showSpinner ? ( <>