check for undefined

This commit is contained in:
Jorrin 2024-04-19 19:28:49 +02:00
parent 5fbe5d1ff5
commit cfa3cfd072

View File

@ -46,9 +46,13 @@ 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) {
if (!mediaId) return;
const data = await getMetaFromId(MWMediaType.SERIES, mediaId); 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,7 +64,7 @@ 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) {
@ -111,16 +115,13 @@ export function NextEpisodeButton(props: {
? false ? false
: meta.episode.number === meta.episodes.at(-1)!.number; : 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);