1
0
Fork 0
mirror of https://github.com/sussy-code/smov.git synced 2024-12-20 14:37:43 +01:00

Merge remote-tracking branch 'movie-web/dev'

This commit is contained in:
Cooper Ransom 2024-04-20 13:09:20 -04:00
commit 301a808fad

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 () => {
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;
return data.meta.seasons;
}
@ -60,13 +64,14 @@ function useSeasons(mediaId: string, isLastEpisode: boolean = false) {
function useNextSeasonEpisode(
nextSeason: MWSeasonMeta | undefined,
mediaId: string,
mediaId: string | undefined,
) {
const state = useAsync(async () => {
if (nextSeason) {
if (!mediaId) return null;
const data = await getMetaFromId(
MWMediaType.SERIES,
mediaId ?? "",
mediaId,
nextSeason?.id,
);
if (data?.meta.type !== MWMediaType.SERIES) return null;
@ -105,18 +110,17 @@ export function NextEpisodeButton(props: {
const enableAutoplay = usePreferencesStore((s) => s.enableAutoplay);
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(
(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);