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:
@@ -33,7 +33,9 @@ export const loadBudgetFromStorage = (): number => {
|
||||
|
||||
// 모든 데이터 완전히 초기화
|
||||
export const resetAllStorageData = (): void => {
|
||||
// 모든 Storage 키 삭제
|
||||
console.log('완전 초기화 시작 - resetAllStorageData');
|
||||
|
||||
// 모든 Storage 키 목록 (명시적으로 더 많은 키 추가)
|
||||
const keysToRemove = [
|
||||
'transactions',
|
||||
'budget',
|
||||
@@ -44,20 +46,42 @@ export const resetAllStorageData = (): void => {
|
||||
'expenseData',
|
||||
'chartData',
|
||||
'monthlyData',
|
||||
'spendingData'
|
||||
'spendingData',
|
||||
'categorySpending',
|
||||
'monthlyBudget',
|
||||
'dailyBudget',
|
||||
'weeklyBudget',
|
||||
'hasVisitedBefore',
|
||||
'dontShowWelcome',
|
||||
'monthlyTotals',
|
||||
'analytics',
|
||||
'expenseHistory',
|
||||
'budgetHistory',
|
||||
'transactionHistory',
|
||||
'lastSync',
|
||||
'syncEnabled'
|
||||
];
|
||||
|
||||
// 명시적으로 알려진 키들 삭제
|
||||
keysToRemove.forEach(key => localStorage.removeItem(key));
|
||||
keysToRemove.forEach(key => {
|
||||
console.log(`삭제 중: ${key}`);
|
||||
localStorage.removeItem(key);
|
||||
});
|
||||
|
||||
// 명시적으로 트랜잭션 초기화
|
||||
localStorage.setItem('transactions', JSON.stringify([]));
|
||||
|
||||
// 모든 예산 관련, 지출 관련 데이터 검색 및 삭제
|
||||
const keywordsToFind = ['budget', 'expense', 'transaction', 'analytic', 'spending', 'chart', 'financial', 'money', 'category'];
|
||||
const keywordsToFind = [
|
||||
'budget', 'expense', 'transaction', 'analytic',
|
||||
'spending', 'chart', 'financial', 'money',
|
||||
'category', 'month', 'daily', 'weekly', 'total',
|
||||
'sync', 'cache', 'visited', 'welcome', 'target',
|
||||
'remain', 'goal', 'analytics', 'data'
|
||||
];
|
||||
|
||||
// 모든 localStorage 순회하며 키워드 포함된 항목 삭제
|
||||
for (let i = 0; i < localStorage.length; i++) {
|
||||
for (let i = localStorage.length - 1; i >= 0; i--) {
|
||||
const key = localStorage.key(i);
|
||||
if (key) {
|
||||
const lowerKey = key.toLowerCase();
|
||||
@@ -68,5 +92,24 @@ export const resetAllStorageData = (): void => {
|
||||
}
|
||||
}
|
||||
|
||||
// 강제로 빈 데이터로 초기화
|
||||
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({
|
||||
식비: 0,
|
||||
교통비: 0,
|
||||
생활비: 0,
|
||||
쇼핑: 0,
|
||||
의료: 0,
|
||||
여가: 0,
|
||||
교육: 0,
|
||||
기타: 0
|
||||
}));
|
||||
|
||||
console.log('모든 저장소 데이터가 완전히 초기화되었습니다.');
|
||||
};
|
||||
|
||||
Reference in New Issue
Block a user