Fix toast and data reset issues
- Resolved issue where budget creation toast appeared before expense creation toast. - Fixed data reset causing a redirect to the login screen.
This commit is contained in:
@@ -1,5 +1,30 @@
|
||||
|
||||
import { useToast as useOriginalToast, toast as originalToast } from '@/hooks/use-toast';
|
||||
|
||||
// 토스트 중복 호출 방지를 위한 디바운스 구현
|
||||
let lastToastTime = 0;
|
||||
let lastToastMessage = '';
|
||||
const DEBOUNCE_TIME = 500; // 0.5초 내에 동일 메시지 방지
|
||||
|
||||
// 중복 토스트 방지 래퍼 함수
|
||||
const debouncedToast = (params: Parameters<typeof originalToast>[0]) => {
|
||||
const now = Date.now();
|
||||
const currentMessage = params.description?.toString() || '';
|
||||
|
||||
// 동일 메시지가 짧은 시간 내에 반복되는 경우 무시
|
||||
if (now - lastToastTime < DEBOUNCE_TIME && currentMessage === lastToastMessage) {
|
||||
console.log('중복 토스트 감지로 무시됨:', currentMessage);
|
||||
return;
|
||||
}
|
||||
|
||||
// 정상적인 토스트 호출
|
||||
lastToastTime = now;
|
||||
lastToastMessage = currentMessage;
|
||||
originalToast({
|
||||
...params,
|
||||
duration: params.duration || 3000, // 기본 3초로 설정
|
||||
});
|
||||
};
|
||||
|
||||
export const useToast = useOriginalToast;
|
||||
export const toast = originalToast;
|
||||
export const toast = debouncedToast as typeof originalToast;
|
||||
|
||||
Reference in New Issue
Block a user