mirror of
https://github.com/sussy-code/smov.git
synced 2024-12-20 14:37:43 +01:00
polishing episode selector
This commit is contained in:
parent
745a5d77b5
commit
13d836946e
2 changed files with 74 additions and 49 deletions
|
@ -1,4 +1,5 @@
|
||||||
import React, { useEffect, useState } from 'react';
|
import React, { useEffect, useState } from "react";
|
||||||
|
|
||||||
import { get } from "@/backend/metadata/tmdb";
|
import { get } from "@/backend/metadata/tmdb";
|
||||||
import { conf } from "@/setup/config";
|
import { conf } from "@/setup/config";
|
||||||
|
|
||||||
|
@ -6,49 +7,78 @@ interface ModalEpisodeSelectorProps {
|
||||||
tmdbId: string;
|
tmdbId: string;
|
||||||
}
|
}
|
||||||
|
|
||||||
interface Season {
|
export function EpisodeSelector({ tmdbId }: ModalEpisodeSelectorProps) {
|
||||||
season_number: number;
|
|
||||||
}
|
|
||||||
|
|
||||||
export const EpisodeSelector: React.FC<ModalEpisodeSelectorProps> = ({ tmdbId }) => {
|
|
||||||
const [seasonsData, setSeasonsData] = useState<any[]>([]);
|
const [seasonsData, setSeasonsData] = useState<any[]>([]);
|
||||||
|
const [selectedSeason, setSelectedSeason] = useState<any>(null);
|
||||||
|
|
||||||
useEffect(() => {
|
useEffect(() => {
|
||||||
const fetchSeasons = async () => {
|
const fetchSeasons = async () => {
|
||||||
try {
|
try {
|
||||||
// Fetch TV show details to get seasons list
|
|
||||||
const showDetails = await get<any>(`/tv/${tmdbId}`, {
|
const showDetails = await get<any>(`/tv/${tmdbId}`, {
|
||||||
api_key: conf().TMDB_READ_API_KEY,
|
api_key: conf().TMDB_READ_API_KEY,
|
||||||
language: "en-US",
|
language: "en-US",
|
||||||
});
|
});
|
||||||
|
setSeasonsData(showDetails.seasons);
|
||||||
const seasons = showDetails.seasons as Season[];
|
|
||||||
const seasonsDetailsPromises = seasons.map(season =>
|
|
||||||
get<any>(`/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) {
|
} catch (err) {
|
||||||
console.error(err);
|
console.error(err);
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
fetchSeasons();
|
fetchSeasons();
|
||||||
}, [tmdbId]);
|
}, [tmdbId]);
|
||||||
|
|
||||||
console.log(seasonsData)
|
const handleSeasonSelect = async (season: any) => {
|
||||||
|
try {
|
||||||
|
const seasonDetails = await get<any>(
|
||||||
|
`/tv/${tmdbId}/season/${season.season_number}`,
|
||||||
|
{
|
||||||
|
api_key: conf().TMDB_READ_API_KEY,
|
||||||
|
language: "en-US",
|
||||||
|
},
|
||||||
|
);
|
||||||
|
setSelectedSeason(seasonDetails);
|
||||||
|
} catch (err) {
|
||||||
|
console.error(err);
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<div>
|
<div className="flex p-2 mt-4 bg-mediaCard-hoverBackground rounded max-h-48 overflow-hidden">
|
||||||
{seasonsData.map((season, index) => (
|
<div className="flex-none w-20 overflow-y-auto max-h-48">
|
||||||
<div key={index}>
|
{seasonsData.map((season) => (
|
||||||
Season {season.season_number}: {season.name}
|
<div
|
||||||
</div>
|
key={season.season_number}
|
||||||
))}
|
onClick={() => handleSeasonSelect(season)}
|
||||||
|
className="cursor-pointer hover:bg-search-background p-1 text-center rounded"
|
||||||
|
>
|
||||||
|
S{season.season_number}
|
||||||
|
</div>
|
||||||
|
))}
|
||||||
|
</div>
|
||||||
|
<div className="flex-auto p-2 overflow-y-auto max-h-96">
|
||||||
|
{selectedSeason ? (
|
||||||
|
<div>
|
||||||
|
<h2>
|
||||||
|
{selectedSeason.name} - {selectedSeason.episodes.length} episodes
|
||||||
|
</h2>
|
||||||
|
<ul>
|
||||||
|
{selectedSeason.episodes.map(
|
||||||
|
(
|
||||||
|
episode: { episode_number: number; name: string },
|
||||||
|
index: number,
|
||||||
|
) => (
|
||||||
|
<li key={episode.episode_number}>
|
||||||
|
{episode.episode_number}. {episode.name}
|
||||||
|
</li>
|
||||||
|
),
|
||||||
|
)}
|
||||||
|
</ul>
|
||||||
|
</div>
|
||||||
|
) : (
|
||||||
|
<div>
|
||||||
|
<p>Select a season to see details</p>
|
||||||
|
</div>
|
||||||
|
)}
|
||||||
|
</div>
|
||||||
</div>
|
</div>
|
||||||
);
|
);
|
||||||
};
|
}
|
||||||
|
|
|
@ -5,8 +5,8 @@ import { useNavigate } from "react-router-dom";
|
||||||
import { get } from "@/backend/metadata/tmdb";
|
import { get } from "@/backend/metadata/tmdb";
|
||||||
import { conf } from "@/setup/config";
|
import { conf } from "@/setup/config";
|
||||||
import { MediaItem } from "@/utils/mediaTypes";
|
import { MediaItem } from "@/utils/mediaTypes";
|
||||||
import { EpisodeSelector } from "./ModalEpisodeSelector";
|
|
||||||
|
|
||||||
|
import { EpisodeSelector } from "./ModalEpisodeSelector";
|
||||||
import { Button } from "../buttons/Button";
|
import { Button } from "../buttons/Button";
|
||||||
import { Icon, Icons } from "../Icon";
|
import { Icon, Icons } from "../Icon";
|
||||||
|
|
||||||
|
@ -154,7 +154,7 @@ export function PopupModal({
|
||||||
>
|
>
|
||||||
<div
|
<div
|
||||||
ref={modalRef}
|
ref={modalRef}
|
||||||
className="rounded-xl p-3 m-8 bg-modal-background flex justify-center items-center transition-opacity duration-100 max-w-full sm:max-w-xl"
|
className="rounded-xl p-3 m-4 sm:m-8 bg-modal-background flex justify-center items-center transition-opacity duration-100 max-w-full sm:max-w-xl w-full sm:w-auto"
|
||||||
style={{ opacity: style.opacity }}
|
style={{ opacity: style.opacity }}
|
||||||
>
|
>
|
||||||
<div className="aspect-w-16 aspect-h-9 overflow-y-auto w-full sm:w-auto">
|
<div className="aspect-w-16 aspect-h-9 overflow-y-auto w-full sm:w-auto">
|
||||||
|
@ -194,11 +194,9 @@ export function PopupModal({
|
||||||
const releaseInfo = mediaInfo?.results?.find(
|
const releaseInfo = mediaInfo?.results?.find(
|
||||||
(result: any) => result.iso_3166_1 === "US",
|
(result: any) => result.iso_3166_1 === "US",
|
||||||
);
|
);
|
||||||
return releaseInfo && releaseInfo.rating ? (
|
return releaseInfo && releaseInfo.rating
|
||||||
releaseInfo.rating
|
? releaseInfo.rating
|
||||||
) : (
|
: "NR";
|
||||||
<Skeleton />
|
|
||||||
);
|
|
||||||
})()}
|
})()}
|
||||||
</span>
|
</span>
|
||||||
</div>
|
</div>
|
||||||
|
@ -245,25 +243,22 @@ export function PopupModal({
|
||||||
</div>
|
</div>
|
||||||
{data?.genres?.length > 0
|
{data?.genres?.length > 0
|
||||||
? data.genres.map((genre: { name: string }) => (
|
? data.genres.map((genre: { name: string }) => (
|
||||||
<div
|
<div key={genre.name} className="inline-block">
|
||||||
key={genre.name}
|
<div className="px-2 py-1 bg-mediaCard-hoverBackground rounded hover:bg-search-background cursor-default duration-200 transition-colors transform hover:scale-110">
|
||||||
className="px-2 py-1 bg-mediaCard-hoverBackground rounded hover:bg-search-background cursor-default duration-200 transition-colors"
|
{genre.name}
|
||||||
>
|
</div>
|
||||||
{genre.name}
|
|
||||||
</div>
|
</div>
|
||||||
))
|
))
|
||||||
: Array.from({ length: 3 }).map((_) => <Skeleton />)}
|
: Array.from({ length: 3 }).map((_) => (
|
||||||
|
<div className="inline-block">
|
||||||
|
<Skeleton />
|
||||||
|
</div>
|
||||||
|
))}
|
||||||
</div>
|
</div>
|
||||||
<div className="relative whitespace-normal font-medium overflow-y-auto max-h-40">
|
<div className="relative whitespace-normal font-medium overflow-y-auto max-h-32">
|
||||||
{data?.overview}
|
{data?.overview}
|
||||||
</div>
|
</div>
|
||||||
<div>
|
<div>{isTVShow ? <EpisodeSelector tmdbId={media.id} /> : null}</div>
|
||||||
{isTVShow ? (
|
|
||||||
<EpisodeSelector
|
|
||||||
tmdbId={media.id}
|
|
||||||
/>
|
|
||||||
): null}
|
|
||||||
</div>
|
|
||||||
<div className="flex justify-center items-center mt-4 mb-1">
|
<div className="flex justify-center items-center mt-4 mb-1">
|
||||||
<Button
|
<Button
|
||||||
theme="purple"
|
theme="purple"
|
||||||
|
|
Loading…
Reference in a new issue