diff --git a/components/CloudSyncSettings.tsx b/components/CloudSyncSettings.tsx index b9ef7b5c7..353884a62 100644 --- a/components/CloudSyncSettings.tsx +++ b/components/CloudSyncSettings.tsx @@ -10,24 +10,24 @@ import React, { useState, useCallback, useEffect } from 'react'; import { - AlertTriangle, - Check, - Cloud, - CloudOff, - Copy, - ExternalLink, - Eye, - EyeOff, - Fingerprint, - Github, - Key, - Loader2, - Lock, - RefreshCw, - Shield, - ShieldCheck, - Unlock, - X, + AlertTriangle, + Check, + Cloud, + CloudOff, + Copy, + ExternalLink, + Eye, + EyeOff, + Fingerprint, + Github, + Key, + Loader2, + Lock, + RefreshCw, + Shield, + ShieldCheck, + Unlock, + X, } from 'lucide-react'; import { useCloudSync } from '../application/state/useCloudSync'; import type { CloudProvider, ConflictInfo, SyncPayload } from '../domain/sync'; @@ -42,15 +42,15 @@ import { toast } from './ui/toast'; // ============================================================================ const GoogleDriveIcon: React.FC<{ className?: string }> = ({ className }) => ( - - - + + + ); const OneDriveIcon: React.FC<{ className?: string }> = ({ className }) => ( - - - + + + ); // ============================================================================ @@ -58,30 +58,30 @@ const OneDriveIcon: React.FC<{ className?: string }> = ({ className }) => ( // ============================================================================ interface ToggleProps { - checked: boolean; - onChange: (checked: boolean) => void; - disabled?: boolean; + checked: boolean; + onChange: (checked: boolean) => void; + disabled?: boolean; } const Toggle: React.FC = ({ checked, onChange, disabled }) => ( - + ); // ============================================================================ @@ -89,22 +89,22 @@ const Toggle: React.FC = ({ checked, onChange, disabled }) => ( // ============================================================================ interface StatusDotProps { - status: 'connected' | 'syncing' | 'error' | 'disconnected' | 'connecting'; - className?: string; + status: 'connected' | 'syncing' | 'error' | 'disconnected' | 'connecting'; + className?: string; } const StatusDot: React.FC = ({ status, className }) => { - const colors = { - connected: 'bg-green-500', - syncing: 'bg-blue-500 animate-pulse', - error: 'bg-red-500', - connecting: 'bg-yellow-500 animate-pulse', - disconnected: 'bg-muted-foreground/50', - }; + const colors = { + connected: 'bg-green-500', + syncing: 'bg-blue-500 animate-pulse', + error: 'bg-red-500', + connecting: 'bg-yellow-500 animate-pulse', + disconnected: 'bg-muted-foreground/50', + }; - return ( - - ); + return ( + + ); }; // ============================================================================ @@ -112,147 +112,147 @@ const StatusDot: React.FC = ({ status, className }) => { // ============================================================================ interface GatekeeperScreenProps { - onSetupComplete: () => void; + onSetupComplete: () => void; } const GatekeeperScreen: React.FC = ({ onSetupComplete }) => { - const { setupMasterKey } = useCloudSync(); - const [password, setPassword] = useState(''); - const [confirmPassword, setConfirmPassword] = useState(''); - const [showPassword, setShowPassword] = useState(false); - const [acknowledged, setAcknowledged] = useState(false); - const [isLoading, setIsLoading] = useState(false); - const [error, setError] = useState(null); + const { setupMasterKey } = useCloudSync(); + const [password, setPassword] = useState(''); + const [confirmPassword, setConfirmPassword] = useState(''); + const [showPassword, setShowPassword] = useState(false); + const [acknowledged, setAcknowledged] = useState(false); + const [isLoading, setIsLoading] = useState(false); + const [error, setError] = useState(null); - const passwordStrength = React.useMemo(() => { - if (password.length < 8) return { level: 0, text: 'Too short' }; - let score = 0; - if (password.length >= 12) score++; - if (/[A-Z]/.test(password)) score++; - if (/[a-z]/.test(password)) score++; - if (/[0-9]/.test(password)) score++; - if (/[^A-Za-z0-9]/.test(password)) score++; - - if (score <= 2) return { level: 1, text: 'Weak' }; - if (score <= 3) return { level: 2, text: 'Moderate' }; - if (score <= 4) return { level: 3, text: 'Strong' }; - return { level: 4, text: 'Very Strong' }; - }, [password]); + const passwordStrength = React.useMemo(() => { + if (password.length < 8) return { level: 0, text: 'Too short' }; + let score = 0; + if (password.length >= 12) score++; + if (/[A-Z]/.test(password)) score++; + if (/[a-z]/.test(password)) score++; + if (/[0-9]/.test(password)) score++; + if (/[^A-Za-z0-9]/.test(password)) score++; - const canSubmit = password.length >= 8 && password === confirmPassword && acknowledged; + if (score <= 2) return { level: 1, text: 'Weak' }; + if (score <= 3) return { level: 2, text: 'Moderate' }; + if (score <= 4) return { level: 3, text: 'Strong' }; + return { level: 4, text: 'Very Strong' }; + }, [password]); - const handleSubmit = async (e: React.FormEvent) => { - e.preventDefault(); - if (!canSubmit) return; + const canSubmit = password.length >= 8 && password === confirmPassword && acknowledged; - setIsLoading(true); - setError(null); + const handleSubmit = async (e: React.FormEvent) => { + e.preventDefault(); + if (!canSubmit) return; - try { - await setupMasterKey(password, confirmPassword); - toast.success('Encryption vault enabled'); - onSetupComplete(); - } catch (err) { - setError(err instanceof Error ? err.message : 'Failed to setup master key'); - } finally { - setIsLoading(false); - } - }; + setIsLoading(true); + setError(null); - return ( -
-
- -
- -

End-to-End Encrypted Sync

-

- Your data is encrypted locally before syncing. Cloud providers never see your plaintext data. - Set a master key to enable secure sync. -

+ try { + await setupMasterKey(password, confirmPassword); + toast.success('Encryption vault enabled'); + onSetupComplete(); + } catch (err) { + setError(err instanceof Error ? err.message : 'Failed to setup master key'); + } finally { + setIsLoading(false); + } + }; -
-
- -
- setPassword(e.target.value)} - placeholder="Enter a strong password" - className="pr-10" - /> - -
- {password.length > 0 && ( -
-
-
-
- {passwordStrength.text} + return ( +
+
+
- )} + +

End-to-End Encrypted Sync

+

+ Your data is encrypted locally before syncing. Cloud providers never see your plaintext data. + Set a master key to enable secure sync. +

+ + +
+ +
+ setPassword(e.target.value)} + placeholder="Enter a strong password" + className="pr-10" + /> + +
+ {password.length > 0 && ( +
+
+
+
+ {passwordStrength.text} +
+ )} +
+ +
+ + setConfirmPassword(e.target.value)} + placeholder="Confirm your password" + /> + {confirmPassword && password !== confirmPassword && ( +

Passwords do not match

+ )} +
+ + + + {error && ( +

{error}

+ )} + + +
- -
- - setConfirmPassword(e.target.value)} - placeholder="Confirm your password" - /> - {confirmPassword && password !== confirmPassword && ( -

Passwords do not match

- )} -
- - - - {error && ( -

{error}

- )} - - - -
- ); + ); }; // ============================================================================ @@ -260,102 +260,102 @@ const GatekeeperScreen: React.FC = ({ onSetupComplete }) // ============================================================================ interface UnlockScreenProps { - onUnlock: () => void; + onUnlock: () => void; } const UnlockScreen: React.FC = ({ onUnlock }) => { - const { unlock } = useCloudSync(); - const [password, setPassword] = useState(''); - const [showPassword, setShowPassword] = useState(false); - const [isLoading, setIsLoading] = useState(false); - const [error, setError] = useState(null); - const [attempts, setAttempts] = useState(0); + const { unlock } = useCloudSync(); + const [password, setPassword] = useState(''); + const [showPassword, setShowPassword] = useState(false); + const [isLoading, setIsLoading] = useState(false); + const [error, setError] = useState(null); + const [attempts, setAttempts] = useState(0); - const handleSubmit = async (e: React.FormEvent) => { - e.preventDefault(); - if (!password) return; + const handleSubmit = async (e: React.FormEvent) => { + e.preventDefault(); + if (!password) return; - setIsLoading(true); - setError(null); + setIsLoading(true); + setError(null); - try { - const success = await unlock(password); - if (success) { - onUnlock(); - } else { - setAttempts(a => a + 1); - setError('Incorrect master key'); - setPassword(''); - } - } catch { - setError('Failed to unlock vault'); - } finally { - setIsLoading(false); - } - }; + try { + const success = await unlock(password); + if (success) { + onUnlock(); + } else { + setAttempts(a => a + 1); + setError('Incorrect master key'); + setPassword(''); + } + } catch { + setError('Failed to unlock vault'); + } finally { + setIsLoading(false); + } + }; - return ( -
-
- -
- -

Vault Locked

-

- Enter your master key to access cloud sync settings and sync your data. -

+ return ( +
+
+ +
-
-
- -
- setPassword(e.target.value)} - placeholder="Enter your master key" - className="pr-10" - autoFocus - /> - -
+

Vault Locked

+

+ Enter your master key to access cloud sync settings and sync your data. +

+ + +
+ +
+ setPassword(e.target.value)} + placeholder="Enter your master key" + className="pr-10" + autoFocus + /> + +
+
+ + {error && ( +

+ {error} {attempts >= 3 && '- Too many attempts'} +

+ )} + + + + +
- - {error && ( -

- {error} {attempts >= 3 && '- Too many attempts'} -

- )} - - - - - -
- ); + ); }; // ============================================================================ @@ -363,123 +363,123 @@ const UnlockScreen: React.FC = ({ onUnlock }) => { // ============================================================================ interface ProviderCardProps { - provider: CloudProvider; - name: string; - icon: React.ReactNode; - isConnected: boolean; - isSyncing: boolean; - account?: { name?: string; email?: string; avatarUrl?: string }; - lastSync?: number; - error?: string; - onConnect: () => void; - onDisconnect: () => void; - onSync: () => void; + provider: CloudProvider; + name: string; + icon: React.ReactNode; + isConnected: boolean; + isSyncing: boolean; + account?: { name?: string; email?: string; avatarUrl?: string }; + lastSync?: number; + error?: string; + onConnect: () => void; + onDisconnect: () => void; + onSync: () => void; } const ProviderCard: React.FC = ({ - provider: _provider, - name, - icon, - isConnected, - isSyncing, - account, - lastSync, - error, - onConnect, - onDisconnect, - onSync, + provider: _provider, + name, + icon, + isConnected, + isSyncing, + account, + lastSync, + error, + onConnect, + onDisconnect, + onSync, }) => { - const formatLastSync = (timestamp?: number): string => { - if (!timestamp) return 'Never'; - const date = new Date(timestamp); - const now = new Date(); - const diff = now.getTime() - date.getTime(); - - if (diff < 60000) return 'Just now'; - if (diff < 3600000) return `${Math.floor(diff / 60000)} min ago`; - - return date.toLocaleTimeString([], { hour: '2-digit', minute: '2-digit' }); - }; + const formatLastSync = (timestamp?: number): string => { + if (!timestamp) return 'Never'; + const date = new Date(timestamp); + const now = new Date(); + const diff = now.getTime() - date.getTime(); - const status = error ? 'error' : isSyncing ? 'syncing' : isConnected ? 'connected' : 'disconnected'; + if (diff < 60000) return 'Just now'; + if (diff < 3600000) return `${Math.floor(diff / 60000)} min ago`; - return ( -
-
- {icon} -
+ return date.toLocaleTimeString([], { hour: '2-digit', minute: '2-digit' }); + }; -
-
- {name} - + const status = error ? 'error' : isSyncing ? 'syncing' : isConnected ? 'connected' : 'disconnected'; + + return ( +
+
+ {icon} +
+ +
+
+ {name} + +
+ + {isConnected && account ? ( +
+ {account.avatarUrl && ( + + )} + + {account.name || account.email} + + + · {formatLastSync(lastSync)} + +
+ ) : error ? ( +

{error}

+ ) : ( +

Not connected

+ )} +
+ +
+ {isConnected ? ( + <> + + + + ) : ( + + )} +
- - {isConnected && account ? ( -
- {account.avatarUrl && ( - - )} - - {account.name || account.email} - - - · {formatLastSync(lastSync)} - -
- ) : error ? ( -

{error}

- ) : ( -

Not connected

- )} -
- -
- {isConnected ? ( - <> - - - - ) : ( - - )} -
-
- ); + ); }; // ============================================================================ @@ -487,78 +487,78 @@ const ProviderCard: React.FC = ({ // ============================================================================ interface GitHubDeviceFlowModalProps { - isOpen: boolean; - userCode: string; - verificationUri: string; - isPolling: boolean; - onClose: () => void; + isOpen: boolean; + userCode: string; + verificationUri: string; + isPolling: boolean; + onClose: () => void; } const GitHubDeviceFlowModal: React.FC = ({ - isOpen, - userCode, - verificationUri, - isPolling, - onClose, + isOpen, + userCode, + verificationUri, + isPolling, + onClose, }) => { - const [copied, setCopied] = useState(false); + const [copied, setCopied] = useState(false); - const copyCode = useCallback(() => { - navigator.clipboard.writeText(userCode); - setCopied(true); - setTimeout(() => setCopied(false), 2000); - }, [userCode]); + const copyCode = useCallback(() => { + navigator.clipboard.writeText(userCode); + setCopied(true); + setTimeout(() => setCopied(false), 2000); + }, [userCode]); - if (!isOpen) return null; + if (!isOpen) return null; - return ( -
-
- + return ( +
+
+ -
-
- -
+
+
+ +
-

Connect to GitHub

-

- Copy the code below and enter it on GitHub to authorize Netcatty. -

+

Connect to GitHub

+

+ Copy the code below and enter it on GitHub to authorize Netcatty. +

-
-
- {userCode} +
+
+ {userCode} +
+ +
+ + + + {isPolling && ( +
+ + Waiting for authorization... +
+ )} +
- -
- - - - {isPolling && ( -
- - Waiting for authorization... -
- )}
-
-
- ); + ); }; // ============================================================================ @@ -566,92 +566,92 @@ const GitHubDeviceFlowModal: React.FC = ({ // ============================================================================ interface ConflictModalProps { - conflict: ConflictInfo | null; - onResolve: (resolution: 'USE_LOCAL' | 'USE_REMOTE') => void; - onClose: () => void; + conflict: ConflictInfo | null; + onResolve: (resolution: 'USE_LOCAL' | 'USE_REMOTE') => void; + onClose: () => void; } const ConflictModal: React.FC = ({ - conflict, - onResolve, - onClose, + conflict, + onResolve, + onClose, }) => { - if (!conflict) return null; + if (!conflict) return null; - const formatDate = (timestamp: number) => { - return new Date(timestamp).toLocaleString(); - }; + const formatDate = (timestamp: number) => { + return new Date(timestamp).toLocaleString(); + }; - return ( -
-
- + return ( +
+
+ -
-
- -
-
-

Version Conflict Detected

-

- Choose which version to keep -

-
-
+
+
+ +
+
+

Version Conflict Detected

+

+ Choose which version to keep +

+
+
-
-
-
LOCAL
-
v{conflict.localVersion}
-
- {formatDate(conflict.localUpdatedAt)} +
+
+
LOCAL
+
v{conflict.localVersion}
+
+ {formatDate(conflict.localUpdatedAt)} +
+ {conflict.localDeviceName && ( +
+ {conflict.localDeviceName} +
+ )} +
+ +
+
CLOUD
+
v{conflict.remoteVersion}
+
+ {formatDate(conflict.remoteUpdatedAt)} +
+ {conflict.remoteDeviceName && ( +
+ {conflict.remoteDeviceName} +
+ )} +
+
+ +
+ + +
- {conflict.localDeviceName && ( -
- {conflict.localDeviceName} -
- )} -
- -
-
CLOUD
-
v{conflict.remoteVersion}
-
- {formatDate(conflict.remoteUpdatedAt)} -
- {conflict.remoteDeviceName && ( -
- {conflict.remoteDeviceName} -
- )} -
- -
- - -
-
-
- ); + ); }; // Import the Download icon @@ -662,247 +662,247 @@ import { Download } from 'lucide-react'; // ============================================================================ interface SyncDashboardProps { - onBuildPayload: () => SyncPayload; - onApplyPayload: (payload: SyncPayload) => void; + onBuildPayload: () => SyncPayload; + onApplyPayload: (payload: SyncPayload) => void; } export const SyncDashboard: React.FC = ({ - onBuildPayload, - onApplyPayload, + onBuildPayload, + onApplyPayload, }) => { - const sync = useCloudSync(); - - // GitHub Device Flow state - const [showGitHubModal, setShowGitHubModal] = useState(false); - const [gitHubUserCode, setGitHubUserCode] = useState(''); - const [gitHubVerificationUri, setGitHubVerificationUri] = useState(''); - const [isPollingGitHub, setIsPollingGitHub] = useState(false); + const sync = useCloudSync(); - // Conflict modal - const [_showConflictModal, setShowConflictModal] = useState(false); + // GitHub Device Flow state + const [showGitHubModal, setShowGitHubModal] = useState(false); + const [gitHubUserCode, setGitHubUserCode] = useState(''); + const [gitHubVerificationUri, setGitHubVerificationUri] = useState(''); + const [isPollingGitHub, setIsPollingGitHub] = useState(false); - // Handle conflict detection - useEffect(() => { - if (sync.currentConflict) { - setShowConflictModal(true); - } - }, [sync.currentConflict]); + // Conflict modal + const [_showConflictModal, setShowConflictModal] = useState(false); - // Connect GitHub - const handleConnectGitHub = async () => { - try { - const deviceFlow = await sync.connectGitHub(); - setGitHubUserCode(deviceFlow.userCode); - setGitHubVerificationUri(deviceFlow.verificationUri); - setShowGitHubModal(true); - setIsPollingGitHub(true); + // Handle conflict detection + useEffect(() => { + if (sync.currentConflict) { + setShowConflictModal(true); + } + }, [sync.currentConflict]); - await sync.completeGitHubAuth( - deviceFlow.deviceCode, - deviceFlow.interval, - deviceFlow.expiresAt, - () => {} // onPending callback - ); + // Connect GitHub + const handleConnectGitHub = async () => { + try { + const deviceFlow = await sync.connectGitHub(); + setGitHubUserCode(deviceFlow.userCode); + setGitHubVerificationUri(deviceFlow.verificationUri); + setShowGitHubModal(true); + setIsPollingGitHub(true); - setIsPollingGitHub(false); - setShowGitHubModal(false); - toast.success('GitHub connected successfully'); - } catch (error) { - setIsPollingGitHub(false); - toast.error(error instanceof Error ? error.message : 'Unknown error', 'GitHub connection failed'); - } - }; + await sync.completeGitHubAuth( + deviceFlow.deviceCode, + deviceFlow.interval, + deviceFlow.expiresAt, + () => { } // onPending callback + ); - // Connect Google - const handleConnectGoogle = async () => { - try { - const url = await sync.connectGoogle(); - window.open(url, '_blank', 'width=600,height=700'); - toast.info('Complete authorization in browser'); - } catch (error) { - toast.error(error instanceof Error ? error.message : 'Unknown error', 'Google connection failed'); - } - }; + setIsPollingGitHub(false); + setShowGitHubModal(false); + toast.success('GitHub connected successfully'); + } catch (error) { + setIsPollingGitHub(false); + toast.error(error instanceof Error ? error.message : 'Unknown error', 'GitHub connection failed'); + } + }; - // Connect OneDrive - const handleConnectOneDrive = async () => { - try { - const url = await sync.connectOneDrive(); - window.open(url, '_blank', 'width=600,height=700'); - toast.info('Complete authorization in browser'); - } catch (error) { - toast.error(error instanceof Error ? error.message : 'Unknown error', 'OneDrive connection failed'); - } - }; + // Connect Google + const handleConnectGoogle = async () => { + try { + const url = await sync.connectGoogle(); + window.open(url, '_blank', 'width=600,height=700'); + toast.info('Complete authorization in browser'); + } catch (error) { + toast.error(error instanceof Error ? error.message : 'Unknown error', 'Google connection failed'); + } + }; - // Sync to provider - const handleSync = async (provider: CloudProvider) => { - try { - const payload = onBuildPayload(); - const result = await sync.syncToProvider(provider, payload); - - if (result.success) { - toast.success(`Synced to ${provider}`); - } else if (result.conflictDetected) { - // Conflict modal will show automatically - } else { - toast.error(result.error || 'Sync failed', 'Sync failed'); - } - } catch (error) { - toast.error(error instanceof Error ? error.message : 'Unknown error', 'Sync error'); - } - }; + // Connect OneDrive + const handleConnectOneDrive = async () => { + try { + const url = await sync.connectOneDrive(); + window.open(url, '_blank', 'width=600,height=700'); + toast.info('Complete authorization in browser'); + } catch (error) { + toast.error(error instanceof Error ? error.message : 'Unknown error', 'OneDrive connection failed'); + } + }; - // Resolve conflict - const handleResolveConflict = async (resolution: 'USE_LOCAL' | 'USE_REMOTE') => { - try { - const payload = await sync.resolveConflict(resolution); - if (payload && resolution === 'USE_REMOTE') { - onApplyPayload(payload); - toast.success('Downloaded cloud data'); - } else if (resolution === 'USE_LOCAL') { - // Re-sync with local data - const localPayload = onBuildPayload(); - await sync.syncNow(localPayload); - toast.success('Uploaded local data'); - } - setShowConflictModal(false); - } catch (error) { - toast.error(error instanceof Error ? error.message : 'Unknown error', 'Conflict resolution failed'); - } - }; - - return ( -
- {/* Header with status */} -
-
-
- -
-
-
- Vault Unlocked - -
- - {sync.connectedProviderCount} provider(s) connected - -
-
-
- - -
-
- - {/* Provider Cards */} -
-

Cloud Providers

- - } - isConnected={sync.providers.github.status === 'connected'} - isSyncing={sync.providers.github.status === 'syncing'} - account={sync.providers.github.account} - lastSync={sync.providers.github.lastSync} - error={sync.providers.github.error} - onConnect={handleConnectGitHub} - onDisconnect={() => sync.disconnectProvider('github')} - onSync={() => handleSync('github')} - /> - - } - isConnected={sync.providers.google.status === 'connected'} - isSyncing={sync.providers.google.status === 'syncing'} - account={sync.providers.google.account} - lastSync={sync.providers.google.lastSync} - error={sync.providers.google.error} - onConnect={handleConnectGoogle} - onDisconnect={() => sync.disconnectProvider('google')} - onSync={() => handleSync('google')} - /> - - } - isConnected={sync.providers.onedrive.status === 'connected'} - isSyncing={sync.providers.onedrive.status === 'syncing'} - account={sync.providers.onedrive.account} - lastSync={sync.providers.onedrive.lastSync} - error={sync.providers.onedrive.error} - onConnect={handleConnectOneDrive} - onDisconnect={() => sync.disconnectProvider('onedrive')} - onSync={() => handleSync('onedrive')} - /> -
- - {/* Sync All Button */} - {sync.hasAnyConnectedProvider && ( - - )} + const result = await sync.syncToProvider(provider, payload); - {/* Auto-sync Settings */} -
-
-
-
Auto-sync
-
- Automatically sync when changes are made + if (result.success) { + toast.success(`Synced to ${provider}`); + } else if (result.conflictDetected) { + // Conflict modal will show automatically + } else { + toast.error(result.error || 'Sync failed', 'Sync failed'); + } + } catch (error) { + toast.error(error instanceof Error ? error.message : 'Unknown error', 'Sync error'); + } + }; + + // Resolve conflict + const handleResolveConflict = async (resolution: 'USE_LOCAL' | 'USE_REMOTE') => { + try { + const payload = await sync.resolveConflict(resolution); + if (payload && resolution === 'USE_REMOTE') { + onApplyPayload(payload); + toast.success('Downloaded cloud data'); + } else if (resolution === 'USE_LOCAL') { + // Re-sync with local data + const localPayload = onBuildPayload(); + await sync.syncNow(localPayload); + toast.success('Uploaded local data'); + } + setShowConflictModal(false); + } catch (error) { + toast.error(error instanceof Error ? error.message : 'Unknown error', 'Conflict resolution failed'); + } + }; + + return ( +
+ {/* Header with status */} +
+
+
+ +
+
+
+ Vault Unlocked + +
+ + {sync.connectedProviderCount} provider(s) connected + +
+
+
+ + +
-
- sync.setAutoSync(enabled)} - /> + + {/* Provider Cards */} +
+

Cloud Providers

+ + } + isConnected={sync.providers.github.status === 'connected'} + isSyncing={sync.providers.github.status === 'syncing'} + account={sync.providers.github.account} + lastSync={sync.providers.github.lastSync} + error={sync.providers.github.error} + onConnect={handleConnectGitHub} + onDisconnect={() => sync.disconnectProvider('github')} + onSync={() => handleSync('github')} + /> + + } + isConnected={sync.providers.google.status === 'connected'} + isSyncing={sync.providers.google.status === 'syncing'} + account={sync.providers.google.account} + lastSync={sync.providers.google.lastSync} + error={sync.providers.google.error} + onConnect={handleConnectGoogle} + onDisconnect={() => sync.disconnectProvider('google')} + onSync={() => handleSync('google')} + /> + + } + isConnected={sync.providers.onedrive.status === 'connected'} + isSyncing={sync.providers.onedrive.status === 'syncing'} + account={sync.providers.onedrive.account} + lastSync={sync.providers.onedrive.lastSync} + error={sync.providers.onedrive.error} + onConnect={handleConnectOneDrive} + onDisconnect={() => sync.disconnectProvider('onedrive')} + onSync={() => handleSync('onedrive')} + /> +
+ + {/* Sync All Button */} + {sync.hasAnyConnectedProvider && ( + + )} + + {/* Auto-sync Settings */} +
+
+
+
Auto-sync
+
+ Automatically sync when changes are made +
+
+ sync.setAutoSync(enabled)} + /> +
+
+ + {/* Modals */} + { + setShowGitHubModal(false); + setIsPollingGitHub(false); + }} + /> + + setShowConflictModal(false)} + />
-
- - {/* Modals */} - { - setShowGitHubModal(false); - setIsPollingGitHub(false); - }} - /> - - setShowConflictModal(false)} - /> -
- ); + ); }; // ============================================================================ @@ -910,24 +910,24 @@ export const SyncDashboard: React.FC = ({ // ============================================================================ interface CloudSyncSettingsProps { - onBuildPayload: () => SyncPayload; - onApplyPayload: (payload: SyncPayload) => void; + onBuildPayload: () => SyncPayload; + onApplyPayload: (payload: SyncPayload) => void; } export const CloudSyncSettings: React.FC = (props) => { - const { securityState } = useCloudSync(); - const [justSetup, setJustSetup] = useState(false); + const { securityState } = useCloudSync(); + const [justSetup, setJustSetup] = useState(false); - // Show appropriate screen based on security state - if (securityState === 'NO_KEY') { - return setJustSetup(true)} />; - } + // Show appropriate screen based on security state + if (securityState === 'NO_KEY') { + return setJustSetup(true)} />; + } - if (securityState === 'LOCKED' && !justSetup) { - return {}} />; - } + if (securityState === 'LOCKED' && !justSetup) { + return { }} />; + } - return ; + return ; }; export default CloudSyncSettings; diff --git a/components/SyncStatusButton.tsx b/components/SyncStatusButton.tsx index 17984c379..ada60f77a 100644 --- a/components/SyncStatusButton.tsx +++ b/components/SyncStatusButton.tsx @@ -13,25 +13,25 @@ import React, { useState } from 'react'; import { - CloudOff, - Github, - Loader2, - Lock, - RefreshCw, - Settings, - Shield, - ShieldAlert, - ShieldCheck, - Unlock, + CloudOff, + Github, + Loader2, + Lock, + RefreshCw, + Settings, + Shield, + ShieldAlert, + ShieldCheck, + Unlock, } from 'lucide-react'; import { useCloudSync, useSecurityState } from '../application/state/useCloudSync'; import type { CloudProvider } from '../domain/sync'; import { cn } from '../lib/utils'; import { Button } from './ui/button'; import { - Popover, - PopoverContent, - PopoverTrigger, + Popover, + PopoverContent, + PopoverTrigger, } from './ui/popover'; // ============================================================================ @@ -39,21 +39,21 @@ import { // ============================================================================ const GoogleDriveIcon: React.FC<{ className?: string }> = ({ className }) => ( - - - + + + ); const OneDriveIcon: React.FC<{ className?: string }> = ({ className }) => ( - - - + + + ); const providerIcons: Record = { - github: , - google: , - onedrive: , + github: , + google: , + onedrive: , }; // ============================================================================ @@ -61,31 +61,31 @@ const providerIcons: Record = { // ============================================================================ interface StatusIndicatorProps { - status: 'synced' | 'syncing' | 'error' | 'locked' | 'setup' | 'none'; - size?: 'sm' | 'md'; - className?: string; + status: 'synced' | 'syncing' | 'error' | 'locked' | 'setup' | 'none'; + size?: 'sm' | 'md'; + className?: string; } const StatusIndicator: React.FC = ({ status, size = 'sm', className }) => { - const sizeClass = size === 'sm' ? 'w-2 h-2' : 'w-2.5 h-2.5'; - - const baseClasses = cn( - 'rounded-full', - sizeClass, - status === 'syncing' && 'animate-pulse', - className - ); - - const colors = { - synced: 'bg-green-500', - syncing: 'bg-blue-500', - error: 'bg-red-500', - locked: 'bg-amber-500', - setup: 'bg-muted-foreground/50', - none: 'bg-muted-foreground/30', - }; - - return ; + const sizeClass = size === 'sm' ? 'w-2 h-2' : 'w-2.5 h-2.5'; + + const baseClasses = cn( + 'rounded-full', + sizeClass, + status === 'syncing' && 'animate-pulse', + className + ); + + const colors = { + synced: 'bg-green-500', + syncing: 'bg-blue-500', + error: 'bg-red-500', + locked: 'bg-amber-500', + setup: 'bg-muted-foreground/50', + none: 'bg-muted-foreground/30', + }; + + return ; }; // ============================================================================ @@ -93,82 +93,82 @@ const StatusIndicator: React.FC = ({ status, size = 'sm', // ============================================================================ interface ProviderRowProps { - provider: CloudProvider; - name: string; - isConnected: boolean; - isSyncing: boolean; - lastSync?: number; - avatarUrl?: string; - error?: string; - onSync: () => void; + provider: CloudProvider; + name: string; + isConnected: boolean; + isSyncing: boolean; + lastSync?: number; + avatarUrl?: string; + error?: string; + onSync: () => void; } const ProviderRow: React.FC = ({ - provider, - name, - isConnected, - isSyncing, - lastSync, - avatarUrl, - error, - onSync, + provider, + name, + isConnected, + isSyncing, + lastSync, + avatarUrl, + error, + onSync, }) => { - const formatTime = (timestamp?: number): string => { - if (!timestamp) return 'Never'; - const diff = Date.now() - timestamp; - if (diff < 60000) return 'Just now'; - if (diff < 3600000) return `${Math.floor(diff / 60000)}m ago`; - return new Date(timestamp).toLocaleTimeString([], { hour: '2-digit', minute: '2-digit' }); - }; + const formatTime = (timestamp?: number): string => { + if (!timestamp) return 'Never'; + const diff = Date.now() - timestamp; + if (diff < 60000) return 'Just now'; + if (diff < 3600000) return `${Math.floor(diff / 60000)}m ago`; + return new Date(timestamp).toLocaleTimeString([], { hour: '2-digit', minute: '2-digit' }); + }; - return ( -
-
- {providerIcons[provider]} -
- -
-
- {name} - {isConnected && ( - - )} -
- {isConnected ? ( -
- {avatarUrl && ( - + return ( +
+
+ {providerIcons[provider]} +
+ +
+
+ {name} + {isConnected && ( + + )} +
+ {isConnected ? ( +
+ {avatarUrl && ( + + )} + + {formatTime(lastSync)} + +
+ ) : ( + Not connected + )} +
+ + {isConnected && ( + )} - - {formatTime(lastSync)} - -
- ) : ( - Not connected - )} -
- - {isConnected && ( - - )} -
- ); +
+ ); }; // ============================================================================ @@ -176,248 +176,248 @@ const ProviderRow: React.FC = ({ // ============================================================================ interface SyncStatusButtonProps { - onOpenSettings?: () => void; - className?: string; + onOpenSettings?: () => void; + className?: string; } export const SyncStatusButton: React.FC = ({ - onOpenSettings, - className, + onOpenSettings, + className, }) => { - const [isOpen, setIsOpen] = useState(false); - const { isLocked, hasNoKey } = useSecurityState(); - const sync = useCloudSync(); + const [isOpen, setIsOpen] = useState(false); + const { isLocked, hasNoKey } = useSecurityState(); + const sync = useCloudSync(); - // Determine overall status for the button indicator - const getOverallStatus = (): StatusIndicatorProps['status'] => { - if (hasNoKey) return 'setup'; - if (isLocked) return 'locked'; - if (sync.isSyncing) return 'syncing'; - if (sync.lastError) return 'error'; - if (sync.hasAnyConnectedProvider) return 'synced'; - return 'none'; - }; + // Determine overall status for the button indicator + const getOverallStatus = (): StatusIndicatorProps['status'] => { + if (hasNoKey) return 'setup'; + if (isLocked) return 'locked'; + if (sync.isSyncing) return 'syncing'; + if (sync.lastError) return 'error'; + if (sync.hasAnyConnectedProvider) return 'synced'; + return 'none'; + }; - const overallStatus = getOverallStatus(); + const overallStatus = getOverallStatus(); - // Get the button icon based on state - const getButtonIcon = () => { - if (hasNoKey) return ; - if (isLocked) return ; - if (sync.isSyncing) return ; - if (sync.lastError) return ; - if (sync.hasAnyConnectedProvider) return ; - return ; - }; + // Get the button icon based on state + const getButtonIcon = () => { + if (hasNoKey) return ; + if (isLocked) return ; + if (sync.isSyncing) return ; + if (sync.lastError) return ; + if (sync.hasAnyConnectedProvider) return ; + return ; + }; - // Handle sync for a specific provider - const handleSync = async (provider: CloudProvider) => { - // This would need the payload from the app - for now just trigger sync state - // In real implementation, this should call through to the app's sync handler - console.log('Sync requested for:', provider); - }; + // Handle sync for a specific provider + const handleSync = async (provider: CloudProvider) => { + // This would need the payload from the app - for now just trigger sync state + // In real implementation, this should call through to the app's sync handler + console.log('Sync requested for:', provider); + }; - return ( - - - - - - - {/* Header */} -
-
-
- {overallStatus === 'synced' && ( - - )} - {overallStatus === 'syncing' && ( - - )} - {overallStatus === 'error' && ( - - )} - {overallStatus === 'locked' && ( - - )} - {(overallStatus === 'setup' || overallStatus === 'none') && ( - - )} - - - {overallStatus === 'synced' && 'Synced'} - {overallStatus === 'syncing' && 'Syncing...'} - {overallStatus === 'error' && 'Sync Error'} - {overallStatus === 'locked' && 'Vault Locked'} - {overallStatus === 'setup' && 'Setup Required'} - {overallStatus === 'none' && 'Not Connected'} - -
- - {onOpenSettings && ( - - )} -
- - {sync.deviceName && overallStatus !== 'setup' && ( -
- {sync.deviceName} -
- )} -
+ return ( + + + -
- ) : isLocked ? ( - // Locked state -
- -

- Unlock your vault to sync data. -

- -
- ) : ( - // Connected/syncing state - show providers - <> - handleSync('github')} - /> - - handleSync('google')} - /> - - handleSync('onedrive')} - /> - - {/* Quick actions */} - {sync.hasAnyConnectedProvider && ( -
- + + + + {/* Header */} +
+
+
+ {overallStatus === 'synced' && ( + + )} + {overallStatus === 'syncing' && ( + + )} + {overallStatus === 'error' && ( + + )} + {overallStatus === 'locked' && ( + + )} + {(overallStatus === 'setup' || overallStatus === 'none') && ( + + )} + + + {overallStatus === 'synced' && 'Synced'} + {overallStatus === 'syncing' && 'Syncing...'} + {overallStatus === 'error' && 'Sync Error'} + {overallStatus === 'locked' && 'Vault Locked'} + {overallStatus === 'setup' && 'Setup Required'} + {overallStatus === 'none' && 'Not Connected'} + +
+ + {onOpenSettings && ( + + )} +
+ + {sync.deviceName && overallStatus !== 'setup' && ( +
+ {sync.deviceName} +
)} - Sync All Now -
- )} - - {!sync.hasAnyConnectedProvider && ( -
-

- Connect a cloud provider to start syncing. -

- + + {/* Content based on state */} +
+ {hasNoKey ? ( + // Setup required +
+ +

+ Set up encrypted sync to keep your data safe across devices. +

+ +
+ ) : isLocked ? ( + // Locked state +
+ +

+ Unlock your vault to sync data. +

+ +
+ ) : ( + // Connected/syncing state - show providers + <> + handleSync('github')} + /> + + handleSync('google')} + /> + + handleSync('onedrive')} + /> + + {/* Quick actions */} + {sync.hasAnyConnectedProvider && ( +
+ +
+ )} + + {!sync.hasAnyConnectedProvider && ( +
+

+ Connect a cloud provider to start syncing. +

+ +
+ )} + + )}
- )} - - )} -
-
- - ); + + + ); }; export default SyncStatusButton;