api: reconfigered api handling

This commit is contained in:
Yordan Simeonov
2025-10-20 18:45:01 +02:00
parent d0194f0dc2
commit 98a2067b8d
9 changed files with 112 additions and 295 deletions

View File

@@ -23,14 +23,13 @@ export default function ShowDetails() {
genres,
streamingService,
id,
endDate,
} = useLocalSearchParams();
const [selectedParticipants, setSelectedParticipants] =
React.useState<boolean>(true);
const [selectedSeason, setSelectedSeason] = React.useState<number>(1);
const showId = Number(id);
const { fetchSeasonParticipants, fetchSeasonCount } = useSeasonContext();
const { fetchSeasonParticipants, fetchSeasonCount, fetchSeasonDates } = useSeasonContext();
const [seasonCount, setSeasonCount] = React.useState<number>(0);
const [participants, setParticipants] = React.useState<
{ id: number; name: string; imageUri: string }[]
@@ -62,15 +61,21 @@ export default function ShowDetails() {
};
}, [showId, fetchSeasonCount, selectedSeason]);
React.useEffect(() => {
React.useEffect(() => {
if (!showId || !selectedSeason) return;
let active = true;
(async () => {
setPError(null);
setPLoading(true);
try {
const data = await fetchSeasonParticipants(showId, selectedSeason);
if (active) setParticipants(data);
const [data, dates] = await Promise.all([
fetchSeasonParticipants(showId, selectedSeason),
fetchSeasonDates(showId, selectedSeason),
]);
if (active) {
setParticipants(data);
setStartDate(dates?.startDate);
}
} catch {
if (active) setPError("Fehler beim Laden");
} finally {
@@ -80,14 +85,18 @@ export default function ShowDetails() {
return () => {
active = false;
};
}, [showId, selectedSeason, fetchSeasonParticipants]);
}, [showId, selectedSeason, fetchSeasonParticipants, fetchSeasonDates]);
const startDateObj = new Date(startDate as string);
const formattedStartDate = startDateObj.toLocaleDateString("de-DE", {
day: "2-digit",
month: "long",
year: "numeric",
});
const formattedStartDate = React.useMemo(() => {
if (!startDate) return "";
const d = new Date(startDate);
if (isNaN(d.getTime())) return "";
return d.toLocaleDateString("de-DE", {
day: "2-digit",
month: "long",
year: "numeric",
});
}, [startDate]);
return (
<View style={styles.mainContainer}>
@@ -98,7 +107,10 @@ export default function ShowDetails() {
paddingBottom: Dimensions.get("window").height * 0.1,
}}
>
<Text style={styles.startDate}>{formattedStartDate}</Text>
{formattedStartDate ? (
<Text style={styles.startDate}>{formattedStartDate}</Text>
) : null}
<ShowInfo
seasons={seasonCount}
participants={participants.length}