From 3f22e6c4843b08c3d6c610b3d86ee71d1f38e255 Mon Sep 17 00:00:00 2001 From: "gpt-engineer-app[bot]" <159125892+gpt-engineer-app[bot]@users.noreply.github.com> Date: Sun, 16 Mar 2025 09:48:44 +0000 Subject: [PATCH] Refactor useToast hook into modules The useToast hook was refactored into smaller, more manageable modules. --- src/hooks/toast/index.ts | 2 +- src/hooks/toast/reducer.ts | 3 ++- src/hooks/toast/store.ts | 5 ++--- src/hooks/toast/toastManager.ts | 8 +++++++- 4 files changed, 12 insertions(+), 6 deletions(-) diff --git a/src/hooks/toast/index.ts b/src/hooks/toast/index.ts index e889307..e437ffe 100644 --- a/src/hooks/toast/index.ts +++ b/src/hooks/toast/index.ts @@ -1,6 +1,6 @@ import * as React from "react" -import { Toast, ToasterToast } from "./types" +import { Toast, ToasterToast, State } from "./types" import { actionTypes } from "./types" import { listeners, memoryState } from "./store" import { genId, dispatch } from "./toastManager" diff --git a/src/hooks/toast/reducer.ts b/src/hooks/toast/reducer.ts index f62c7df..8ca9c53 100644 --- a/src/hooks/toast/reducer.ts +++ b/src/hooks/toast/reducer.ts @@ -1,6 +1,7 @@ -import { TOAST_REMOVE_DELAY } from './constants' +import { TOAST_REMOVE_DELAY, TOAST_LIMIT } from './constants' import { Action, State, actionTypes } from './types' +import { dispatch } from './toastManager' // 토스트 타임아웃 맵 export const toastTimeouts = new Map>() diff --git a/src/hooks/toast/store.ts b/src/hooks/toast/store.ts index 1112e29..8dbed91 100644 --- a/src/hooks/toast/store.ts +++ b/src/hooks/toast/store.ts @@ -3,7 +3,6 @@ import { State } from './types' // 전역 상태 및 리스너 export const listeners: Array<(state: State) => void> = [] -export let memoryState: State = { toasts: [] } -// 마지막 액션 추적 (중복 방지용) -export let lastAction: { type: string; id?: string; time: number } | null = null +// memoryState와 lastAction은 toastManager.ts에서 관리 +export { memoryState } from './toastManager'; diff --git a/src/hooks/toast/toastManager.ts b/src/hooks/toast/toastManager.ts index 5bebe86..030034c 100644 --- a/src/hooks/toast/toastManager.ts +++ b/src/hooks/toast/toastManager.ts @@ -2,7 +2,11 @@ import { Action, actionTypes } from './types' import { TOAST_LIMIT } from './constants' import { reducer } from './reducer' -import { listeners, memoryState, lastAction } from './store' +import { listeners } from './store' + +// 전역 상태 관리 +let memoryState = { toasts: [] }; +let lastAction = null; // ID 생성기 let count = 0 @@ -49,3 +53,5 @@ export function dispatch(action: Action) { listener(memoryState) }) } + +export { memoryState };