diff --git a/src/components/app/app.tsx b/src/components/app/app.tsx index 7a713fb..713e24a 100644 --- a/src/components/app/app.tsx +++ b/src/components/app/app.tsx @@ -14,6 +14,7 @@ import { Toolbar } from '@/components/toolbar'; import { SnackbarProvider } from '@/contexts/snackbar'; import { sounds } from '@/data/sounds'; +import { FADE_OUT } from '@/constants/events'; import type { Sound } from '@/data/types'; import { subscribe } from '@/lib/event'; @@ -57,7 +58,7 @@ export function App() { }, []); useEffect(() => { - const unsubscribe = subscribe('fadeOut', (e: { duration: number }) => { + const unsubscribe = subscribe(FADE_OUT, (e: { duration: number }) => { lock(); setTimeout(() => { diff --git a/src/components/modals/sleep-timer/sleep-timer.tsx b/src/components/modals/sleep-timer/sleep-timer.tsx index 22d64fa..08fdb4b 100644 --- a/src/components/modals/sleep-timer/sleep-timer.tsx +++ b/src/components/modals/sleep-timer/sleep-timer.tsx @@ -5,6 +5,7 @@ import { Timer } from '@/components/timer'; import { dispatch } from '@/lib/event'; import { useSoundStore } from '@/store'; import { cn } from '@/helpers/styles'; +import { FADE_OUT } from '@/constants/events'; import styles from './sleep-timer.module.css'; @@ -58,7 +59,7 @@ export function SleepTimerModal({ onClose, show }: SleepTimerModalProps) { if (timeLeft === 0) { setRunning(false); // pause(); - dispatch('fadeOut', { duration: 1000 }); + dispatch(FADE_OUT, { duration: 1000 }); setTimeSpent(0); diff --git a/src/constants/events.ts b/src/constants/events.ts new file mode 100644 index 0000000..9317274 --- /dev/null +++ b/src/constants/events.ts @@ -0,0 +1,2 @@ +export const FADE_OUT = 'FADE_OUT'; +export const CLOSE_MODALS = 'CLOSE_MODALS'; diff --git a/src/hooks/use-sound.ts b/src/hooks/use-sound.ts index 135b6e1..37e3779 100644 --- a/src/hooks/use-sound.ts +++ b/src/hooks/use-sound.ts @@ -4,6 +4,7 @@ import { Howl } from 'howler'; import { useLoadingStore } from '@/store'; import { subscribe } from '@/lib/event'; import { useSSR } from './use-ssr'; +import { FADE_OUT } from '@/constants/events'; export function useSound( src: string, @@ -78,7 +79,7 @@ export function useSound( useEffect(() => { const listener = (e: { duration: number }) => fadeOut(e.duration); - return subscribe('fadeOut', listener); + return subscribe(FADE_OUT, listener); }, [fadeOut]); const control = useMemo( diff --git a/src/lib/modal.ts b/src/lib/modal.ts index 0931cfc..f7a550c 100644 --- a/src/lib/modal.ts +++ b/src/lib/modal.ts @@ -1,11 +1,12 @@ import { dispatch, subscribe } from './event'; +import { CLOSE_MODALS } from '@/constants/events'; export function closeModals() { - dispatch('closeModals'); + dispatch(CLOSE_MODALS); } export function onCloseModals(listener: () => void) { - const unsubscribe = subscribe('closeModals', listener); + const unsubscribe = subscribe(CLOSE_MODALS, listener); return unsubscribe; }