diff --git a/src/components/media/ModalEpisodeSelector.tsx b/src/components/media/ModalEpisodeSelector.tsx index 298a74b9..ae3a6f3c 100644 --- a/src/components/media/ModalEpisodeSelector.tsx +++ b/src/components/media/ModalEpisodeSelector.tsx @@ -1,4 +1,4 @@ -import React, { useEffect, useState } from "react"; +import React, { useCallback, useEffect, useState } from "react"; import { get } from "@/backend/metadata/tmdb"; import { conf } from "@/setup/config"; @@ -11,6 +11,24 @@ export function EpisodeSelector({ tmdbId }: ModalEpisodeSelectorProps) { const [seasonsData, setSeasonsData] = useState([]); const [selectedSeason, setSelectedSeason] = useState(null); + const handleSeasonSelect = useCallback( + async (season: any) => { + try { + const seasonDetails = await get( + `/tv/${tmdbId}/season/${season.season_number}`, + { + api_key: conf().TMDB_READ_API_KEY, + language: "en-US", + }, + ); + setSelectedSeason(seasonDetails); + } catch (err) { + console.error(err); + } + }, + [tmdbId], + ); + useEffect(() => { const fetchSeasons = async () => { try { @@ -19,65 +37,56 @@ export function EpisodeSelector({ tmdbId }: ModalEpisodeSelectorProps) { language: "en-US", }); setSeasonsData(showDetails.seasons); + handleSeasonSelect(showDetails.seasons[0]); // Default to first season } catch (err) { console.error(err); } }; fetchSeasons(); - }, [tmdbId]); - - const handleSeasonSelect = async (season: any) => { - try { - const seasonDetails = await get( - `/tv/${tmdbId}/season/${season.season_number}`, - { - api_key: conf().TMDB_READ_API_KEY, - language: "en-US", - }, - ); - setSelectedSeason(seasonDetails); - } catch (err) { - console.error(err); - } - }; + }, [handleSeasonSelect, tmdbId]); return ( -
-
+
+
{seasonsData.map((season) => (
handleSeasonSelect(season)} - className="cursor-pointer hover:bg-search-background p-1 text-center rounded" + className="cursor-pointer hover:bg-search-background p-1 text-center rounded hover:scale-95 transition-transform duration-300" > S{season.season_number}
))}
-
- {selectedSeason ? ( -
-

- {selectedSeason.name} - {selectedSeason.episodes.length} episodes -

-
    - {selectedSeason.episodes.map( - ( - episode: { episode_number: number; name: string }, - index: number, - ) => ( -
  • - {episode.episode_number}. {episode.name} -
  • - ), - )} -
-
- ) : ( -
-

Select a season to see details

-
- )} +
+
+ {selectedSeason ? ( + selectedSeason.episodes.map( + (episode: { + episode_number: number; + name: string; + still_path: string; + }) => ( +
+ {episode.name} +

{episode.name}

+
+
+ ), + ) + ) : ( +
+ Select a season to see episodes +
+ )} +
);