70 lines
2.0 KiB
TypeScript
70 lines
2.0 KiB
TypeScript
|
|
import { MutableRefObject } from 'react';
|
|
import { Transaction } from '@/components/TransactionCard';
|
|
import { saveTransactionsToStorage } from '../../storageUtils';
|
|
import { deleteTransactionFromSupabase } from '../../supabaseUtils';
|
|
import { toast } from '@/hooks/useToast.wrapper';
|
|
|
|
/**
|
|
* 스토리지 및 Supabase 삭제 처리 - 간소화 및 안정성 개선
|
|
*/
|
|
export const handleDeleteStorage = (
|
|
updatedTransactions: Transaction[],
|
|
id: string,
|
|
user: any,
|
|
pendingDeletionRef: MutableRefObject<Set<string>>
|
|
) => {
|
|
try {
|
|
// 로컬 스토리지 업데이트
|
|
saveTransactionsToStorage(updatedTransactions);
|
|
console.log('로컬 스토리지 저장 완료');
|
|
|
|
// Supabase 업데이트 (비동기 처리)
|
|
if (user) {
|
|
// 네트워크 작업은 비동기로 진행
|
|
setTimeout(() => {
|
|
try {
|
|
deleteTransactionFromSupabase(user, id)
|
|
.catch(error => {
|
|
console.error('Supabase 삭제 오류:', error);
|
|
})
|
|
.finally(() => {
|
|
// 작업 완료 표시
|
|
if (pendingDeletionRef.current) {
|
|
pendingDeletionRef.current.delete(id);
|
|
}
|
|
});
|
|
} catch (e) {
|
|
console.error('Supabase 작업 오류:', e);
|
|
// 작업 완료 표시
|
|
if (pendingDeletionRef.current) {
|
|
pendingDeletionRef.current.delete(id);
|
|
}
|
|
}
|
|
}, 10);
|
|
} else {
|
|
// 작업 완료 표시
|
|
if (pendingDeletionRef.current) {
|
|
pendingDeletionRef.current.delete(id);
|
|
}
|
|
}
|
|
|
|
// 이벤트 발생
|
|
setTimeout(() => {
|
|
try {
|
|
window.dispatchEvent(new Event('transactionDeleted'));
|
|
} catch (e) {
|
|
console.error('이벤트 발생 오류:', e);
|
|
}
|
|
}, 100);
|
|
|
|
} catch (storageError) {
|
|
console.error('스토리지 작업 중 오류:', storageError);
|
|
|
|
// 작업 완료 표시
|
|
if (pendingDeletionRef.current) {
|
|
pendingDeletionRef.current.delete(id);
|
|
}
|
|
}
|
|
};
|