Skip to content

Commit

Permalink
Use peak debugging tech #6
Browse files Browse the repository at this point in the history
  • Loading branch information
itzCozi committed Mar 24, 2024
1 parent e8836cb commit 6c6b87a
Showing 1 changed file with 25 additions and 9 deletions.
34 changes: 25 additions & 9 deletions src/components/player/atoms/NextEpisodeButton.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -54,8 +54,6 @@ export function NextEpisodeButton(props: {
const setShouldStartFromBeginning = usePlayerStore(
(s) => s.setShouldStartFromBeginning,
);
const currentTime = usePlayerStore((s) => s.progress.time);
const episodeDuration = usePlayerStore((s) => s.progress.duration);

let show = false;
if (showingState === "always") show = true;
Expand All @@ -80,7 +78,31 @@ export function NextEpisodeButton(props: {
setShouldStartFromBeginning(true);
setDirectMeta(metaCopy);
props.onChange?.(metaCopy);
}, [setDirectMeta, nextEp, meta, props, setShouldStartFromBeginning]);

// Check if the current video has finished
if (time === duration) {
// Get the next episode
const nextEpisode = meta?.episodes?.find(
(v) => v.number === (meta?.episode?.number ?? 0) + 1,
);

// If there is a next episode, start playing it
if (nextEpisode) {
metaCopy.episode = nextEpisode;
setShouldStartFromBeginning(true);
setDirectMeta(metaCopy);
props.onChange?.(metaCopy);
}
}
}, [
setDirectMeta,
nextEp,
meta,
props,
setShouldStartFromBeginning,
time,
duration,
]);

const startCurrentEpisodeFromBeginning = useCallback(() => {
if (!meta || !meta.episode) return;
Expand All @@ -90,12 +112,6 @@ export function NextEpisodeButton(props: {
props.onChange?.(metaCopy);
}, [setDirectMeta, meta, props, setShouldStartFromBeginning]);

useEffect(() => {
if (currentTime === episodeDuration) {
loadNextEpisode();
}
}, [currentTime, episodeDuration, loadNextEpisode]);

if (!meta?.episode || !nextEp) return null;
if (metaType !== "show") return null;

Expand Down

0 comments on commit 6c6b87a

Please sign in to comment.