import { View, Image, Text, TouchableOpacity } from "react-native"; import styles from "@/app/stackStyles/participantStyles"; import Ionicons from "@expo/vector-icons/Ionicons"; import React, { useEffect, useMemo, useState } from "react"; import { router, useLocalSearchParams } from "expo-router"; import { usePersonContext } from "@/contexts/PersonContext"; import { ScrollView, GestureHandlerRootView, } from "react-native-gesture-handler"; import { useShowContext } from "@/contexts/ShowContext"; import { getPersonHistory } from "@/apis/personApi"; export default function ParticipantScreen() { const { getPersonAppearances, isLoading, getError } = usePersonContext(); const [appearances, setAppearances] = useState< { showId: number; seasons: number[]; }[] >([]); const { shows, error, loading } = useShowContext(); const { participantId, name, season } = useLocalSearchParams(); const numericId = Array.isArray(participantId) ? Number(participantId[0]) : Number(participantId); useEffect(() => { let active = true; (async () => { if (!numericId || Number.isNaN(numericId)) return; const data = await getPersonAppearances(numericId); if (!active) return; const grouped = data.showIds.map((id) => ({ showId: id, seasons: data.byShow[id], })); setAppearances(grouped); })(); return () => { active = false; }; }, [numericId, getPersonAppearances]); const resolved = useMemo( () => appearances .map((a) => { const show = shows.find((s) => s.id === a.showId); if (!show) return null; return { show, seasons: a.seasons }; }) .filter( (v): v is { show: (typeof shows)[number]; seasons: number[] } => !!v ), [appearances, shows] ); return ( {name ? (Array.isArray(name) ? name[0] : name) : "Teilnehmer"} router.back()} > Single 24 Jahre Köln Auftritte: {isLoading(numericId) && ( Lädt... )} {getError(numericId) && ( {getError(numericId)} )} {!isLoading(numericId) && resolved.length === 0 && !getError(numericId) && ( Keine Einträge. )} {resolved.map(({ show, seasons }) => ( {show.title} Staffel {seasons.length === 1 ? ` ${seasons[0]}` : `n ${seasons.join(", ")}`} ))} ); }