import { useState } from 'react'; import { toast } from '@/hooks/useToast.wrapper'; import { trySyncAllData } from '@/utils/syncUtils'; import { getLastSyncTime, setLastSyncTime } from '@/utils/syncUtils'; import { handleSyncResult } from './syncResultHandler'; import type { SyncResult } from '@/utils/syncUtils'; /** * 수동 동기화 기능을 위한 커스텀 훅 */ export const useManualSync = (user: any) => { const [syncing, setSyncing] = useState(false); // 수동 동기화 핸들러 const handleManualSync = async () => { if (!user) { toast({ title: "로그인 필요", description: "데이터 동기화를 위해 로그인이 필요합니다.", variant: "destructive" }); return; } await performSync(user.id); }; // 실제 동기화 수행 함수 const performSync = async (userId: string) => { if (!userId) return; try { setSyncing(true); // 인자 수정: 콜백 함수 제거 const result = await trySyncAllData(userId); handleSyncResult(result); setLastSyncTime(new Date().toISOString()); } catch (error) { console.error('동기화 오류:', error); toast({ title: "동기화 오류", description: "동기화 중 문제가 발생했습니다. 다시 시도해주세요.", variant: "destructive" }); } finally { setSyncing(false); } }; return { syncing, handleManualSync }; };