Fix transaction deletion issue

Addresses an issue where the application becomes unresponsive after deleting a transaction.
This commit is contained in:
gpt-engineer-app[bot]
2025-03-17 23:41:03 +00:00
parent 196c071b53
commit ce12e99f6d
4 changed files with 116 additions and 39 deletions

View File

@@ -12,30 +12,65 @@ export const useTransactionsEvents = (
useEffect(() => {
console.log('useTransactions - 이벤트 리스너 설정');
// 바운싱 방지 변수
let isProcessing = false;
// 트랜잭션 업데이트 이벤트
const handleTransactionUpdate = (e?: any) => {
console.log('트랜잭션 업데이트 이벤트 감지:', e);
loadTransactions();
// 처리 중 중복 호출 방지
if (isProcessing) return;
isProcessing = true;
setTimeout(() => {
loadTransactions();
isProcessing = false;
}, 150);
};
// 트랜잭션 삭제 이벤트
const handleTransactionDelete = () => {
console.log('트랜잭션 삭제 이벤트 감지됨');
loadTransactions();
// 처리 중 중복 호출 방지
if (isProcessing) return;
isProcessing = true;
setTimeout(() => {
loadTransactions();
isProcessing = false;
}, 200);
};
// 스토리지 이벤트
const handleStorageEvent = (e: StorageEvent) => {
if (e.key === 'transactions' || e.key === null) {
console.log('스토리지 이벤트 감지:', e.key);
loadTransactions();
// 처리 중 중복 호출 방지
if (isProcessing) return;
isProcessing = true;
setTimeout(() => {
loadTransactions();
isProcessing = false;
}, 150);
}
};
// 포커스 이벤트
const handleFocus = () => {
console.log('창 포커스: 트랜잭션 새로고침');
loadTransactions();
// 처리 중 중복 호출 방지
if (isProcessing) return;
isProcessing = true;
setTimeout(() => {
loadTransactions();
isProcessing = false;
}, 200);
};
// 이벤트 리스너 등록
@@ -45,7 +80,9 @@ export const useTransactionsEvents = (
window.addEventListener('focus', handleFocus);
// 새로고침 키가 변경되면 데이터 로드
loadTransactions();
if (!isProcessing) {
loadTransactions();
}
// 클린업 함수
return () => {