Fix data loss on sync after reset
Addresses an issue where budget data was lost after a data reset, logout, and subsequent synchronization. The fix ensures budget data is correctly restored in such scenarios.
This commit is contained in:
@@ -1,47 +1,49 @@
|
||||
|
||||
import { SyncResult } from '@/utils/sync/data';
|
||||
import { toast } from '@/hooks/useToast.wrapper';
|
||||
import type { SyncResult } from '@/utils/syncUtils';
|
||||
|
||||
/**
|
||||
* 동기화 결과 처리 함수
|
||||
*/
|
||||
// 동기화 결과 처리 함수
|
||||
export const handleSyncResult = (result: SyncResult) => {
|
||||
if (!result) {
|
||||
toast({
|
||||
title: "동기화 오류",
|
||||
description: "동기화 결과를 처리할 수 없습니다.",
|
||||
variant: "destructive"
|
||||
});
|
||||
return;
|
||||
}
|
||||
|
||||
if (result.success) {
|
||||
if (result.partial) {
|
||||
// 부분 성공 처리
|
||||
toast({
|
||||
title: "부분 동기화 완료",
|
||||
description: "일부 데이터만 동기화되었습니다. 다시 시도해보세요.",
|
||||
variant: "default"
|
||||
});
|
||||
} else {
|
||||
// 전체 성공 처리
|
||||
if (result.uploadSuccess && result.downloadSuccess) {
|
||||
// 양방향 동기화 성공
|
||||
toast({
|
||||
title: "동기화 완료",
|
||||
description: "모든 데이터가 성공적으로 동기화되었습니다.",
|
||||
variant: "default"
|
||||
});
|
||||
|
||||
// 데이터 변경 이벤트 발생
|
||||
window.dispatchEvent(new Event('budgetDataUpdated'));
|
||||
window.dispatchEvent(new Event('categoryBudgetsUpdated'));
|
||||
window.dispatchEvent(new Event('transactionUpdated'));
|
||||
} else if (result.uploadSuccess) {
|
||||
// 업로드만 성공
|
||||
toast({
|
||||
title: "동기화 완료",
|
||||
description: "로컬 데이터가 클라우드에 업로드되었습니다.",
|
||||
});
|
||||
} else if (result.downloadSuccess) {
|
||||
// 다운로드만 성공
|
||||
toast({
|
||||
title: "동기화 완료",
|
||||
description: "클라우드 데이터가 기기에 다운로드되었습니다.",
|
||||
});
|
||||
}
|
||||
|
||||
// 상세 결과 로깅
|
||||
console.log("동기화 세부 결과:", {
|
||||
예산업로드: result.details?.budgetUpload ? '성공' : '실패',
|
||||
예산다운로드: result.details?.budgetDownload ? '성공' : '실패',
|
||||
트랜잭션업로드: result.details?.transactionUpload ? '성공' : '실패',
|
||||
트랜잭션다운로드: result.details?.transactionDownload ? '성공' : '실패'
|
||||
});
|
||||
|
||||
return true;
|
||||
} else {
|
||||
// 실패 처리
|
||||
// 동기화 실패
|
||||
console.error("동기화 실패 세부 결과:", result.details);
|
||||
|
||||
toast({
|
||||
title: "동기화 실패",
|
||||
description: "데이터 동기화에 실패했습니다. 나중에 다시 시도해보세요.",
|
||||
description: "데이터 동기화 중 문제가 발생했습니다. 다시 시도해주세요.",
|
||||
variant: "destructive"
|
||||
});
|
||||
|
||||
return false;
|
||||
}
|
||||
};
|
||||
|
||||
Reference in New Issue
Block a user