Fix transaction deletion issue
Addresses an issue where the application becomes unresponsive after deleting a transaction.
This commit is contained in:
@@ -24,30 +24,49 @@ export const handleDeleteStorage = (
|
||||
|
||||
// 로컬 스토리지 업데이트
|
||||
saveTransactionsToStorage(updatedTransactions);
|
||||
console.log('로컬 스토리지 저장 완료');
|
||||
|
||||
// Supabase 업데이트
|
||||
// Supabase 업데이트 (비동기 처리)
|
||||
if (user) {
|
||||
deleteTransactionFromSupabase(user, id)
|
||||
.catch(error => {
|
||||
console.error('Supabase 삭제 오류:', error);
|
||||
// 오류 시에도 UI에는 영향이 없도록 함 (이미 로컬에서는 제거됨)
|
||||
})
|
||||
.finally(() => {
|
||||
// 삭제 완료 후 토스트 표시
|
||||
if (!isCanceled) {
|
||||
toast({
|
||||
title: "삭제 완료",
|
||||
description: "지출 항목이 삭제되었습니다.",
|
||||
duration: 2000
|
||||
// 동기적 에러를 피하기 위해 setTimeout으로 감싸기
|
||||
setTimeout(() => {
|
||||
try {
|
||||
deleteTransactionFromSupabase(user, id)
|
||||
.catch(error => {
|
||||
console.error('Supabase 삭제 오류:', error);
|
||||
})
|
||||
.finally(() => {
|
||||
// 삭제 완료 후 토스트 표시 (취소되지 않은 경우만)
|
||||
if (!isCanceled) {
|
||||
toast({
|
||||
title: "삭제 완료",
|
||||
description: "지출 항목이 삭제되었습니다.",
|
||||
duration: 2000
|
||||
});
|
||||
}
|
||||
});
|
||||
}
|
||||
} catch (e) {
|
||||
console.error('Supabase 작업 초기화 오류:', e);
|
||||
}
|
||||
}, 10);
|
||||
} else {
|
||||
// 사용자가 없는 경우 토스트 표시
|
||||
if (!isCanceled) {
|
||||
toast({
|
||||
title: "삭제 완료",
|
||||
description: "지출 항목이 삭제되었습니다.",
|
||||
duration: 2000
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
// 삭제 완료 이벤트 발생
|
||||
// 삭제 완료 이벤트 발생 - 지연 처리로 안정성 향상
|
||||
setTimeout(() => {
|
||||
try {
|
||||
window.dispatchEvent(new Event('transactionDeleted'));
|
||||
if (!isCanceled) {
|
||||
console.log('트랜잭션 삭제 완료 이벤트 발생');
|
||||
window.dispatchEvent(new Event('transactionDeleted'));
|
||||
}
|
||||
} catch (e) {
|
||||
console.error('이벤트 발생 오류:', e);
|
||||
}
|
||||
@@ -57,12 +76,14 @@ export const handleDeleteStorage = (
|
||||
console.error('스토리지 작업 중 오류:', storageError);
|
||||
|
||||
// 삭제 실패 알림
|
||||
toast({
|
||||
title: "삭제 중 오류",
|
||||
description: "지출 항목 삭제 중 문제가 발생했습니다.",
|
||||
variant: "destructive",
|
||||
duration: 2000
|
||||
});
|
||||
if (!isCanceled) {
|
||||
toast({
|
||||
title: "삭제 중 오류",
|
||||
description: "지출 항목 삭제 중 문제가 발생했습니다.",
|
||||
variant: "destructive",
|
||||
duration: 2000
|
||||
});
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
|
||||
Reference in New Issue
Block a user