Fix data display issues
Addresses issues where budget and expense data were not displaying correctly on the summary cards, category bar graph, and transaction/analytics pages. Also fixes a bug where data was disappearing after input.
This commit is contained in:
@@ -12,28 +12,40 @@ export const useCategoryBudgetState = () => {
|
||||
loadCategoryBudgetsFromStorage()
|
||||
);
|
||||
|
||||
// 이벤트 리스너 설정
|
||||
// 초기 로드 및 이벤트 리스너 설정
|
||||
useEffect(() => {
|
||||
const loadCategories = () => {
|
||||
console.log('카테고리 예산 로드 시도');
|
||||
const loaded = loadCategoryBudgetsFromStorage();
|
||||
setCategoryBudgets(loaded);
|
||||
console.log('카테고리 예산 로드됨:', loaded);
|
||||
};
|
||||
|
||||
// 초기 로드
|
||||
loadCategories();
|
||||
|
||||
// 이벤트 리스너 설정
|
||||
const handleCategoryUpdate = () => {
|
||||
setCategoryBudgets(loadCategoryBudgetsFromStorage());
|
||||
console.log('카테고리 예산 업데이트 이벤트 감지');
|
||||
loadCategories();
|
||||
};
|
||||
|
||||
window.addEventListener('categoryBudgetsUpdated', handleCategoryUpdate);
|
||||
window.addEventListener('storage', handleCategoryUpdate);
|
||||
window.addEventListener('focus', handleCategoryUpdate);
|
||||
|
||||
return () => {
|
||||
window.removeEventListener('categoryBudgetsUpdated', handleCategoryUpdate);
|
||||
window.removeEventListener('storage', handleCategoryUpdate);
|
||||
window.removeEventListener('focus', handleCategoryUpdate);
|
||||
};
|
||||
}, []);
|
||||
|
||||
// 카테고리 예산 업데이트 함수
|
||||
const updateCategoryBudgets = useCallback((newCategoryBudgets: Record<string, number>) => {
|
||||
console.log('카테고리 예산 업데이트:', newCategoryBudgets);
|
||||
setCategoryBudgets(newCategoryBudgets);
|
||||
saveCategoryBudgetsToStorage(newCategoryBudgets);
|
||||
|
||||
// 로컬 이벤트 발생 (다른 컴포넌트에서 변경 감지하도록)
|
||||
window.dispatchEvent(new Event('categoryBudgetsUpdated'));
|
||||
}, []);
|
||||
|
||||
// 카테고리 예산 초기화 함수
|
||||
@@ -45,7 +57,7 @@ export const useCategoryBudgetState = () => {
|
||||
|
||||
return {
|
||||
categoryBudgets,
|
||||
setCategoryBudgets,
|
||||
setCategoryBudgets: updateCategoryBudgets,
|
||||
updateCategoryBudgets,
|
||||
resetCategoryBudgets
|
||||
};
|
||||
|
||||
Reference in New Issue
Block a user