Investigate budget display issue

Examine why budget data is not displaying correctly on the expense and analytics screens, despite being saved successfully.
This commit is contained in:
gpt-engineer-app[bot]
2025-03-22 10:53:56 +00:00
parent c92d41e8f0
commit ab86d9b5f9
5 changed files with 223 additions and 75 deletions

View File

@@ -17,7 +17,7 @@ export const useExtendedBudgetUpdate = (
amount: number,
newCategoryBudgets?: Record<string, number>
) => {
console.log(`확장된 예산 목표 업데이트: ${type}, 금액: ${amount}, 카테고리 예산:`, newCategoryBudgets);
console.log(`확장된 예산 목표 업데이트 호출: ${type}, 금액: ${amount}, 카테고리 예산:`, newCategoryBudgets);
// 카테고리 예산이 제공된 경우 업데이트
if (newCategoryBudgets) {
@@ -48,7 +48,7 @@ export const useExtendedBudgetUpdate = (
// 총액 계산 (0 확인)
const totalAmount = Object.values(updatedCategoryBudgets).reduce((sum, val) => sum + val, 0);
console.log('카테고리 총액:', totalAmount);
console.log('카테고리 예산 총합:', totalAmount, updatedCategoryBudgets);
if (totalAmount <= 0) {
toast({
@@ -71,19 +71,39 @@ export const useExtendedBudgetUpdate = (
description: `월간 총 예산이 ${totalAmount.toLocaleString()}원으로 설정되었습니다.`
});
// 여러 번의 이벤트 발생으로 UI 업데이트 보장 (타이밍 문제 해결)
// 다중 이벤트 발생으로 UI 업데이트 보장
// 0.5초 후 1차 업데이트
setTimeout(() => {
console.log("예산 UI 업데이트 이벤트 발생 (1차)");
window.dispatchEvent(new Event('budgetDataUpdated'));
}, 300);
}, 500);
// 1.5초 후 2차 업데이트
setTimeout(() => {
console.log("예산 UI 업데이트 이벤트 발생 (2차)");
window.dispatchEvent(new Event('budgetDataUpdated'));
// 스토리지 이벤트도 발생시켜 데이터 로드 보장
window.dispatchEvent(new StorageEvent('storage', {
key: 'budgetData',
newValue: localStorage.getItem('budgetData')
}));
}, 1000);
const savedData = localStorage.getItem('budgetData');
if (savedData) {
window.dispatchEvent(new StorageEvent('storage', {
key: 'budgetData',
newValue: savedData
}));
}
}, 1500);
// 3초 후 3차 업데이트 (최종 보장)
setTimeout(() => {
console.log("예산 UI 업데이트 이벤트 발생 (3차/최종)");
window.dispatchEvent(new Event('budgetDataUpdated'));
const savedData = localStorage.getItem('budgetData');
if (savedData) {
window.dispatchEvent(new StorageEvent('storage', {
key: 'budgetData',
newValue: savedData
}));
}
}, 3000);
} catch (error) {
console.error('카테고리 예산 업데이트 오류:', error);
toast({
@@ -132,19 +152,38 @@ export const useExtendedBudgetUpdate = (
description: `${periodText} 예산이 ${amount.toLocaleString()}원으로 설정되었습니다.`
});
// 데이터 표시 강제 갱신 (타이밍 문제 해결을 위한 여러 이벤트 발생)
// 다중 이벤트 발생
// 0.5초 후 1차 업데이트
setTimeout(() => {
console.log("예산 UI 업데이트 이벤트 발생 (1차)");
window.dispatchEvent(new Event('budgetDataUpdated'));
}, 300);
}, 500);
// 1.5초 후 2차 업데이트
setTimeout(() => {
console.log("예산 UI 업데이트 이벤트 발생 (2차)");
window.dispatchEvent(new Event('budgetDataUpdated'));
// 스토리지 이벤트도 발생시켜 데이터 로드 보장
window.dispatchEvent(new StorageEvent('storage', {
key: 'budgetData',
newValue: localStorage.getItem('budgetData')
}));
}, 1000);
const savedData = localStorage.getItem('budgetData');
if (savedData) {
window.dispatchEvent(new StorageEvent('storage', {
key: 'budgetData',
newValue: savedData
}));
}
}, 1500);
// 3초 후 3차 업데이트 (최종 보장)
setTimeout(() => {
console.log("예산 UI 업데이트 이벤트 발생 (3차/최종)");
window.dispatchEvent(new Event('budgetDataUpdated'));
const savedData = localStorage.getItem('budgetData');
if (savedData) {
window.dispatchEvent(new StorageEvent('storage', {
key: 'budgetData',
newValue: savedData
}));
}
}, 3000);
}
}, [categoryBudgets, handleBudgetGoalUpdate, updateCategoryBudgets]);