mirror of
https://github.com/remvze/moodist.git
synced 2026-02-28 00:53:13 +08:00
fix: play sounds when starting timer if not already playing
This commit is contained in:
@@ -21,6 +21,8 @@ export function SleepTimerModal({ onClose, show }: SleepTimerModalProps) {
|
||||
|
||||
const timerId = useRef<NodeJS.Timeout>();
|
||||
|
||||
const isPlaying = useSoundStore(state => state.isPlaying);
|
||||
const play = useSoundStore(state => state.play);
|
||||
const pause = useSoundStore(state => state.pause);
|
||||
|
||||
const calculateTotalSeconds = useCallback((): number => {
|
||||
@@ -36,6 +38,7 @@ export function SleepTimerModal({ onClose, show }: SleepTimerModalProps) {
|
||||
|
||||
const handleStart = () => {
|
||||
if (timerId.current) clearInterval(timerId.current);
|
||||
if (!isPlaying) play();
|
||||
|
||||
setTimeLeft(calculateTotalSeconds);
|
||||
setRunning(true);
|
||||
|
||||
Reference in New Issue
Block a user