mirror of
https://github.com/remvze/moodist.git
synced 2025-12-17 00:44:14 +00:00
refactor: reduce dependency
This commit is contained in:
parent
f025213ef2
commit
c893e2a6ad
3 changed files with 16 additions and 7 deletions
|
|
@ -16,11 +16,13 @@ import { SnackbarProvider } from '@/contexts/snackbar';
|
|||
import { sounds } from '@/data/sounds';
|
||||
|
||||
import type { Sound } from '@/data/types';
|
||||
import { subscribe } from '@/lib/event';
|
||||
|
||||
export function App() {
|
||||
const categories = useMemo(() => sounds.categories, []);
|
||||
|
||||
const favorites = useSoundStore(useShallow(state => state.getFavorites()));
|
||||
const pause = useSoundStore(state => state.pause);
|
||||
|
||||
const favoriteSounds = useMemo(() => {
|
||||
const favoriteSounds = categories
|
||||
|
|
@ -52,6 +54,16 @@ export function App() {
|
|||
return () => document.removeEventListener('visibilitychange', onChange);
|
||||
}, []);
|
||||
|
||||
useEffect(() => {
|
||||
const unsubscribe = subscribe('fadeOut', (e: { duration: number }) => {
|
||||
setTimeout(() => {
|
||||
pause();
|
||||
}, e.duration);
|
||||
});
|
||||
|
||||
return unsubscribe;
|
||||
}, [pause]);
|
||||
|
||||
const allCategories = useMemo(() => {
|
||||
const favorites = [];
|
||||
|
||||
|
|
|
|||
|
|
@ -58,7 +58,7 @@ export function SleepTimerModal({ onClose, show }: SleepTimerModalProps) {
|
|||
if (timeLeft === 0) {
|
||||
setRunning(false);
|
||||
// pause();
|
||||
dispatch('fadeOut', { duration: 5000 });
|
||||
dispatch('fadeOut', { duration: 1000 });
|
||||
|
||||
setTimeSpent(0);
|
||||
|
||||
|
|
|
|||
|
|
@ -1,7 +1,7 @@
|
|||
import { useMemo, useEffect, useCallback, useState } from 'react';
|
||||
import { Howl } from 'howler';
|
||||
|
||||
import { useSoundStore, useLoadingStore } from '@/store';
|
||||
import { useLoadingStore } from '@/store';
|
||||
import { subscribe } from '@/lib/event';
|
||||
import { useSSR } from './use-ssr';
|
||||
|
||||
|
|
@ -9,8 +9,6 @@ export function useSound(
|
|||
src: string,
|
||||
options: { loop?: boolean; volume?: number } = {},
|
||||
) {
|
||||
const pauseAll = useSoundStore(state => state.pause);
|
||||
|
||||
const [hasLoaded, setHasLoaded] = useState(false);
|
||||
const isLoading = useLoadingStore(state => state.loaders[src]);
|
||||
const setIsLoading = useLoadingStore(state => state.set);
|
||||
|
|
@ -70,12 +68,11 @@ export function useSound(
|
|||
sound?.fade(sound.volume(), 0, duration);
|
||||
|
||||
setTimeout(() => {
|
||||
pauseAll();
|
||||
|
||||
pause();
|
||||
sound?.volume(options.volume || 0.5);
|
||||
}, duration);
|
||||
},
|
||||
[options.volume, sound, pauseAll],
|
||||
[options.volume, sound, pause],
|
||||
);
|
||||
|
||||
useEffect(() => {
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue