Fix data persistence issue

Addresses a bug where budget and expense data were not persisting correctly, leading to data loss when navigating between pages.
This commit is contained in:
gpt-engineer-app[bot]
2025-03-16 06:41:57 +00:00
parent c23f5cddef
commit 16c17f0257
9 changed files with 135 additions and 37 deletions

View File

@@ -4,7 +4,7 @@ import {
loadCategoryBudgetsFromStorage,
saveCategoryBudgetsToStorage,
clearAllCategoryBudgets
} from '../storage/categoryStorage';
} from '../storage';
// 카테고리 예산 상태 관리 훅
export const useCategoryBudgetState = () => {
@@ -12,6 +12,21 @@ export const useCategoryBudgetState = () => {
loadCategoryBudgetsFromStorage()
);
// 이벤트 리스너 설정
useEffect(() => {
const handleCategoryUpdate = () => {
setCategoryBudgets(loadCategoryBudgetsFromStorage());
};
window.addEventListener('categoryBudgetsUpdated', handleCategoryUpdate);
window.addEventListener('storage', handleCategoryUpdate);
return () => {
window.removeEventListener('categoryBudgetsUpdated', handleCategoryUpdate);
window.removeEventListener('storage', handleCategoryUpdate);
};
}, []);
// 카테고리 예산 업데이트 함수
const updateCategoryBudgets = useCallback((newCategoryBudgets: Record<string, number>) => {
setCategoryBudgets(newCategoryBudgets);