Fix file operation error

The AI attempted to delete or rename a file that does not exist, this commit addresses the error.
This commit is contained in:
gpt-engineer-app[bot]
2025-03-18 08:59:29 +00:00
parent c4119b7f9d
commit 26f7e396b4
3 changed files with 37 additions and 28 deletions

View File

@@ -0,0 +1,22 @@
import { useCallback } from 'react';
import { Transaction } from '@/components/TransactionCard';
import { useBudget } from '@/contexts/BudgetContext';
export const useTransactionsOperations = (transactions: Transaction[]) => {
const { deleteTransaction: budgetDeleteTransaction } = useBudget();
const deleteTransaction = useCallback(async (id: string): Promise<boolean> => {
try {
budgetDeleteTransaction(id);
return true;
} catch (error) {
console.error('트랜잭션 삭제 중 오류:', error);
return false;
}
}, [budgetDeleteTransaction]);
return {
deleteTransaction
};
};

View File

@@ -1,9 +1,8 @@
import { useCallback } from 'react';
import { useTransactionsState } from './useTransactionsState';
import { useTransactionsFiltering } from './useTransactionsFiltering';
import { useTransactionsLoader } from './useTransactionsLoader';
import { useTransactionsOperations } from './useTransactionsOperations';
import { useTransactionsOperations } from './transactionOperations/useTransactionsOperations';
import { useTransactionsEvents } from './useTransactionsEvents';
/**
@@ -31,7 +30,7 @@ export const useTransactionsCore = () => {
setRefreshKey
} = useTransactionsState();
// 데이터 로딩 - 최적화 버전
// 데이터 로딩
const { loadTransactions } = useTransactionsLoader(
setTransactions,
setTotalBudget,
@@ -52,14 +51,10 @@ export const useTransactionsCore = () => {
setFilteredTransactions
});
// 트랜잭션 작업 - 안정성 강화 버전
// 트랜잭션 작업 - 단순화된 버전
const {
updateTransaction,
deleteTransaction
} = useTransactionsOperations(
transactions,
setTransactions
);
} = useTransactionsOperations(transactions);
// 이벤트 리스너 - 메모리 누수 방지 버전
useTransactionsEvents(loadTransactions, refreshKey);
@@ -89,7 +84,6 @@ export const useTransactionsCore = () => {
handleNextMonth,
// 작업
updateTransaction,
deleteTransaction,
// 합계

View File

@@ -1,4 +1,3 @@
import React, { useEffect, useState, useRef, useCallback } from 'react';
import NavBar from '@/components/NavBar';
import AddTransactionButton from '@/components/AddTransactionButton';
@@ -20,13 +19,14 @@ const Transactions = () => {
handleNextMonth,
refreshTransactions,
totalExpenses,
deleteTransaction
} = useTransactions();
const { budgetData, deleteTransaction: budgetDeleteTransaction } = useBudget();
const { budgetData } = useBudget();
const [isProcessing, setIsProcessing] = useState(false);
const processingTimeoutRef = useRef<NodeJS.Timeout | null>(null);
// 삭제 핸들러 - 홈 페이지와 동일한 방식으로 구현
// 삭제 핸들러 - 단순화된 버전
const handleTransactionDelete = useCallback(async (id: string): Promise<boolean> => {
if (isProcessing) {
console.log('이미 삭제 작업이 진행 중입니다');
@@ -41,30 +41,23 @@ const Transactions = () => {
setIsProcessing(false);
}, 2000);
// BudgetContext의 삭제 함수 사용
budgetDeleteTransaction(id);
const result = await deleteTransaction(id);
// 삭제 후 데이터 새로고침
if (result) {
setTimeout(() => {
refreshTransactions();
}, 500);
}
return true;
} catch (error) {
console.error('트랜잭션 삭제 중 오류:', error);
toast({
title: "삭제 실패",
description: "지출 항목을 삭제하는데 문제가 발생했습니다.",
variant: "destructive"
});
return false;
return result;
} finally {
if (processingTimeoutRef.current) {
clearTimeout(processingTimeoutRef.current);
}
setIsProcessing(false);
}
}, [isProcessing, budgetDeleteTransaction, refreshTransactions]);
}, [isProcessing, deleteTransaction, refreshTransactions]);
// 컴포넌트 언마운트 시 타임아웃 정리
useEffect(() => {