Skip to content

Commit

Permalink
check for undefined
Browse files Browse the repository at this point in the history
  • Loading branch information
JorrinKievit committed Apr 19, 2024
1 parent 5fbe5d1 commit cfa3cfd
Showing 1 changed file with 8 additions and 7 deletions.
15 changes: 8 additions & 7 deletions src/components/player/atoms/NextEpisodeButton.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -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 () => {
if (isLastEpisode) {
if (!mediaId) return;
const data = await getMetaFromId(MWMediaType.SERIES, mediaId);
if (data?.meta.type !== MWMediaType.SERIES) return null;
return data.meta.seasons;
Expand All @@ -60,7 +64,7 @@ function useSeasons(mediaId: string, isLastEpisode: boolean = false) {

function useNextSeasonEpisode(
nextSeason: MWSeasonMeta | undefined,
mediaId: string,
mediaId: string | undefined,
) {
const state = useAsync(async () => {
if (nextSeason) {
Expand Down Expand Up @@ -111,16 +115,13 @@ export function NextEpisodeButton(props: {
? 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(
(season) => season.number === (meta?.season?.number ?? 0) + 1,
);

const nextSeasonEpisode = useNextSeasonEpisode(
nextSeason,
meta?.tmdbId ?? "",
);
const nextSeasonEpisode = useNextSeasonEpisode(nextSeason, meta?.tmdbId);

let show = false;
const hasAutoplayed = useRef(false);
Expand Down

0 comments on commit cfa3cfd

Please sign in to comment.