import React, { useEffect, useState } from 'react'; import { CloudOff, RefreshCw } from 'lucide-react'; import { outboxCount } from '../lib/offline'; // Small notice above the bottom navigation: offline (with the number of changes waiting), or // "synchronisiere" while queued changes are being sent after the connection came back. export const OfflineBanner: React.FC = () => { const [online, setOnline] = useState(() => (typeof navigator === 'undefined' ? true : navigator.onLine)); const [pending, setPending] = useState(() => outboxCount()); useEffect(() => { const update = () => { setOnline(navigator.onLine); setPending(outboxCount()); }; window.addEventListener('online', update); window.addEventListener('offline', update); window.addEventListener('mindsift:outbox-changed', update); window.addEventListener('storage', update); return () => { window.removeEventListener('online', update); window.removeEventListener('offline', update); window.removeEventListener('mindsift:outbox-changed', update); window.removeEventListener('storage', update); }; }, []); if (online && pending === 0) return null; const waiting = `${pending} ${pending === 1 ? 'Änderung wartet' : 'Änderungen warten'}`; return (
{online ? ( ) : ( )} {online ? `Synchronisiere – ${waiting}…` : pending > 0 ? `Offline · ${waiting} auf Verbindung` : 'Offline – Änderungen werden bei Verbindung synchronisiert'}
); };