Refactor useToast hook into modules

The useToast hook was refactored into smaller, more manageable modules.
This commit is contained in:
gpt-engineer-app[bot]
2025-03-16 09:48:44 +00:00
parent 61acb461e0
commit 3f22e6c484
4 changed files with 12 additions and 6 deletions

View File

@@ -1,6 +1,6 @@
import * as React from "react" import * as React from "react"
import { Toast, ToasterToast } from "./types" import { Toast, ToasterToast, State } from "./types"
import { actionTypes } from "./types" import { actionTypes } from "./types"
import { listeners, memoryState } from "./store" import { listeners, memoryState } from "./store"
import { genId, dispatch } from "./toastManager" import { genId, dispatch } from "./toastManager"

View File

@@ -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 { Action, State, actionTypes } from './types'
import { dispatch } from './toastManager'
// 토스트 타임아웃 맵 // 토스트 타임아웃 맵
export const toastTimeouts = new Map<string, ReturnType<typeof setTimeout>>() export const toastTimeouts = new Map<string, ReturnType<typeof setTimeout>>()

View File

@@ -3,7 +3,6 @@ import { State } from './types'
// 전역 상태 및 리스너 // 전역 상태 및 리스너
export const listeners: Array<(state: State) => void> = [] export const listeners: Array<(state: State) => void> = []
export let memoryState: State = { toasts: [] }
// 마지막 액션 추적 (중복 방지용) // memoryState와 lastAction은 toastManager.ts에서 관리
export let lastAction: { type: string; id?: string; time: number } | null = null export { memoryState } from './toastManager';

View File

@@ -2,7 +2,11 @@
import { Action, actionTypes } from './types' import { Action, actionTypes } from './types'
import { TOAST_LIMIT } from './constants' import { TOAST_LIMIT } from './constants'
import { reducer } from './reducer' import { reducer } from './reducer'
import { listeners, memoryState, lastAction } from './store' import { listeners } from './store'
// 전역 상태 관리
let memoryState = { toasts: [] };
let lastAction = null;
// ID 생성기 // ID 생성기
let count = 0 let count = 0
@@ -49,3 +53,5 @@ export function dispatch(action: Action) {
listener(memoryState) listener(memoryState)
}) })
} }
export { memoryState };