From 0784695ae50b85143e5d4f79435bd0656bb982ae Mon Sep 17 00:00:00 2001 From: James Hawkins Date: Sat, 7 Aug 2021 20:27:22 +0100 Subject: [PATCH] commit --- src/components/VideoElement.js | 10 +++++++++- src/views/Movie.js | 22 +++++++++++----------- src/views/Search.js | 9 ++++++++- 3 files changed, 28 insertions(+), 13 deletions(-) diff --git a/src/components/VideoElement.js b/src/components/VideoElement.js index 2f3863fc..5837f0e2 100644 --- a/src/components/VideoElement.js +++ b/src/components/VideoElement.js @@ -28,7 +28,15 @@ export function VideoElement({ streamUrl, loading, setProgress }) { hls.attachMedia(videoRef.current); hls.loadSource(streamUrl); } - }, [videoRef, streamUrl, loading]) + }, [videoRef, streamUrl, loading]); + + React.useEffect(() => { + console.log('running') + const element = document.getElementsByClassName('videoElement')[0]; + if (!element) return; + + element.onProgress = setProgress; + }) if (error) return (Your browser is not supported) diff --git a/src/views/Movie.js b/src/views/Movie.js index d3d8d1b4..348e53d5 100644 --- a/src/views/Movie.js +++ b/src/views/Movie.js @@ -20,6 +20,7 @@ export function MovieView(props) { const [ episodeLists, setEpisodeList ] = React.useState([]); const [ loading, setLoading ] = React.useState(false); const [ selectedSeason, setSelectedSeason ] = React.useState("1"); + let isVideoTimeSet = React.useRef(false) const season = showRouteMatch?.params.season || "1"; const episode = showRouteMatch?.params.episode || "1"; @@ -31,12 +32,12 @@ export function MovieView(props) { React.useEffect(() => { if (streamData.type === "show" && !showRouteMatch) history.replace(`${baseRouteMatch.url}/season/1/episode/1`); - }, [streamData, showRouteMatch, history, baseRouteMatch.url]); + }, [streamData.type, showRouteMatch, history, baseRouteMatch.url]); - React.useEffect(() => { - if (streamData.type === "show" && showRouteMatch) setSelectedSeason(showRouteMatch.params.season.toString()); - // eslint-disable-next-line react-hooks/exhaustive-deps - }, []); + // React.useEffect(() => { + // if (streamData.type === "show" && showRouteMatch) setSelectedSeason(showRouteMatch.params.season.toString()); + // // eslint-disable-next-line react-hooks/exhaustive-deps + // }, []); React.useEffect(() => { let cancel = false; @@ -74,12 +75,10 @@ export function MovieView(props) { setSeasonList(streamData.seasons); setEpisodeList(streamData.episodes[selectedSeason]); } - }, [streamData, selectedSeason]) + }, [streamData.seasons, streamData.episodes, streamData.type, selectedSeason]) React.useEffect(() => { - let cancel = false; - - if (!cancel) { + if (!isVideoTimeSet.current) { let ls = JSON.parse(localStorage.getItem("video-progress") || "{}") let key = streamData.type === "show" ? `${season}-${episode}` : "full" let time = ls?.[streamData.source]?.[streamData.type]?.[streamData.slug]?.[key]?.currentlyAt; @@ -88,7 +87,7 @@ export function MovieView(props) { const element = document.getElementsByClassName('videoElement')[0]; if (!element) { - return () => { cancel = false } + return () => { isVideoTimeSet.current = false } } element.currentTime = time; @@ -96,11 +95,12 @@ export function MovieView(props) { } return () => { - cancel = true; + isVideoTimeSet.current = true; } }) const setProgress = (evt) => { + console.log('setting progress') let ls = JSON.parse(localStorage.getItem("video-progress") || "{}") if (!ls[streamData.source]) diff --git a/src/views/Search.js b/src/views/Search.js index 7428d006..3aefe420 100644 --- a/src/views/Search.js +++ b/src/views/Search.js @@ -149,6 +149,11 @@ export function SearchView() { source } + // due to a constraint with incompatible localStorage data, + // we must quit here if episode and season data is not included + // in the show's data. watching the show will resolve. + if (!subselection.meta) continue; + if (entry.percentageDone < 90) { newContinueWatching.push(entry) // begin next episode logic @@ -157,7 +162,7 @@ export function SearchView() { if (!subselection.show) continue; let newShow = {}; - + // if the current season has a next episode, load it if (subselection.meta.episodes[subselection.show.season].includes(`${parseInt(subselection.show.episode) + 1}`)) { newShow.season = subselection.show.season; @@ -189,6 +194,8 @@ export function SearchView() { return b.data.updatedAt - a.data.updatedAt }); + console.log(newContinueWatching); + setContinueWatching(newContinueWatching) }) }, []);