fix: Sync-Icon nur während aktiver Synchronisation animieren

Die Drehung hing an der Queue-Länge statt am laufenden Sync. Veraltete
Queue-Einträge werden nach Pull bereinigt; parallele syncAll-Läufe
werden im Sync-State korrekt gezählt.

Co-authored-by: Cursor <cursoragent@cursor.com>
This commit is contained in:
2026-05-31 12:23:50 +02:00
co-authored by Cursor
parent b86e5a15d6
commit 282e7ba8ba
6 changed files with 117 additions and 13 deletions
+28
View File
@@ -0,0 +1,28 @@
import { useEffect, useState } from 'react'
import { useLiveQuery } from 'dexie-react-hooks'
import { db } from '../services/db.js'
import { subscribeToSyncState } from '../services/sync.js'
/** Sync queue depth and whether a sync pass is running (for header indicators). */
export function useSyncIndicator(logbookId?: string | null) {
const [isSyncing, setIsSyncing] = useState(false)
const pendingCount =
useLiveQuery(
() =>
logbookId
? db.syncQueue.where({ logbookId }).count()
: db.syncQueue.count(),
[logbookId]
) ?? 0
useEffect(() => subscribeToSyncState(setIsSyncing), [])
return {
isSyncing,
pendingCount,
/** Spin only while a sync pass is active — not for stale queue counts. */
showSpinner: isSyncing,
showPendingWarning: pendingCount > 0 && !isSyncing
}
}