From 30dab9051ad13bb934088b76f7ad6db8c750f33d Mon Sep 17 00:00:00 2001 From: DevOFVictory <49123418+mafeth@users.noreply.github.com> Date: Thu, 23 Oct 2025 18:49:01 +0200 Subject: [PATCH] updated search --- app/(tabs)/explore.tsx | 46 ++++++++++++++----------- app/types.ts | 32 ----------------- components/discovery/PersonRow.tsx | 25 +++++++++++--- components/discovery/SeasonCarousel.tsx | 11 +++--- components/discovery/ShowBox.tsx | 29 +++++++++++----- utils/searchMapping.ts | 3 +- 6 files changed, 76 insertions(+), 70 deletions(-) delete mode 100644 app/types.ts diff --git a/app/(tabs)/explore.tsx b/app/(tabs)/explore.tsx index d4647c4..16d7214 100644 --- a/app/(tabs)/explore.tsx +++ b/app/(tabs)/explore.tsx @@ -1,7 +1,8 @@ import { AutoCompleteItem } from "@/apis/autoCompleteApi"; import { getSearchResults, SearchResultItem } from "@/apis/searchApi"; +import { Season } from "@/apis/seasonApi"; +import { Show } from "@/apis/showApi"; import styles from "@/app/tabStyles/indexStyles"; -import { Season, Show } from "@/app/types"; import ShowBox from "@/components/discovery/ShowBox"; import { useDiscoveryContext } from "@/contexts/DiscoveryContext"; import { FontAwesome } from "@expo/vector-icons"; @@ -56,6 +57,8 @@ export default function ExploreScreen() { } }, [results]); + + // Group SEASON results by showId const seasonsByShowId = React.useMemo(() => { const map = new Map(); @@ -84,24 +87,27 @@ export default function ExploreScreen() { React.useEffect(() => { const needed = Array.from(seasonsByShowId.keys()).filter((id) => !showsById[id]); if (needed.length === 0) return; + let cancelled = false; (async () => { try { const fetched = await Promise.all(needed.map((id) => getShowById(id))); if (cancelled) return; + const next: Record = {}; for (const s of fetched) { if (!s) continue; - next[Number((s as any).showId)] = s as Show; + next[s.id] = s; // wichtig: s.id, nicht s.showId + } + if (Object.keys(next).length) { + setShowsById((prev) => ({ ...prev, ...next })); } - if (Object.keys(next).length) setShowsById((prev) => ({ ...prev, ...next })); } catch (e) { console.error(e); } })(); - return () => { - cancelled = true; - }; + + return () => { cancelled = true; }; }, [seasonsByShowId, showsById]); // PERSON hits shown at the top (like old screen) @@ -113,7 +119,7 @@ export default function ExploreScreen() { }, [results]); return ( - + Durchsuchen @@ -188,7 +194,7 @@ export default function ExploreScreen() { Personen {persons.slice(0, 5).map((p) => ( - + ))} )} @@ -203,21 +209,21 @@ export default function ExploreScreen() { // If show metadata is not yet loaded, render a minimal ShowBox fallback once per page item if (!show) { return ( - } - /> + } + /> ); } return ( - } - /> + } + /> ); })} diff --git a/app/types.ts b/app/types.ts deleted file mode 100644 index f52b232..0000000 --- a/app/types.ts +++ /dev/null @@ -1,32 +0,0 @@ -export type Person = { -personId: number; -name: string; -birthDate?: string | null; -imageUrl?: string | null; -}; - - - -export type Season = { -seasonId: number; -showId: number; -startDate?: string | null; -endDate?: string | null; -seasonNumber?: number | null; -participants?: Person[]; -moderators?: Person[]; -}; - - -export type Show = { -showId: number; -title: string; -description?: string; -genre?: string; -thumbnailUrl: string; -logoUrl?: string; -bannerUrl?: string; -running?: boolean; -streamingServices?: string; -concept?: string -}; \ No newline at end of file diff --git a/components/discovery/PersonRow.tsx b/components/discovery/PersonRow.tsx index c3919da..2b8e07c 100644 --- a/components/discovery/PersonRow.tsx +++ b/components/discovery/PersonRow.tsx @@ -1,5 +1,6 @@ import { FontAwesome } from "@expo/vector-icons"; import { useNavigation } from "@react-navigation/native"; +import { router } from "expo-router"; import React from "react"; import { StyleSheet, Text, TouchableOpacity, View } from "react-native"; @@ -16,16 +17,32 @@ const calcAge = (birthDate?: string | null): number | null => { return age < 0 || age > 130 ? null : age; }; -export default function PersonRow({ person }: { person: PersonLite }) { +type Props = { + person: any; + onPress?: () => void; +}; + + + +export default function PersonRow({ person, onPress }: Props) { const navigation = useNavigation(); const age = calcAge(person.birthDate); const id = person.personId ?? person.id; + const goToPerson = React.useCallback( + (id: number) => { + console.log("go to person", id); + router.push({ + pathname: "/participant", + params: { participantId: String(id), name: person.name }, + }); + }, [] + ); + return ( { - // If your PersonDetail expects a Person object instead of an id, adapt this accordingly - // navigation.navigate("PersonDetail" as never, { personId: id } as never); + goToPerson(Number(id)); }} style={styles.personRow} > @@ -34,7 +51,7 @@ export default function PersonRow({ person }: { person: PersonLite }) { {person.name || "Unbekannt"}{age != null ? ` (${age})` : ""} - aus: unterschiedlichen Shows + {/* aus: unterschiedlichen Shows */} diff --git a/components/discovery/SeasonCarousel.tsx b/components/discovery/SeasonCarousel.tsx index fe48530..8e9d2d2 100644 --- a/components/discovery/SeasonCarousel.tsx +++ b/components/discovery/SeasonCarousel.tsx @@ -1,4 +1,5 @@ -import { Season, Show } from "@/app/types"; +import { Season } from "@/apis/seasonApi"; +import { Show } from "@/apis/showApi"; import { FontAwesome } from "@expo/vector-icons"; import React from "react"; import { Dimensions, FlatList, LayoutChangeEvent, NativeScrollEvent, NativeSyntheticEvent, Pressable, StyleSheet, View } from "react-native"; @@ -18,7 +19,7 @@ export default function SeasonCarousel({ }) { const [currentIndex, setCurrentIndex] = React.useState(0); const [sliderWidth, setSliderWidth] = React.useState(Math.floor(WINDOW_WIDTH - 20)); - const listRef = React.useRef | null>(null); + const listRef = React.useRef>(null); const onLayout = (e: LayoutChangeEvent) => { const w = Math.max(0, Math.floor(e.nativeEvent.layout.width)); @@ -47,9 +48,9 @@ export default function SeasonCarousel({ return ( (listRef.current = r)} + ref={listRef} data={seasons} - keyExtractor={(season, idx) => `${show.showId}-${(season as any)?.seasonId ?? `season-${idx}`}`} + keyExtractor={(season, idx) => `${show.id}-${(season as any)?.seasonId ?? `season-${idx}`}`} horizontal pagingEnabled showsHorizontalScrollIndicator={false} @@ -71,7 +72,7 @@ export default function SeasonCarousel({ {seasons.map((_, i) => ( - + ))} diff --git a/components/discovery/ShowBox.tsx b/components/discovery/ShowBox.tsx index 31cd1a3..404536e 100644 --- a/components/discovery/ShowBox.tsx +++ b/components/discovery/ShowBox.tsx @@ -1,8 +1,13 @@ -import { Season, Show } from "@/app/types"; -import GenreTag from "@/components/discovery/GenreTag"; +import { Season } from "@/apis/seasonApi"; +import { Show } from "@/apis/showApi"; import { useNavigation } from "@react-navigation/native"; +import { router } from "expo-router"; +import React from "react"; import { Image, StyleSheet, Text, TouchableOpacity, View } from "react-native"; + + + export default function ShowBox({ show, displayedSeason, @@ -14,9 +19,14 @@ export default function ShowBox({ }) { const navigation = useNavigation(); + const goToShow = React.useCallback((id: number) => { + router.push({ pathname: "/showDetails", params: { id: String(id) } }); + }, []); + + return ( navigation.navigate("ShowDetail", { show })} + onPress={() => goToShow(Number(show.id))} style={ !shadow ? [styles.showContainer, { backgroundColor: "#1b1e2b", paddingBottom: 0 }] @@ -24,7 +34,7 @@ export default function ShowBox({ } > - + {show.running && LIVE} @@ -33,19 +43,22 @@ export default function ShowBox({ {displayedSeason ? ( - Staffel {displayedSeason.seasonNumber} ( - {new Date(displayedSeason.startDate).getFullYear()}) + Staffel {displayedSeason.seasonNumber} + {displayedSeason.startDate + ? ` (${new Date(displayedSeason.startDate).getFullYear()})` + : ""} ) : null} + {show.description} - {show.genre.split(", ").map((genre: any) => ( + {/* {show.genres.map((genre: string) => ( {genre} - ))} + ))} */} diff --git a/utils/searchMapping.ts b/utils/searchMapping.ts index f2f7ee3..ae904f3 100644 --- a/utils/searchMapping.ts +++ b/utils/searchMapping.ts @@ -7,8 +7,9 @@ export const getIconName = (type: AutoCompleteItem["type"]) => { case "SHOW": return "television"; case "YEAR": - case "CUSTOM": return "calendar"; + case "CUSTOM": + return "tag"; default: return "tag"; }