diff --git a/src/components/media/ModalEpisodeSelector.tsx b/src/components/media/ModalEpisodeSelector.tsx index c2510f1d..c2912cbf 100644 --- a/src/components/media/ModalEpisodeSelector.tsx +++ b/src/components/media/ModalEpisodeSelector.tsx @@ -10,25 +10,16 @@ interface ModalEpisodeSelectorProps { mediaTitle: string; } -interface Season { - season_number: number; - id: number; -} - -interface ShowDetails { - seasons: Season[]; -} - export function EpisodeSelector({ tmdbId, mediaTitle, }: ModalEpisodeSelectorProps) { - const [seasonsData, setSeasonsData] = useState([]); + const [seasonsData, setSeasonsData] = useState([]); const [selectedSeason, setSelectedSeason] = useState(null); const navigate = useNavigate(); const handleSeasonSelect = useCallback( - async (season: Season) => { + async (season: any) => { try { const seasonDetails = await get( `/tv/${tmdbId}/season/${season.season_number}`, @@ -37,11 +28,7 @@ export function EpisodeSelector({ language: "en-US", }, ); - setSelectedSeason({ - ...seasonDetails, - season_number: season.season_number, - id: season.id, - }); + setSelectedSeason(seasonDetails); } catch (err) { console.error(err); } @@ -52,18 +39,16 @@ export function EpisodeSelector({ useEffect(() => { const fetchSeasons = async () => { try { - const showDetails = await get(`/tv/${tmdbId}`, { + const showDetails = await get(`/tv/${tmdbId}`, { api_key: conf().TMDB_READ_API_KEY, language: "en-US", }); setSeasonsData(showDetails.seasons); - const regularSeasons = showDetails.seasons.filter( - (season: Season) => season.season_number > 0, - ); - if (regularSeasons.length > 0) { - handleSeasonSelect(regularSeasons[0]); - } else if (showDetails.seasons.length > 0) { + if (showDetails.seasons[0] === 0) { + // Default to first season handleSeasonSelect(showDetails.seasons[0]); + } else { + handleSeasonSelect(showDetails.seasons[1]); } } catch (err) { console.error(err); @@ -73,14 +58,15 @@ export function EpisodeSelector({ }, [handleSeasonSelect, tmdbId]); return ( -
-
- {seasonsData.map((season: Season) => ( +
+
+ {seasonsData.map((season) => (
handleSeasonSelect(season)} className={`cursor-pointer p-1 text-center rounded transition-transform duration-200 ${ - selectedSeason && season.id === selectedSeason.id + selectedSeason && + season.season_number === selectedSeason.season_number ? "bg-search-background" : "hover:bg-search-background hover:scale-95" }`} @@ -91,27 +77,25 @@ export function EpisodeSelector({
))}
-
-
+
+
{selectedSeason ? ( selectedSeason.episodes.map( (episode: { episode_number: number; name: string; still_path: string; + show_id: number; id: number; }) => ( { - const url = `/media/tmdb-tv-${tmdbId}-${mediaTitle}/${selectedSeason.id}/${episode.id}`; - console.log(`Navigating to: ${url}`); - console.log( - `Season ID: ${selectedSeason.id}, Episode ID: ${episode.id}`, - ); - navigate(url); - }} - className="group cursor-pointer rounded-xl relative p-[0.65em] bg-background-main transition-colors duration-[0.28s]" + key={episode.episode_number} + onClick={() => + navigate( + `/media/tmdb-tv-${tmdbId}-${mediaTitle}/${episode.show_id}/${episode.id}`, + ) + } + className="group cursor-pointer rounded-xl relative p-[0.65em] bg-background-main transition-colors duration-[0.28s] flex-shrink-0 w-48 sm:w-auto mr-2 sm:mr-0" >

- {`S${selectedSeason.season_number}E${episode.episode_number}: ${episode.name}`} + {episode.name}