Fix transaction deletion issue
Addresses the issue where deleting a transaction in the transaction history would cause the application to freeze.
This commit is contained in:
@@ -25,7 +25,6 @@ const Transactions = () => {
|
||||
const { budgetData } = useBudget();
|
||||
const [isDataLoaded, setIsDataLoaded] = useState(false);
|
||||
const [isProcessing, setIsProcessing] = useState(false);
|
||||
// 트랜잭션 삭제 중인 ID 추적
|
||||
const [deletingId, setDeletingId] = useState<string | null>(null);
|
||||
|
||||
// 데이터 로드 상태 관리
|
||||
@@ -35,10 +34,10 @@ const Transactions = () => {
|
||||
}
|
||||
}, [budgetData, isLoading]);
|
||||
|
||||
// 트랜잭션 삭제 핸들러 (안정성 개선)
|
||||
// 트랜잭션 삭제 핸들러 (성능 및 안정성 개선)
|
||||
const handleTransactionDelete = async (id: string) => {
|
||||
// 이미 처리 중인 삭제 작업이 있다면 취소
|
||||
if (isProcessing || deletingId) {
|
||||
// 이미 처리 중인 경우 작업 무시
|
||||
if (isProcessing || deletingId === id) {
|
||||
console.log('이미 삭제 작업이 진행 중입니다:', deletingId);
|
||||
return;
|
||||
}
|
||||
@@ -50,22 +49,19 @@ const Transactions = () => {
|
||||
setIsProcessing(true);
|
||||
setDeletingId(id);
|
||||
|
||||
// 트랜잭션 삭제 수행
|
||||
// 비동기 삭제 작업 실행
|
||||
const success = await deleteTransaction(id);
|
||||
|
||||
// 일정 시간 후 처리 상태 해제 (UI 응답성 향상)
|
||||
// 데이터 새로고침 (UI 응답성 향상을 위해 약간 지연)
|
||||
setTimeout(() => {
|
||||
refreshTransactions();
|
||||
|
||||
// 상태 초기화
|
||||
setIsProcessing(false);
|
||||
setDeletingId(null);
|
||||
|
||||
// 삭제 성공 시 데이터 새로고침
|
||||
if (success) {
|
||||
console.log('삭제 성공, 데이터 새로고침');
|
||||
setTimeout(() => {
|
||||
refreshTransactions();
|
||||
}, 300);
|
||||
}
|
||||
}, 800);
|
||||
}, 300);
|
||||
|
||||
return success;
|
||||
} catch (error) {
|
||||
console.error('트랜잭션 삭제 처리 중 오류:', error);
|
||||
|
||||
@@ -73,10 +69,12 @@ const Transactions = () => {
|
||||
setIsProcessing(false);
|
||||
setDeletingId(null);
|
||||
|
||||
// 오류 후에도 데이터 새로고침 (안정성 향상)
|
||||
// 오류 후에도 데이터 새로고침 (일관성 유지)
|
||||
setTimeout(() => {
|
||||
refreshTransactions();
|
||||
}, 500);
|
||||
|
||||
return false;
|
||||
}
|
||||
};
|
||||
|
||||
|
||||
Reference in New Issue
Block a user