import StackHeader from "@/components/ui/StackHeader"; import { useLocalSearchParams, router } from "expo-router"; import ShowInfo from "@/components/ui/ShowInfo"; import ParticipantDetails from "@/components/ParticipantDeatails"; import React from "react"; import { useSeasonContext } from "@/contexts/SeasonContext"; import { Dimensions, Image, ScrollView, Text, TouchableOpacity, View, } from "react-native"; import * as WebBrowser from "expo-web-browser"; import styles from "./stackStyles/showDetailStyles"; export default function ShowDetails() { const { bannerUri, description, concept, genres, streamingService, id } = useLocalSearchParams(); const [selectedParticipants, setSelectedParticipants] = React.useState(true); const [selectedSeason, setSelectedSeason] = React.useState(1); const showId = Number(id); const { fetchSeasonParticipants, fetchSeasonCount } = useSeasonContext(); const [seasonCount, setSeasonCount] = React.useState(0); const [participants, setParticipants] = React.useState< { id: number; name: string; imageUri: string }[] >([]); const [pLoading, setPLoading] = React.useState(false); const [pError, setPError] = React.useState(null); React.useEffect(() => { if (!showId) return; let active = true; (async () => { const count = await fetchSeasonCount(showId); if (active) { setSeasonCount(count); if (count > 0 && selectedSeason > count) setSelectedSeason(1); } })(); return () => { active = false; }; }, [showId, fetchSeasonCount]); 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); } catch { if (active) setPError("Fehler beim Laden"); } finally { if (active) setPLoading(false); } })(); return () => { active = false; }; }, [showId, selectedSeason, fetchSeasonParticipants]); return ( setSelectedParticipants(true)}> Teilnehmer setSelectedParticipants(false)}> Details {selectedParticipants ? ( <> Staffeln {Array.from({ length: seasonCount }, (_, idx) => idx + 1).map( (season) => ( setSelectedSeason(season)} > {season} ) )} {pError && ( {pError} )} {!pLoading && !pError && participants.length === 0 && ( Keine Teilnehmer. )} {participants.map((p) => ( router.push({ pathname: "/participant", params: { participantId: p.id, name: p.name, }, }) } > {p.name} ))} ) : ( )} ); }