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:
gpt-engineer-app[bot]
2025-03-16 06:46:45 +00:00
parent 16c17f0257
commit f3edf5fa20
8 changed files with 126 additions and 78 deletions

View File

@@ -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
};