Handle data reset with cloud sync
The prompt requests clarification on whether data reset should also delete cloud data when the user is logged in.
This commit is contained in:
@@ -1,13 +1,15 @@
|
||||
|
||||
import { useState, useEffect, useCallback } from 'react';
|
||||
import { resetAllData } from '@/contexts/budget/storage';
|
||||
import { resetAllStorageData } from '@/utils/storageUtils';
|
||||
import { clearCloudData } from '@/utils/syncUtils';
|
||||
import { useAuth } from '@/contexts/auth/AuthProvider';
|
||||
|
||||
export const useDataInitialization = (resetBudgetData?: () => void) => {
|
||||
const [isInitialized, setIsInitialized] = useState(false);
|
||||
const { user } = useAuth();
|
||||
|
||||
// 모든 데이터 초기화 함수
|
||||
const initializeAllData = useCallback(() => {
|
||||
const initializeAllData = useCallback(async () => {
|
||||
// 중요: 이미 방문한 적이 있으면 절대 초기화하지 않음
|
||||
const hasVisitedBefore = localStorage.getItem('hasVisitedBefore') === 'true';
|
||||
if (hasVisitedBefore) {
|
||||
@@ -23,6 +25,12 @@ export const useDataInitialization = (resetBudgetData?: () => void) => {
|
||||
console.log('useDataInitialization - 초기화 전 dontShowWelcome 값:', dontShowWelcomeValue);
|
||||
|
||||
try {
|
||||
// 로그인 상태라면 클라우드 데이터도 초기화 (첫 방문 시)
|
||||
if (user) {
|
||||
console.log('로그인 상태: 클라우드 데이터도 초기화 시도');
|
||||
await clearCloudData(user.id);
|
||||
}
|
||||
|
||||
// 모든 데이터 완전히 삭제 및 초기화 (한 번만 실행)
|
||||
resetAllData();
|
||||
resetAllStorageData();
|
||||
@@ -48,7 +56,7 @@ export const useDataInitialization = (resetBudgetData?: () => void) => {
|
||||
console.error('데이터 초기화 중 오류 발생:', error);
|
||||
return false;
|
||||
}
|
||||
}, [resetBudgetData]);
|
||||
}, [resetBudgetData, user]);
|
||||
|
||||
// 분석 페이지 데이터 초기화 함수
|
||||
const clearAllAnalyticsData = useCallback(() => {
|
||||
@@ -100,8 +108,9 @@ export const useDataInitialization = (resetBudgetData?: () => void) => {
|
||||
console.log('이미 방문 기록이 있어 초기화를 건너뜁니다.');
|
||||
setIsInitialized(true);
|
||||
} else {
|
||||
const result = initializeAllData();
|
||||
setIsInitialized(result);
|
||||
initializeAllData().then(result => {
|
||||
setIsInitialized(result);
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user