'use client'; import { useState, useEffect } from 'react'; import { getLoginUrl } from '@/lib/config/storage'; import { Dialog, DialogContent, DialogDescription, DialogFooter, DialogHeader, DialogTitle, } from '@/components/ui/dialog'; import { Button } from '@/components/ui/button'; import { Cloud, CloudOff, RefreshCw, AlertTriangle, CheckSquare, ArrowUp, ArrowDown } from 'lucide-react'; import { SyncTabs, BulkActionState } from './sync-tabs'; import { useSyncStatus } from './hooks/use-sync-status'; interface SyncDialogProps { open: boolean; onOpenChange: (open: boolean) => void; onSyncComplete?: () => void; } export function SyncDialog({ open, onOpenChange, onSyncComplete }: SyncDialogProps) { const [authenticated, setAuthenticated] = useState(false); const [authLoading, setAuthLoading] = useState(true); const { status, refresh, loading, refreshing, error } = useSyncStatus(); const [bulkState, setBulkState] = useState(null); useEffect(() => { if (open) { checkAuth(); refresh(); } }, [open, refresh]); const checkAuth = async () => { setAuthLoading(true); try { const response = await fetch('/api/auth/me'); const data = await response.json(); setAuthenticated(data.authenticated); } catch { setAuthenticated(false); } finally { setAuthLoading(false); } }; const handleSyncComplete = () => { refresh(); onSyncComplete?.(); }; const dialogContentClass = "sm:max-w-2xl"; // Loading state if (authLoading) { return ( Server Sync Checking authentication status... ); } // Not authenticated if (!authenticated) { return ( Not Authenticated You need to login to sync projects, skills, and templates with the server. ); } return ( Server Sync Synchronize projects, skills, and templates between your browser and the server.
{/* Error Banner */} {error && (

Error loading sync status

{error}

)} {/* Initial Loading */} {loading && (
Loading sync status...
)} {/* Tabbed Content (kept visible during refresh) */} {!loading && !error && (
{refreshing && (
)}
)}
{/* Bulk Actions - left side */}
{bulkState && bulkState.selectableCount > 0 && ( )} {bulkState && bulkState.pushableCount > 0 && ( )} {bulkState && bulkState.pullableCount > 0 && ( )}
{/* Right side buttons */}
); }