Refactor data initialization process

Review and adjust the data initialization logic to ensure proper functionality.
This commit is contained in:
gpt-engineer-app[bot]
2025-03-16 07:52:45 +00:00
parent 23ba0f7e90
commit c5a5a20d36
6 changed files with 342 additions and 247 deletions

View File

@@ -13,11 +13,21 @@ export const useBudgetReset = (
try {
console.log('BudgetContext에서 데이터 리셋 시작');
// 로컬 스토리지 초기화
// 데이터 초기화 순서 중요
resetTransactions();
resetCategoryBudgets();
resetBudgetDataInternal();
// 이벤트 발생
try {
window.dispatchEvent(new Event('transactionUpdated'));
window.dispatchEvent(new Event('budgetDataUpdated'));
window.dispatchEvent(new Event('categoryBudgetsUpdated'));
window.dispatchEvent(new StorageEvent('storage'));
} catch (e) {
console.error('이벤트 발생 오류:', e);
}
console.log('BudgetContext에서 데이터 리셋 완료');
// 토스트 알림
@@ -25,6 +35,8 @@ export const useBudgetReset = (
title: "모든 데이터 초기화",
description: "예산과 지출 내역이 모두 초기화되었습니다.",
});
return true;
} catch (error) {
console.error('데이터 초기화 중 오류:', error);
toast({
@@ -32,6 +44,8 @@ export const useBudgetReset = (
description: "데이터를 초기화하는 중 오류가 발생했습니다.",
variant: "destructive"
});
return false;
}
}, [resetTransactions, resetCategoryBudgets, resetBudgetDataInternal]);