Retain sync setting on reset
After data reset, the sync setting should remain in its previous state (On or Off) instead of always defaulting to Off.
This commit is contained in:
@@ -5,7 +5,7 @@ import { useToast } from '@/hooks/useToast.wrapper';
|
||||
import { resetAllStorageData } from '@/utils/storageUtils';
|
||||
import { clearCloudData } from '@/utils/syncUtils';
|
||||
import { useAuth } from '@/contexts/auth/AuthProvider';
|
||||
import { setSyncEnabled } from '@/utils/sync/syncSettings';
|
||||
import { isSyncEnabled } from '@/utils/sync/syncSettings';
|
||||
|
||||
export interface DataResetResult {
|
||||
isCloudResetSuccess: boolean | null;
|
||||
@@ -23,6 +23,10 @@ export const useDataReset = () => {
|
||||
setIsResetting(true);
|
||||
console.log('모든 데이터 초기화 시작');
|
||||
|
||||
// 현재 동기화 설정 저장
|
||||
const syncWasEnabled = isSyncEnabled();
|
||||
console.log('데이터 초기화 전 동기화 상태:', syncWasEnabled ? '활성화' : '비활성화');
|
||||
|
||||
// 클라우드 데이터 초기화 먼저 시도 (로그인 상태인 경우)
|
||||
let cloudResetSuccess = false;
|
||||
if (user) {
|
||||
@@ -32,8 +36,8 @@ export const useDataReset = () => {
|
||||
|
||||
if (cloudResetSuccess) {
|
||||
console.log('클라우드 데이터 초기화 성공');
|
||||
// 동기화 비활성화 (중요: 초기화 후 자동 동기화 방지)
|
||||
setSyncEnabled(false);
|
||||
// 주석 처리 - 동기화 설정 유지
|
||||
// setSyncEnabled(false);
|
||||
} else {
|
||||
console.warn('클라우드 데이터 초기화 실패 또는 부분 성공');
|
||||
}
|
||||
@@ -65,6 +69,12 @@ export const useDataReset = () => {
|
||||
}
|
||||
}
|
||||
|
||||
// 동기화 설정 백업
|
||||
if (syncWasEnabled) {
|
||||
authBackupItems['syncEnabled'] = 'true';
|
||||
console.log('동기화 설정 백업: 활성화 상태');
|
||||
}
|
||||
|
||||
// 데이터 초기화
|
||||
resetAllStorageData();
|
||||
|
||||
@@ -85,12 +95,15 @@ export const useDataReset = () => {
|
||||
}
|
||||
});
|
||||
|
||||
// 동기화 설정 초기화
|
||||
if (user) {
|
||||
localStorage.removeItem('lastSync');
|
||||
localStorage.setItem('syncEnabled', 'false');
|
||||
// 동기화 설정 복원
|
||||
if (syncWasEnabled) {
|
||||
localStorage.setItem('syncEnabled', 'true');
|
||||
console.log('동기화 설정 복원: 활성화 상태');
|
||||
}
|
||||
|
||||
// 마지막 동기화 시간은 초기화
|
||||
localStorage.removeItem('lastSync');
|
||||
|
||||
// 스토리지 이벤트 트리거하여 다른 컴포넌트에 변경 알림
|
||||
window.dispatchEvent(new Event('transactionUpdated'));
|
||||
window.dispatchEvent(new Event('budgetDataUpdated'));
|
||||
@@ -102,7 +115,9 @@ export const useDataReset = () => {
|
||||
if (cloudResetSuccess) {
|
||||
toast({
|
||||
title: "모든 데이터가 초기화되었습니다.",
|
||||
description: "로컬 및 클라우드의 모든 데이터가 초기화되었습니다. 동기화 기능이 꺼졌습니다.",
|
||||
description: syncWasEnabled
|
||||
? "로컬 및 클라우드의 모든 데이터가 초기화되었습니다. 동기화 설정은 유지됩니다."
|
||||
: "로컬 및 클라우드의 모든 데이터가 초기화되었습니다.",
|
||||
});
|
||||
} else {
|
||||
toast({
|
||||
|
||||
Reference in New Issue
Block a user