Improve iOS support

This commit is contained in:
0x1eef 2023-07-15 00:48:22 -03:00
parent fdfb75a648
commit e3ef370027

View file

@ -26,21 +26,18 @@ export function Timer({
const [tid, setTid] = useState<ReturnType<typeof setTimeout>>(); const [tid, setTid] = useState<ReturnType<typeof setTimeout>>();
useEffect(() => { useEffect(() => {
if (tid) {
clearTimeout(tid);
setTid(undefined);
}
setMs(ayah.readTimeMs); setMs(ayah.readTimeMs);
}, [ayah.id, soundOn]); }, [ayah.id, soundOn]);
useEffect(() => { useEffect(() => {
if ((soundOn && isStalled) || isPaused) { if ((soundOn && isStalled) || isPaused) {
return; /* no-op */
} else if (ms <= 0) { } else if (ms <= 0) {
setStream([...stream, surah.ayat[ayah.id]]); setStream([...stream, surah.ayat[ayah.id]]);
} else { } else {
setTid(setTimeout(() => setMs(ms - 100), 100)); setTid(setTimeout(() => setMs(ms - 100), 100));
} }
return () => clearTimeout(tid);
}, [isStalled, isPaused, soundOn, ms]); }, [isStalled, isPaused, soundOn, ms]);
return <div className="timer">{formatNumber(ms / 1000, locale)}</div>; return <div className="timer">{formatNumber(ms / 1000, locale)}</div>;