Refactor project for improvements
This commit refactors the project to improve overall code quality, performance, and maintainability. Specific changes may include code cleanup, optimization, and architectural enhancements.
This commit is contained in:
@@ -28,28 +28,34 @@ const TransactionDeleteAlert: React.FC<TransactionDeleteAlertProps> = ({ onDelet
|
||||
|
||||
setIsDeleting(true);
|
||||
|
||||
// 비동기 실행 후 1초 내에 강제 닫힘 (UI 응답성 유지)
|
||||
const deletePromise = onDelete();
|
||||
// 삭제 작업 시작 즉시 다이얼로그 닫기 (UI 응답성 향상)
|
||||
setIsOpen(false);
|
||||
|
||||
// Promise 또는 boolean 값을 처리 (onDelete가 Promise가 아닐 수도 있음)
|
||||
if (deletePromise instanceof Promise) {
|
||||
await deletePromise;
|
||||
}
|
||||
|
||||
// 삭제 작업 완료 후 다이얼로그 닫기 (애니메이션 효과 위해 지연)
|
||||
setTimeout(() => {
|
||||
setIsOpen(false);
|
||||
setTimeout(() => setIsDeleting(false), 300); // 추가 안전장치
|
||||
}, 300);
|
||||
// 짧은 딜레이 추가 (UI 애니메이션 완료를 위해)
|
||||
setTimeout(async () => {
|
||||
try {
|
||||
// 삭제 함수 실행
|
||||
const result = await onDelete();
|
||||
console.log('삭제 결과:', result);
|
||||
} catch (error) {
|
||||
console.error('삭제 처리 오류:', error);
|
||||
} finally {
|
||||
// 상태 정리 (약간 지연)
|
||||
setTimeout(() => {
|
||||
setIsDeleting(false);
|
||||
}, 100);
|
||||
}
|
||||
}, 150);
|
||||
} catch (error) {
|
||||
console.error('삭제 작업 처리 중 오류:', error);
|
||||
console.error('삭제 핸들러 오류:', error);
|
||||
setIsDeleting(false);
|
||||
setIsOpen(false);
|
||||
}
|
||||
};
|
||||
|
||||
return (
|
||||
<AlertDialog open={isOpen} onOpenChange={(open) => {
|
||||
// 삭제 중에는 닫기 방지
|
||||
// 삭제 중에는 상태 변경 방지
|
||||
if (isDeleting && !open) return;
|
||||
setIsOpen(open);
|
||||
}}>
|
||||
@@ -80,7 +86,7 @@ const TransactionDeleteAlert: React.FC<TransactionDeleteAlertProps> = ({ onDelet
|
||||
{isDeleting ? (
|
||||
<>
|
||||
<Loader2 size={16} className="mr-1 animate-spin" />
|
||||
삭제 중...
|
||||
처리 중...
|
||||
</>
|
||||
) : (
|
||||
<>
|
||||
|
||||
@@ -13,12 +13,14 @@ const TransactionDateGroup: React.FC<TransactionDateGroupProps> = ({
|
||||
transactions,
|
||||
onTransactionDelete
|
||||
}) => {
|
||||
// onTransactionDelete 함수를 래핑하여 Promise<boolean>을 반환하도록 보장
|
||||
// 안정적인 삭제 핸들러
|
||||
const handleDelete = async (id: string): Promise<boolean> => {
|
||||
try {
|
||||
return await onTransactionDelete(id);
|
||||
// 적절한 타입 변환 처리
|
||||
const result = await Promise.resolve(onTransactionDelete(id));
|
||||
return !!result;
|
||||
} catch (error) {
|
||||
console.error('트랜잭션 삭제 처리 중 오류:', error);
|
||||
console.error('삭제 처리 중 오류:', error);
|
||||
return false;
|
||||
}
|
||||
};
|
||||
|
||||
Reference in New Issue
Block a user