Ensure sync is disabled

The sync setting was not consistently being disabled in certain scenarios. This change ensures that the sync setting is properly disabled when expected.
This commit is contained in:
gpt-engineer-app[bot]
2025-03-18 01:48:38 +00:00
parent dfb9d8ca69
commit 043db23836
5 changed files with 59 additions and 25 deletions

View File

@@ -3,9 +3,9 @@ import { useState } from 'react';
import { useNavigate } from 'react-router-dom';
import { useToast } from '@/hooks/useToast.wrapper';
import { resetAllStorageData } from '@/utils/storageUtils';
import { clearCloudData } from '@/utils/syncUtils';
import { clearCloudData } from '@/utils/sync/clearCloudData';
import { useAuth } from '@/contexts/auth/AuthProvider';
import { isSyncEnabled } from '@/utils/sync/syncSettings';
import { isSyncEnabled, setSyncEnabled } from '@/utils/sync/syncSettings';
export interface DataResetResult {
isCloudResetSuccess: boolean | null;
@@ -36,8 +36,6 @@ export const useDataReset = () => {
if (cloudResetSuccess) {
console.log('클라우드 데이터 초기화 성공');
// 주석 처리 - 동기화 설정 유지
// setSyncEnabled(false);
} else {
console.warn('클라우드 데이터 초기화 실패 또는 부분 성공');
}
@@ -69,12 +67,6 @@ export const useDataReset = () => {
}
}
// 동기화 설정 백업
if (syncWasEnabled) {
authBackupItems['syncEnabled'] = 'true';
console.log('동기화 설정 백업: 활성화 상태');
}
// 데이터 초기화
resetAllStorageData();
@@ -95,11 +87,9 @@ export const useDataReset = () => {
}
});
// 동기화 설정 복원
if (syncWasEnabled) {
localStorage.setItem('syncEnabled', 'true');
console.log('동기화 설정 복원: 활성화 상태');
}
// 중요: 동기화 설정은 초기화 후 항상 비활성화
setSyncEnabled(false);
console.log('동기화 설정이 비활성화되었습니다.');
// 마지막 동기화 시간은 초기화
localStorage.removeItem('lastSync');
@@ -109,20 +99,19 @@ export const useDataReset = () => {
window.dispatchEvent(new Event('budgetDataUpdated'));
window.dispatchEvent(new Event('categoryBudgetsUpdated'));
window.dispatchEvent(new StorageEvent('storage'));
window.dispatchEvent(new Event('auth-state-changed')); // 동기화 상태 변경 이벤트 추가
// 클라우드 초기화 상태에 따라 다른 메시지 표시
if (user) {
if (cloudResetSuccess) {
toast({
title: "모든 데이터가 초기화되었습니다.",
description: syncWasEnabled
? "로컬 및 클라우드의 모든 데이터가 초기화되었습니다. 동기화 설정은 유지됩니다."
: "로컬 및 클라우드의 모든 데이터가 초기화되었습니다.",
description: "로컬 및 클라우드의 모든 데이터가 초기화되었으며, 동기화 설정이 비활성화되었습니다.",
});
} else {
toast({
title: "로컬 데이터만 초기화됨",
description: "로컬 데이터는 초기화되었지만, 클라우드 데이터 초기화 중 문제가 발생했습니다.",
description: "로컬 데이터는 초기화되었지만, 클라우드 데이터 초기화 중 문제가 발생했습니다. 동기화 설정이 비활성화되었습니다.",
variant: "destructive"
});
}