Fix toast and sync settings

- Fix issue where toast notifications were not disappearing.
- Ensure sync settings are turned off upon logout.
This commit is contained in:
gpt-engineer-app[bot]
2025-03-16 10:37:26 +00:00
parent dab1a9cb84
commit 14c3fac824
6 changed files with 63 additions and 13 deletions

View File

@@ -1,3 +1,3 @@
export const TOAST_LIMIT = 5 // 최대 5개로 제한
export const TOAST_REMOVE_DELAY = 5000 // 5초 후 DOM에서 제거
export const TOAST_REMOVE_DELAY = 3000 // 3초 후 DOM에서 제거 (5초에서 3초로 변경)

View File

@@ -27,7 +27,7 @@ function toast({ ...props }: Toast) {
onOpenChange: (open) => {
if (!open) dismiss()
},
duration: props.duration || 3000, // 기본 지속 시간 3초로 단축
duration: props.duration || 3000, // 기본 지속 시간 3초로 설정
},
})

View File

@@ -9,7 +9,9 @@ export const toastTimeouts = new Map<string, ReturnType<typeof setTimeout>>()
// 토스트 자동 제거 함수
export const addToRemoveQueue = (toastId: string) => {
if (toastTimeouts.has(toastId)) {
return
// 이미 존재하는 타이머가 있다면 제거 후 새로 설정
clearTimeout(toastTimeouts.get(toastId)!);
toastTimeouts.delete(toastId);
}
const timeout = setTimeout(() => {
@@ -26,6 +28,10 @@ export const addToRemoveQueue = (toastId: string) => {
export const reducer = (state: State, action: Action): State => {
switch (action.type) {
case actionTypes.ADD_TOAST:
// 토스트 추가 시 자동 제거 타이머 설정
if (action.toast.id) {
addToRemoveQueue(action.toast.id);
}
return {
...state,
toasts: [action.toast, ...state.toasts].slice(0, TOAST_LIMIT),

View File

@@ -47,11 +47,26 @@ export function dispatch(action: Action) {
time: now
};
// REMOVE_TOAST 액션 우선순위 높임
if (action.type === actionTypes.REMOVE_TOAST) {
// 즉시 처리
memoryState = reducer(memoryState, action);
listeners.forEach((listener) => {
listener(memoryState);
});
return;
}
// 실제 상태 업데이트 및 리스너 호출
memoryState = reducer(memoryState, action)
memoryState = reducer(memoryState, action);
listeners.forEach((listener) => {
listener(memoryState)
})
listener(memoryState);
});
}
// 토스트 모두 제거 헬퍼 함수
export function clearAllToasts() {
dispatch({ type: actionTypes.REMOVE_TOAST });
}
export { memoryState };