Review and refine sync logic
This commit reviews and refines the synchronization logic to ensure proper functionality and data integrity.
This commit is contained in:
@@ -1,10 +1,8 @@
|
||||
|
||||
import { useState } from 'react';
|
||||
import { toast } from '@/hooks/useToast.wrapper';
|
||||
import { trySyncAllData } from '@/utils/syncUtils';
|
||||
import { getLastSyncTime, setLastSyncTime } from '@/utils/syncUtils';
|
||||
import { trySyncAllData, setLastSyncTime } from '@/utils/syncUtils';
|
||||
import { handleSyncResult } from './syncResultHandler';
|
||||
import type { SyncResult } from '@/utils/syncUtils';
|
||||
|
||||
/**
|
||||
* 수동 동기화 기능을 위한 커스텀 훅
|
||||
@@ -23,6 +21,12 @@ export const useManualSync = (user: any) => {
|
||||
return;
|
||||
}
|
||||
|
||||
// 이미 동기화 중이면 중복 실행 방지
|
||||
if (syncing) {
|
||||
console.log('이미 동기화가 진행 중입니다.');
|
||||
return;
|
||||
}
|
||||
|
||||
await performSync(user.id);
|
||||
};
|
||||
|
||||
@@ -32,11 +36,20 @@ export const useManualSync = (user: any) => {
|
||||
|
||||
try {
|
||||
setSyncing(true);
|
||||
// 인자 수정: userId만 전달
|
||||
console.log('수동 동기화 시작');
|
||||
|
||||
// 동기화 실행
|
||||
const result = await trySyncAllData(userId);
|
||||
|
||||
// 동기화 결과 처리
|
||||
handleSyncResult(result);
|
||||
setLastSyncTime(new Date().toISOString());
|
||||
|
||||
// 동기화 시간 업데이트
|
||||
if (result.success) {
|
||||
setLastSyncTime(new Date().toISOString());
|
||||
}
|
||||
|
||||
return result;
|
||||
} catch (error) {
|
||||
console.error('동기화 오류:', error);
|
||||
toast({
|
||||
@@ -46,6 +59,7 @@ export const useManualSync = (user: any) => {
|
||||
});
|
||||
} finally {
|
||||
setSyncing(false);
|
||||
console.log('수동 동기화 종료');
|
||||
}
|
||||
};
|
||||
|
||||
|
||||
Reference in New Issue
Block a user