diff --git a/src/components/media/ModalEpisodeSelector.tsx b/src/components/media/ModalEpisodeSelector.tsx index f4716589..d056ac35 100644 --- a/src/components/media/ModalEpisodeSelector.tsx +++ b/src/components/media/ModalEpisodeSelector.tsx @@ -1,11 +1,54 @@ -// We make a episode selector modal component that will be used in the media page to select the episode to play. +import React, { useEffect, useState } from 'react'; +import { get } from "@/backend/metadata/tmdb"; +import { conf } from "@/setup/config"; -// import { get } from "../backend/metadata/tmdb"; -// (or whatever the relevant path is to backend/metadata/tmdb) -// import { conf } from "@/setup/config"; +interface ModalEpisodeSelectorProps { + tmdbId: string; +} -// const data = await get("/tv)/[tmdbID-HERE]/season/[seasonNumber-HERE]", { -// api_key: conf().TMDB_READ_API_KEY, -// language: "en-US", -// }); -// Then data will return json of the season information including all the episode names. So just call data.episodes to get a json output of all the episode info +interface Season { + season_number: number; +} + +export const EpisodeSelector: React.FC = ({ tmdbId }) => { + const [seasonsData, setSeasonsData] = useState([]); + + useEffect(() => { + const fetchSeasons = async () => { + try { + // Fetch TV show details to get seasons list + const showDetails = await get(`/tv/${tmdbId}`, { + api_key: conf().TMDB_READ_API_KEY, + language: "en-US", + }); + + const seasons = showDetails.seasons as Season[]; + const seasonsDetailsPromises = seasons.map(season => + get(`/tv/${tmdbId}/season/${season.season_number}`, { + api_key: conf().TMDB_READ_API_KEY, + language: "en-US", + }) + ); + + // Fetch details for all seasons concurrently + const seasonsDetails = await Promise.all(seasonsDetailsPromises); + setSeasonsData(seasonsDetails); + } catch (err) { + console.error(err); + } + }; + + fetchSeasons(); + }, [tmdbId]); + + console.log(seasonsData) + return ( +
+ {seasonsData.map((season, index) => ( +
+ Season {season.season_number}: {season.name} +
+ ))} +
+ ); +}; \ No newline at end of file diff --git a/src/components/media/PopupModal.tsx b/src/components/media/PopupModal.tsx index 959145bf..d139ad29 100644 --- a/src/components/media/PopupModal.tsx +++ b/src/components/media/PopupModal.tsx @@ -5,6 +5,7 @@ import { useNavigate } from "react-router-dom"; import { get } from "@/backend/metadata/tmdb"; import { conf } from "@/setup/config"; import { MediaItem } from "@/utils/mediaTypes"; +import { EpisodeSelector } from "./ModalEpisodeSelector"; import { Button } from "../buttons/Button"; import { Icon, Icons } from "../Icon"; @@ -256,6 +257,13 @@ export function PopupModal({
{data?.overview}
+
+ {isTVShow ? ( + + ): null} +