Fix toast and data display issues

- Fixes an issue where toast notifications would not automatically dismiss.
- Addresses a problem where expense data was not displaying correctly on the transaction and analytics screens.
This commit is contained in:
gpt-engineer-app[bot]
2025-03-16 08:34:58 +00:00
parent 1281156f05
commit fe669b0cfd
6 changed files with 68 additions and 19 deletions

View File

@@ -1,3 +1,4 @@
import * as React from "react"
import type {
@@ -5,8 +6,9 @@ import type {
ToastProps,
} from "@/components/ui/toast"
// 토스트 알림 표시 제한 및 자동 사라짐 시간(ms) 설정
const TOAST_LIMIT = 1
const TOAST_REMOVE_DELAY = 1000000
const TOAST_REMOVE_DELAY = 3000 // 3초 후 자동으로 사라지도록 수정
type ToasterToast = ToastProps & {
id: string

View File

@@ -33,6 +33,7 @@ export const useTransactions = () => {
const [error, setError] = useState<string | null>(null);
const [totalBudget, setTotalBudget] = useState(0);
const { user } = useAuth();
const [refreshKey, setRefreshKey] = useState(0); // 강제 새로고침을 위한 키
// 월 변경 처리
const handlePrevMonth = () => {
@@ -145,7 +146,26 @@ export const useTransactions = () => {
window.removeEventListener('budgetDataUpdated', handleBudgetUpdate);
window.removeEventListener('storage', () => {});
};
}, [user]);
}, [user, refreshKey]);
// 정기적으로 데이터 새로고침
useEffect(() => {
const refreshInterval = setInterval(() => {
loadTransactions();
}, 5000); // 5초마다 데이터 새로고침
// 페이지 포커스 시 새로고침
const handleFocus = () => {
loadTransactions();
};
window.addEventListener('focus', handleFocus);
return () => {
clearInterval(refreshInterval);
window.removeEventListener('focus', handleFocus);
};
}, []);
// 트랜잭션 업데이트
const updateTransaction = (updatedTransaction: Transaction) => {
@@ -181,6 +201,12 @@ export const useTransactions = () => {
});
};
// 데이터 강제 새로고침
const refreshTransactions = () => {
setRefreshKey(prev => prev + 1);
loadTransactions();
};
return {
transactions: filteredTransactions,
isLoading,
@@ -194,6 +220,6 @@ export const useTransactions = () => {
updateTransaction,
deleteTransaction,
totalExpenses: calculateTotalExpenses(filteredTransactions),
refreshTransactions: loadTransactions
refreshTransactions
};
};