import { useState, useEffect } from 'react' import { syncProgressManager } from '@/lib/syncProgressManager' import type { SyncProgress } from '@/lib/userContentSync' import { t } from '@/lib/i18n' export function GlobalSyncProgressBar(): React.ReactElement | null { const [progress, setProgress] = useState(null) useEffect(() => { const unsubscribe = syncProgressManager.subscribe((newProgress) => { setProgress(newProgress) }) return () => { unsubscribe() } }, []) if (!progress || progress.completed) { return null } // Extract relay name from URL (remove wss:// and truncate if too long) const getRelayDisplayName = (relayUrl?: string): string => { if (!relayUrl) { return 'Connecting...' } const cleaned = relayUrl.replace(/^wss?:\/\//, '').replace(/\/$/, '') if (cleaned.length > 50) { return `${cleaned.substring(0, 47)}...` } return cleaned } // Spinning sync icon const SyncIcon = (): React.ReactElement => ( ) return (
{progress.currentRelay && ( {getRelayDisplayName(progress.currentRelay)} )} {!progress.currentRelay && ( {t('settings.sync.connecting')} )}
) }