Skip to content

Commit

Permalink
refactor: add constants
Browse files Browse the repository at this point in the history
  • Loading branch information
remvze committed May 1, 2024
1 parent d9246b6 commit 81678ea
Show file tree
Hide file tree
Showing 5 changed files with 11 additions and 5 deletions.
3 changes: 2 additions & 1 deletion src/components/app/app.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -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';
Expand Down Expand Up @@ -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(() => {
Expand Down
3 changes: 2 additions & 1 deletion src/components/modals/sleep-timer/sleep-timer.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -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';

Expand Down Expand Up @@ -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);

Expand Down
2 changes: 2 additions & 0 deletions src/constants/events.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
export const FADE_OUT = 'FADE_OUT';
export const CLOSE_MODALS = 'CLOSE_MODALS';
3 changes: 2 additions & 1 deletion src/hooks/use-sound.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down Expand Up @@ -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(
Expand Down
5 changes: 3 additions & 2 deletions src/lib/modal.ts
Original file line number Diff line number Diff line change
@@ -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;
}

0 comments on commit 81678ea

Please sign in to comment.