Merge pull request #1140 from movie-web/fix/#1118

fix tmdb 404 request
This commit is contained in:
William Oldham 2024-04-20 10:37:58 +01:00 committed by GitHub
commit 9bd5f30f40
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194

View File

@ -46,10 +46,14 @@ function Button(props: {
); );
} }
function useSeasons(mediaId: string, isLastEpisode: boolean = false) { function useSeasons(
mediaId: string | undefined,
isLastEpisode: boolean = false,
) {
const state = useAsync(async () => { const state = useAsync(async () => {
if (isLastEpisode) { if (isLastEpisode) {
const data = await getMetaFromId(MWMediaType.SERIES, mediaId ?? ""); if (!mediaId) return null;
const data = await getMetaFromId(MWMediaType.SERIES, mediaId);
if (data?.meta.type !== MWMediaType.SERIES) return null; if (data?.meta.type !== MWMediaType.SERIES) return null;
return data.meta.seasons; return data.meta.seasons;
} }
@ -60,13 +64,14 @@ function useSeasons(mediaId: string, isLastEpisode: boolean = false) {
function useNextSeasonEpisode( function useNextSeasonEpisode(
nextSeason: MWSeasonMeta | undefined, nextSeason: MWSeasonMeta | undefined,
mediaId: string, mediaId: string | undefined,
) { ) {
const state = useAsync(async () => { const state = useAsync(async () => {
if (nextSeason) { if (nextSeason) {
if (!mediaId) return null;
const data = await getMetaFromId( const data = await getMetaFromId(
MWMediaType.SERIES, MWMediaType.SERIES,
mediaId ?? "", mediaId,
nextSeason?.id, nextSeason?.id,
); );
if (data?.meta.type !== MWMediaType.SERIES) return null; if (data?.meta.type !== MWMediaType.SERIES) return null;
@ -106,18 +111,17 @@ export function NextEpisodeButton(props: {
const enableAutoplay = usePreferencesStore((s) => s.enableAutoplay); const enableAutoplay = usePreferencesStore((s) => s.enableAutoplay);
const isLastEpisode = const isLastEpisode =
meta?.episode?.number === meta?.episodes?.at(-1)?.number; !meta?.episode?.number || !meta?.episodes?.at(-1)?.number
? false
: meta.episode.number === meta.episodes.at(-1)!.number;
const seasons = useSeasons(meta?.tmdbId ?? "", isLastEpisode); const seasons = useSeasons(meta?.tmdbId, isLastEpisode);
const nextSeason = seasons.value?.find( const nextSeason = seasons.value?.find(
(season) => season.number === (meta?.season?.number ?? 0) + 1, (season) => season.number === (meta?.season?.number ?? 0) + 1,
); );
const nextSeasonEpisode = useNextSeasonEpisode( const nextSeasonEpisode = useNextSeasonEpisode(nextSeason, meta?.tmdbId);
nextSeason,
meta?.tmdbId ?? "",
);
let show = false; let show = false;
const hasAutoplayed = useRef(false); const hasAutoplayed = useRef(false);