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

@@ -25,6 +25,8 @@ const Transactions = () => {
const { budgetData } = useBudget();
const [isDataLoaded, setIsDataLoaded] = useState(false);
const [isProcessing, setIsProcessing] = useState(false);
// 트랜잭션 삭제 중인 ID 추적
const [deletingId, setDeletingId] = useState<string | null>(null);
// 데이터 로드 상태 관리
useEffect(() => {
@@ -33,23 +35,32 @@ const Transactions = () => {
}
}, [budgetData, isLoading]);
// 트랜잭션 삭제 핸들러 (오류 수정)
// 트랜잭션 삭제 핸들러 (안정성 개선)
const handleTransactionDelete = async (id: string) => {
// 이미 처리 중인 삭제 작업이 있다면 취소
if (isProcessing || deletingId) {
console.log('이미 삭제 작업이 진행 중입니다:', deletingId);
return;
}
try {
console.log('Transactions 페이지에서 트랜잭션 삭제:', id);
// 삭제 중임을 표시
setIsProcessing(true);
setDeletingId(id);
// 트랜잭션 삭제 수행 (개선된 함수 사용)
// 트랜잭션 삭제 수행
const success = await deleteTransaction(id);
// 일정 시간 후 처리 상태 해제 (UI 응답성 향상)
setTimeout(() => {
setIsProcessing(false);
setDeletingId(null);
// 삭제 성공 시 데이터 새로고침
if (success) {
console.log('삭제 성공, 데이터 새로고침');
setTimeout(() => {
refreshTransactions();
}, 300);
@@ -57,9 +68,12 @@ const Transactions = () => {
}, 800);
} catch (error) {
console.error('트랜잭션 삭제 처리 중 오류:', error);
setIsProcessing(false);
// 삭제 실패 시에도 데이터 새로고침 (안정성 향상)
// 오류 발생 시 상태 초기화
setIsProcessing(false);
setDeletingId(null);
// 오류 후에도 데이터 새로고침 (안정성 향상)
setTimeout(() => {
refreshTransactions();
}, 500);
@@ -69,15 +83,17 @@ const Transactions = () => {
// 페이지 포커스나 가시성 변경 시 데이터 새로고침
useEffect(() => {
const handleVisibilityChange = () => {
if (document.visibilityState === 'visible') {
if (document.visibilityState === 'visible' && !isProcessing) {
console.log('거래내역 페이지 보임 - 데이터 새로고침');
refreshTransactions();
}
};
const handleFocus = () => {
console.log('거래내역 페이지 포커스 - 데이터 새로고침');
refreshTransactions();
if (!isProcessing) {
console.log('거래내역 페이지 포커스 - 데이터 새로고침');
refreshTransactions();
}
};
document.addEventListener('visibilitychange', handleVisibilityChange);
@@ -87,7 +103,7 @@ const Transactions = () => {
document.removeEventListener('visibilitychange', handleVisibilityChange);
window.removeEventListener('focus', handleFocus);
};
}, [refreshTransactions]);
}, [refreshTransactions, isProcessing]);
// 트랜잭션을 날짜별로 그룹화
const groupTransactionsByDate = (transactions: Transaction[]): Record<string, Transaction[]> => {