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

@@ -16,23 +16,32 @@ export const useTransactionState = () => {
useEffect(() => {
const loadTransactions = () => {
const storedTransactions = loadTransactionsFromStorage();
console.log('트랜잭션 로드됨:', storedTransactions.length, '개');
setTransactions(storedTransactions);
};
loadTransactions();
// 이벤트 리스너를 추가하여 다른 컴포넌트에서 변경 시 업데이트
const handleTransactionUpdate = () => loadTransactions();
const handleTransactionUpdate = () => {
console.log('트랜잭션 업데이트 이벤트 감지');
loadTransactions();
};
window.addEventListener('transactionUpdated', handleTransactionUpdate);
window.addEventListener('transactionDeleted', handleTransactionUpdate);
window.addEventListener('transactionAdded', handleTransactionUpdate);
window.addEventListener('storage', handleTransactionUpdate);
// 페이지 포커스 시 데이터 갱신
window.addEventListener('focus', handleTransactionUpdate);
return () => {
window.removeEventListener('transactionUpdated', handleTransactionUpdate);
window.removeEventListener('transactionDeleted', handleTransactionUpdate);
window.removeEventListener('transactionAdded', handleTransactionUpdate);
window.removeEventListener('storage', handleTransactionUpdate);
window.removeEventListener('focus', handleTransactionUpdate);
};
}, []);