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:
gpt-engineer-app[bot]
2025-03-18 07:45:06 +00:00
parent 854d27574f
commit 8e609519ac
4 changed files with 109 additions and 104 deletions

View File

@@ -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" />
...
...
</>
) : (
<>

View File

@@ -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;
}
};