1
0
Fork 0
mirror of https://github.com/sussy-code/smov.git synced 2024-12-29 16:07:40 +01:00

Fix issue with next episode vol. 2

This commit is contained in:
Cooper Ransom 2024-03-21 11:41:53 -04:00
parent 7e8c8d7983
commit 7c80e8c783

View file

@ -90,27 +90,31 @@ export function NextEpisodeButton(props: {
}, [setDirectMeta, meta, props, setShouldStartFromBeginning]); }, [setDirectMeta, meta, props, setShouldStartFromBeginning]);
useEffect(() => { useEffect(() => {
let intervalId: number = 0; // Only start the countdown if the button is supposed to show.
if (show && countdown > 0) { if (!show) {
intervalId = window.setInterval(() => { return;
setCountdown((currentCountdown) => {
// When countdown reaches 1, load the next episode on the next tick
if (currentCountdown === 1) {
// Ensure this runs only once by setting countdown to a non-positive number
setCountdown(-1);
loadNextEpisode();
} }
return currentCountdown - 1;
// Initialize the countdown only once when the condition to show the button is met.
setCountdown(15); // Reset to 15 seconds whenever the conditions to show the button are met.
const intervalId = window.setInterval(() => {
setCountdown((currentCountdown) => {
const newCountdown = currentCountdown - 1;
// When countdown reaches 0, load the next episode.
if (newCountdown <= 0) {
loadNextEpisode();
// Stop the countdown by clearing the interval.
window.clearInterval(intervalId);
return 0; // Optionally reset the countdown or keep it at 0.
}
return newCountdown;
}); });
}, 1000); }, 1000);
} else {
window.clearInterval(intervalId); // Cleanup function to clear the interval when the component unmounts or the dependencies change.
if (!show) {
setCountdown(15); // Reset countdown when not showing.
}
}
return () => window.clearInterval(intervalId); return () => window.clearInterval(intervalId);
}, [show, countdown, loadNextEpisode]); }, [show, loadNextEpisode]); // Removed countdown from dependencies to prevent resetting it unnecessarily.
if (!meta?.episode || !nextEp) return null; if (!meta?.episode || !nextEp) return null;
if (metaType !== "show") return null; if (metaType !== "show") return null;