import { useState, useEffect } from 'react' import { syncProgressManager } from '@/lib/syncProgressManager' import type { SyncProgress } from '@/lib/userContentSync' import { t } from '@/lib/i18n' // Extract relay name from URL (remove wss:// and truncate if too long) function getRelayDisplayName(relayUrl?: string): string { if (!relayUrl) { return '' } const cleaned = relayUrl.replace(/^wss?:\/\//, '').replace(/\/$/, '') if (cleaned.length > 50) { return `${cleaned.substring(0, 47)}...` } return cleaned } // Spinning sync icon function SyncIcon(): React.ReactElement { return ( ) } /** * Sync status indicator component for display in header next to key icon * Shows sync icon + relay name when syncing */ export function SyncStatus(): React.ReactElement | null { const [progress, setProgress] = useState(null) useEffect(() => { const unsubscribe = syncProgressManager.subscribe((newProgress) => { setProgress(newProgress) }) // Check current progress immediately const currentProgress = syncProgressManager.getProgress() if (currentProgress) { setProgress(currentProgress) } return () => { unsubscribe() } }, []) // Show indicator if we have progress and it's not completed if (!progress) { return null } // Always show indicator during sync, even if completed is false (means sync is in progress) if (progress.completed) { return null } const relayName = progress.currentRelay ? getRelayDisplayName(progress.currentRelay) : null return (
{relayName ? ( {relayName} ) : ( {t('settings.sync.connecting')} )}
) } /** * Global sync progress bar (deprecated - kept for backward compatibility) * @deprecated Use SyncStatus component in KeyManagementManager instead */ export function GlobalSyncProgressBar(): React.ReactElement | null { return null }