From e248131a70e4ac2e691fb43fd8bf4ec6dd0a933e Mon Sep 17 00:00:00 2001 From: Anton Lantukh Date: Wed, 31 May 2023 16:01:00 +0200 Subject: [PATCH] feat(series): inline player and query init fix --- src/hooks/series/useNextEpisode.ts | 2 +- .../mediaScreens/MediaSeries/MediaSeries.tsx | 9 ++++++++- 2 files changed, 9 insertions(+), 2 deletions(-) diff --git a/src/hooks/series/useNextEpisode.ts b/src/hooks/series/useNextEpisode.ts index 5b6a1c9aa..0b0ea4dea 100644 --- a/src/hooks/series/useNextEpisode.ts +++ b/src/hooks/series/useNextEpisode.ts @@ -20,7 +20,7 @@ export const useNextEpisode = ({ return item; }, - { staleTime: SERIES_CACHE_TIME, cacheTime: SERIES_CACHE_TIME }, + { staleTime: SERIES_CACHE_TIME, cacheTime: SERIES_CACHE_TIME, enabled: !!(series?.series_id && episodeId && episodeMetadata) }, ); return { diff --git a/src/pages/ScreenRouting/mediaScreens/MediaSeries/MediaSeries.tsx b/src/pages/ScreenRouting/mediaScreens/MediaSeries/MediaSeries.tsx index 3a24235c8..0b0080dfb 100644 --- a/src/pages/ScreenRouting/mediaScreens/MediaSeries/MediaSeries.tsx +++ b/src/pages/ScreenRouting/mediaScreens/MediaSeries/MediaSeries.tsx @@ -91,7 +91,7 @@ const MediaSeries: ScreenComponent = ({ data: seriesMedia }) => { [seriesMedia, series, episodes], ); const episodesInSeason = getEpisodesInSeason(episodeMetadata, series); - const { data: nextItem } = useNextEpisode({ series, episodeMetadata, episodeId }); + const { data: nextItem } = useNextEpisode({ series, episodeMetadata, episodeId: episode?.mediaid || firstEpisode?.mediaid }); // Watch history const watchHistoryArray = useWatchHistoryStore((state) => state.watchHistory); @@ -122,6 +122,12 @@ const MediaSeries: ScreenComponent = ({ data: seriesMedia }) => { setSearchParams({ ...searchParams, e: (nextItem || episode)?.mediaid, r: feedId || '', play: nextItem ? '1' : '0' }); }, [setSearchParams, nextItem, episode, feedId, searchParams]); + const handleInlinePlay = useCallback(async () => { + if (!episode) { + setSearchParams({ ...searchParams, e: firstEpisode?.mediaid, r: feedId || '', play: '1' }); + } + }, [setSearchParams, firstEpisode, feedId, episode, searchParams]); + // Effects useEffect(() => { (document.scrollingElement || document.body).scroll({ top: 0 }); @@ -262,6 +268,7 @@ const MediaSeries: ScreenComponent = ({ data: seriesMedia }) => { item={episode || firstEpisode} onComplete={handleComplete} feedId={feedId ?? undefined} + onPlay={handleInlinePlay} startWatchingButton={startWatchingButton} paywall={isLocked(accessModel, isLoggedIn, hasSubscription, episode || firstEpisode)} autostart={play || undefined}