Fix data initialization issue

The data initialization logic was not properly clearing existing data, leading to incorrect budget values. This commit ensures that all relevant data is cleared upon initialization.
This commit is contained in:
gpt-engineer-app[bot]
2025-03-15 23:08:06 +00:00
parent f8abebcac6
commit d798632d05
5 changed files with 191 additions and 40 deletions

View File

@@ -92,6 +92,8 @@ export const clearAllBudgetData = (): void => {
// 모든 데이터 초기화 (첫 로그인 상태)
export const resetAllData = (): void => {
console.log('완전 초기화 시작 - resetAllData');
// 모든 관련 데이터 키 목록 (분석 페이지의 데이터 포함)
const dataKeys = [
'transactions',
@@ -104,19 +106,29 @@ export const resetAllData = (): void => {
'expenseAnalytics', // 지출 분석 데이터
'expenseHistory', // 지출 이력
'budgetHistory', // 예산 이력
'analyticsCache' // 분석 캐시 데이터
'analyticsCache', // 분석 캐시 데이터
'monthlyTotals', // 월간 합계 데이터
'analytics', // 분석 페이지 데이터
'dailyBudget', // 일일 예산
'weeklyBudget', // 주간 예산
'monthlyBudget', // 월간 예산
'chartData', // 차트 데이터
'dontShowWelcome' // 환영 메시지 표시 여부
];
// 모든 관련 데이터 키 삭제
dataKeys.forEach(key => localStorage.removeItem(key));
dataKeys.forEach(key => {
console.log(`삭제 중: ${key}`);
localStorage.removeItem(key);
});
// 기본 데이터로 초기화
clearAllTransactions();
clearAllCategoryBudgets();
clearAllBudgetData();
// 추가적으로 사용자 기기에 저장된 모든 데이터 검사
for (let i = 0; i < localStorage.length; i++) {
// 추가적으로 사용자 기기에 저장된 모든 데이터 검사 (역순으로 루프)
for (let i = localStorage.length - 1; i >= 0; i--) {
const key = localStorage.key(i);
if (key && (
key.includes('expense') ||
@@ -124,13 +136,28 @@ export const resetAllData = (): void => {
key.includes('transaction') ||
key.includes('analytics') ||
key.includes('spending') ||
key.includes('financial')
key.includes('financial') ||
key.includes('chart') ||
key.includes('month') ||
key.includes('sync') ||
key.includes('total') ||
key.includes('welcome') ||
key.includes('visited')
)) {
console.log(`추가 데이터 삭제: ${key}`);
localStorage.removeItem(key);
}
}
// 강제로 빈 데이터로 초기화
localStorage.setItem('transactions', JSON.stringify([]));
localStorage.setItem('budget', JSON.stringify({total: 0}));
localStorage.setItem('budgetData', JSON.stringify({
daily: {targetAmount: 0, spentAmount: 0, remainingAmount: 0},
weekly: {targetAmount: 0, spentAmount: 0, remainingAmount: 0},
monthly: {targetAmount: 0, spentAmount: 0, remainingAmount: 0}
}));
localStorage.setItem('categoryBudgets', JSON.stringify(DEFAULT_CATEGORY_BUDGETS));
console.log('모든 데이터가 초기화되었습니다.');
};