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:
gpt-engineer-app[bot]
2025-03-18 01:21:54 +00:00
parent a6c751941c
commit a4533aea70
5 changed files with 51 additions and 13 deletions

View File

@@ -18,6 +18,7 @@ interface DataResetDialogProps {
onConfirm: () => Promise<void>;
isResetting: boolean;
isLoggedIn: boolean;
syncEnabled: boolean;
}
const DataResetDialog: React.FC<DataResetDialogProps> = ({
@@ -25,7 +26,8 @@ const DataResetDialog: React.FC<DataResetDialogProps> = ({
onOpenChange,
onConfirm,
isResetting,
isLoggedIn
isLoggedIn,
syncEnabled
}) => {
return (
<Dialog open={isOpen} onOpenChange={onOpenChange}>
@@ -40,6 +42,11 @@ const DataResetDialog: React.FC<DataResetDialogProps> = ({
<CloudOff size={16} className="mr-2" />
.
</div>
{syncEnabled && (
<div className="mt-2 text-neuro-income">
.
</div>
)}
</>
) : (
"이 작업은 되돌릴 수 없으며, 모든 예산, 지출 내역, 설정이 영구적으로 삭제됩니다."

View File

@@ -5,11 +5,13 @@ import { Button } from '@/components/ui/button';
import { useAuth } from '@/contexts/auth/AuthProvider';
import { useDataReset } from '@/hooks/useDataReset';
import DataResetDialog from './DataResetDialog';
import { isSyncEnabled } from '@/utils/sync/syncSettings';
const DataResetSection = () => {
const [isResetDialogOpen, setIsResetDialogOpen] = useState(false);
const { user } = useAuth();
const { isResetting, resetAllData } = useDataReset();
const syncEnabled = isSyncEnabled();
const handleResetAllData = async () => {
await resetAllData();
@@ -26,7 +28,11 @@ const DataResetSection = () => {
<div className="text-left">
<h3 className="font-medium"> </h3>
<p className="text-xs text-gray-500 mt-1">
{user ? "로컬 및 클라우드의 모든 예산, 지출 내역이 초기화됩니다." : "모든 예산, 지출 내역, 설정이 초기화됩니다."}
{user
? syncEnabled
? "로컬 및 클라우드의 모든 예산, 지출 내역이 초기화됩니다. 동기화 설정은 유지됩니다."
: "로컬 및 클라우드의 모든 예산, 지출 내역이 초기화됩니다."
: "모든 예산, 지출 내역, 설정이 초기화됩니다."}
</p>
</div>
</div>
@@ -46,6 +52,7 @@ const DataResetSection = () => {
onConfirm={handleResetAllData}
isResetting={isResetting}
isLoggedIn={!!user}
syncEnabled={syncEnabled}
/>
</>
);

View File

@@ -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({

View File

@@ -77,6 +77,8 @@ export const resetAllStorageData = (): void => {
const authSession = localStorage.getItem('authSession');
const sbAuth = localStorage.getItem('sb-auth-token');
const supabase = localStorage.getItem('supabase.auth.token');
// 동기화 설정 백업 (변경된 부분)
const syncEnabled = localStorage.getItem('syncEnabled');
// 모든 Storage 키 목록 (로그인 관련 항목 제외)
const keysToRemove = [
@@ -100,7 +102,7 @@ export const resetAllStorageData = (): void => {
'budgetHistory',
'transactionHistory',
'lastSync',
'syncEnabled'
// 'syncEnabled' 제거됨 - 동기화 설정은 보존
];
// 키 삭제
@@ -154,13 +156,19 @@ export const resetAllStorageData = (): void => {
localStorage.setItem('supabase.auth.token', supabase);
}
// 동기화 설정 복원 (변경된 부분)
if (syncEnabled) {
localStorage.setItem('syncEnabled', syncEnabled);
console.log('동기화 설정 복원:', syncEnabled);
}
// 이벤트 발생
window.dispatchEvent(new Event('transactionUpdated'));
window.dispatchEvent(new Event('budgetDataUpdated'));
window.dispatchEvent(new Event('categoryBudgetsUpdated'));
window.dispatchEvent(new StorageEvent('storage'));
console.log('모든 저장소 데이터가 완전히 초기화되었습니다. (로그인 상태 유지)');
console.log('모든 저장소 데이터가 완전히 초기화되었습니다. (로그인 상태와 동기화 설정 유지)');
} catch (error) {
console.error('데이터 초기화 중 오류:', error);
}

View File

@@ -54,8 +54,9 @@ export const clearCloudData = async (userId: string): Promise<boolean> => {
}
// 동기화 설정 초기화 및 마지막 동기화 시간 초기화
// 변경: 동기화 설정을 비활성화하지 않고 마지막 동기화 시간만 초기화
localStorage.removeItem('lastSync');
localStorage.setItem('syncEnabled', 'false');
// localStorage.setItem('syncEnabled', 'false'); 이 줄 제거
console.log('클라우드 데이터 초기화 완료');
return true;