Fix transaction deletion issue

Addresses the issue where the transaction history page becomes unresponsive after deleting a transaction.
This commit is contained in:
gpt-engineer-app[bot]
2025-03-17 23:37:06 +00:00
parent d48b866b3a
commit 783dd9ce99
6 changed files with 121 additions and 92 deletions

View File

@@ -2,58 +2,58 @@
import { useEffect } from 'react';
/**
* 트랜잭션 이벤트 관련
* 각종 이벤트 리스너를 설정합니다.
* 트랜잭션 이벤트 리스너
* 트랜잭션 업데이트 이벤트 리스합니다.
*/
export const useTransactionsEvents = (
loadTransactions: () => void,
refreshKey: number
) => {
// 이벤트 리스너 설정
useEffect(() => {
console.log('useTransactions - 이벤트 리스너 설정');
// 트랜잭션 업데이트 이벤트 리스너
const handleTransactionUpdated = () => {
console.log('트랜잭션 업데이트 이벤트 감지됨');
// 트랜잭션 업데이트 이벤트
const handleTransactionUpdate = (e?: any) => {
console.log('트랜잭션 업데이트 이벤트 감지:', e);
loadTransactions();
};
// 스토리지 변경 이벤트 리스너
const handleStorageChange = (e: StorageEvent) => {
// 트랜잭션 삭제 이벤트
const handleTransactionDelete = () => {
console.log('트랜잭션 삭제 이벤트 감지됨');
loadTransactions();
};
// 스토리지 이벤트
const handleStorageEvent = (e: StorageEvent) => {
if (e.key === 'transactions' || e.key === null) {
console.log('로컬 스토리지 변경 감지:', e.key);
console.log('스토리지 이벤트 감지:', e.key);
loadTransactions();
}
};
// 페이지 포커스/가시성 이벤트 리스너
// 포커스 이벤트
const handleFocus = () => {
console.log('창 포커스 - 트랜잭션 새로고침');
console.log('창 포커스: 트랜잭션 새로고침');
loadTransactions();
};
const handleVisibilityChange = () => {
if (document.visibilityState === 'visible') {
console.log('페이지 가시성 변경 - 트랜잭션 새로고침');
loadTransactions();
}
};
// 이벤트 리스너 등록
window.addEventListener('transactionUpdated', handleTransactionUpdated);
window.addEventListener('storage', handleStorageChange);
window.addEventListener('transactionUpdated', handleTransactionUpdate);
window.addEventListener('transactionDeleted', handleTransactionDelete);
window.addEventListener('storage', handleStorageEvent);
window.addEventListener('focus', handleFocus);
document.addEventListener('visibilitychange', handleVisibilityChange);
// 컴포넌트 마운트시에만 수동으로 트랜잭션 업데이트 이벤트 발생
window.dispatchEvent(new Event('transactionUpdated'));
// 새로고침 키가 변경되면 데이터 로드
loadTransactions();
// 클린업 함수
return () => {
window.removeEventListener('transactionUpdated', handleTransactionUpdated);
window.removeEventListener('storage', handleStorageChange);
console.log('useTransactions - 이벤트 리스너 제거');
window.removeEventListener('transactionUpdated', handleTransactionUpdate);
window.removeEventListener('transactionDeleted', handleTransactionDelete);
window.removeEventListener('storage', handleStorageEvent);
window.removeEventListener('focus', handleFocus);
document.removeEventListener('visibilitychange', handleVisibilityChange);
};
}, [loadTransactions, refreshKey]);
};