fix: take remvze comments into account

This commit is contained in:
Jef Roelandt 2024-04-28 18:47:24 +02:00
parent 71b62ed3dd
commit 0517c31fc1
2 changed files with 6 additions and 7 deletions

View file

@ -75,7 +75,6 @@ export function Menu() {
return (
<>
<Divider />
<div className={styles.wrapper}>
<DropdownMenu.Root open={isOpen} onOpenChange={o => setIsOpen(o)}>
<DropdownMenu.Trigger asChild>

View file

@ -1,4 +1,4 @@
import { useEffect, useState, useCallback } from 'react';
import { useEffect, useState, useCallback, useRef } from 'react';
import { Modal } from '@/components/modal';
import { FaPlay, FaUndo } from 'react-icons/fa/index';
import { useSoundStore } from '@/store';
@ -18,7 +18,8 @@ export function SleepTimerModal({ onClose, show }: SleepTimerModalProps) {
const [minutes, setMinutes] = useState<string>('0');
const [running, setRunning] = useState(false);
const [timeLeft, setTimeLeft] = useState(0);
const [timerId, setTimerId] = useState<NodeJS.Timeout | undefined>(undefined);
const timerId = useRef<NodeJS.Timeout>();
const pause = useSoundStore(state => state.pause);
@ -33,9 +34,8 @@ export function SleepTimerModal({ onClose, show }: SleepTimerModalProps) {
setTimeLeft(calculateTotalSeconds());
}, [calculateTotalSeconds]);
// Handle multiple clicks on this. Only the latest click should be taken into account
const handleStart = () => {
if (timerId) clearInterval(timerId);
if (timerId.current) clearInterval(timerId.current);
setTimeLeft(calculateTotalSeconds);
setRunning(true);
@ -54,12 +54,12 @@ export function SleepTimerModal({ onClose, show }: SleepTimerModalProps) {
});
}, 1000);
setTimerId(newTimerId);
timerId.current = newTimerId;
}
};
const handleReset = () => {
if (timerId) clearInterval(timerId);
if (timerId.current) clearInterval(timerId.current);
setTimeLeft(0);
setRunning(false);
};