Review expense history page
This commit is contained in:
@@ -4,82 +4,55 @@ import { Transaction } from '@/components/TransactionCard';
|
||||
import { saveTransactionsToStorage } from '../../storageUtils';
|
||||
import { deleteTransactionFromSupabase } from '../../supabaseUtils';
|
||||
import { toast } from '@/hooks/useToast.wrapper';
|
||||
import { normalizeDate } from '@/utils/sync/transaction/dateUtils';
|
||||
|
||||
/**
|
||||
* 스토리지 및 Supabase 삭제 처리
|
||||
* 스토리지 및 Supabase 삭제 처리 - 간소화 및 안정성 개선
|
||||
*/
|
||||
export const handleDeleteStorage = (
|
||||
isCanceled: boolean,
|
||||
updatedTransactions: Transaction[],
|
||||
id: string,
|
||||
user: any,
|
||||
transactionToDelete: Transaction,
|
||||
pendingDeletionRef: MutableRefObject<Set<string>>
|
||||
) => {
|
||||
try {
|
||||
if (isCanceled) {
|
||||
console.log('백그라운드 작업이 취소되었습니다.');
|
||||
return;
|
||||
}
|
||||
|
||||
// 로컬 스토리지 업데이트
|
||||
saveTransactionsToStorage(updatedTransactions);
|
||||
console.log('로컬 스토리지 저장 완료');
|
||||
|
||||
// Supabase 업데이트 (비동기 처리)
|
||||
if (user) {
|
||||
// 동기적 에러를 피하기 위해 setTimeout으로 감싸기
|
||||
// 네트워크 작업은 비동기로 진행
|
||||
setTimeout(() => {
|
||||
try {
|
||||
// 동기화 작업 실행
|
||||
deleteTransactionFromSupabase(user, id)
|
||||
.catch(error => {
|
||||
console.error('Supabase 삭제 오류:', error);
|
||||
})
|
||||
.finally(() => {
|
||||
// 삭제 완료 후 토스트 표시 (취소되지 않은 경우만)
|
||||
if (!isCanceled && pendingDeletionRef.current) {
|
||||
// 작업 완료 표시
|
||||
if (pendingDeletionRef.current) {
|
||||
pendingDeletionRef.current.delete(id);
|
||||
|
||||
// 사용자 피드백
|
||||
toast({
|
||||
title: "삭제 완료",
|
||||
description: "지출 항목이 삭제되었습니다.",
|
||||
duration: 2000
|
||||
});
|
||||
}
|
||||
});
|
||||
} catch (e) {
|
||||
console.error('Supabase 작업 초기화 오류:', e);
|
||||
console.error('Supabase 작업 오류:', e);
|
||||
// 작업 완료 표시
|
||||
if (pendingDeletionRef.current) {
|
||||
pendingDeletionRef.current.delete(id);
|
||||
}
|
||||
}
|
||||
}, 10);
|
||||
} else {
|
||||
// 사용자가 없는 경우 토스트 표시
|
||||
if (!isCanceled) {
|
||||
toast({
|
||||
title: "삭제 완료",
|
||||
description: "지출 항목이 삭제되었습니다.",
|
||||
duration: 2000
|
||||
});
|
||||
}
|
||||
|
||||
// 작업 완료 표시
|
||||
if (pendingDeletionRef.current) {
|
||||
pendingDeletionRef.current.delete(id);
|
||||
}
|
||||
}
|
||||
|
||||
// 삭제 완료 이벤트 발생 - 지연 처리로 안정성 향상
|
||||
// 이벤트 발생
|
||||
setTimeout(() => {
|
||||
try {
|
||||
if (!isCanceled) {
|
||||
console.log('트랜잭션 삭제 완료 이벤트 발생');
|
||||
window.dispatchEvent(new Event('transactionDeleted'));
|
||||
}
|
||||
window.dispatchEvent(new Event('transactionDeleted'));
|
||||
} catch (e) {
|
||||
console.error('이벤트 발생 오류:', e);
|
||||
}
|
||||
@@ -92,17 +65,5 @@ export const handleDeleteStorage = (
|
||||
if (pendingDeletionRef.current) {
|
||||
pendingDeletionRef.current.delete(id);
|
||||
}
|
||||
|
||||
// 삭제 실패 알림
|
||||
if (!isCanceled) {
|
||||
toast({
|
||||
title: "삭제 중 오류",
|
||||
description: "지출 항목 삭제 중 문제가 발생했습니다.",
|
||||
variant: "destructive",
|
||||
duration: 2000
|
||||
});
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
// 중복 정의된 함수 제거 - 이미 import로 가져오고 있으므로 여기서 중복 선언할 필요가 없습니다.
|
||||
|
||||
Reference in New Issue
Block a user