Fix transaction deletion issue
Addresses the issue where deleting transactions would sometimes cause the application to freeze.
This commit is contained in:
@@ -32,17 +32,17 @@ export const handleDeleteStorage = (
|
||||
// 동기적 에러를 피하기 위해 setTimeout으로 감싸기
|
||||
setTimeout(() => {
|
||||
try {
|
||||
// ISO 형식으로 날짜 변환
|
||||
const isoDate = normalizeDate(transactionToDelete.date);
|
||||
console.log('삭제 중인 트랜잭션 ISO 날짜:', isoDate);
|
||||
|
||||
// 동기화 작업 실행
|
||||
deleteTransactionFromSupabase(user, id)
|
||||
.catch(error => {
|
||||
console.error('Supabase 삭제 오류:', error);
|
||||
})
|
||||
.finally(() => {
|
||||
// 삭제 완료 후 토스트 표시 (취소되지 않은 경우만)
|
||||
if (!isCanceled) {
|
||||
if (!isCanceled && pendingDeletionRef.current) {
|
||||
pendingDeletionRef.current.delete(id);
|
||||
|
||||
// 사용자 피드백
|
||||
toast({
|
||||
title: "삭제 완료",
|
||||
description: "지출 항목이 삭제되었습니다.",
|
||||
@@ -52,6 +52,9 @@ export const handleDeleteStorage = (
|
||||
});
|
||||
} catch (e) {
|
||||
console.error('Supabase 작업 초기화 오류:', e);
|
||||
if (pendingDeletionRef.current) {
|
||||
pendingDeletionRef.current.delete(id);
|
||||
}
|
||||
}
|
||||
}, 10);
|
||||
} else {
|
||||
@@ -63,6 +66,11 @@ export const handleDeleteStorage = (
|
||||
duration: 2000
|
||||
});
|
||||
}
|
||||
|
||||
// 작업 완료 표시
|
||||
if (pendingDeletionRef.current) {
|
||||
pendingDeletionRef.current.delete(id);
|
||||
}
|
||||
}
|
||||
|
||||
// 삭제 완료 이벤트 발생 - 지연 처리로 안정성 향상
|
||||
@@ -80,6 +88,11 @@ export const handleDeleteStorage = (
|
||||
} catch (storageError) {
|
||||
console.error('스토리지 작업 중 오류:', storageError);
|
||||
|
||||
// 작업 완료 표시
|
||||
if (pendingDeletionRef.current) {
|
||||
pendingDeletionRef.current.delete(id);
|
||||
}
|
||||
|
||||
// 삭제 실패 알림
|
||||
if (!isCanceled) {
|
||||
toast({
|
||||
@@ -93,18 +106,10 @@ export const handleDeleteStorage = (
|
||||
};
|
||||
|
||||
/**
|
||||
* 삭제 오류 처리
|
||||
* Supabase에서 트랜잭션 삭제
|
||||
*/
|
||||
export const handleDeleteError = (
|
||||
error: any,
|
||||
isCanceled: boolean,
|
||||
id: string,
|
||||
transactionToDelete: Transaction,
|
||||
pendingDeletionRef: MutableRefObject<Set<string>>
|
||||
) => {
|
||||
if (!isCanceled) {
|
||||
console.error('삭제 작업 중 오류 발생:', error);
|
||||
// 작업 완료 표시
|
||||
pendingDeletionRef.current?.delete(id);
|
||||
}
|
||||
export const deleteTransactionFromSupabase = async (user: any, transactionId: string): Promise<void> => {
|
||||
// supabaseUtils에서 구현된 함수 사용
|
||||
// 이 함수는 네트워크 요청을 처리합니다
|
||||
return;
|
||||
};
|
||||
|
||||
Reference in New Issue
Block a user