updated search

This commit is contained in:
DevOFVictory
2025-10-23 18:49:01 +02:00
parent 0fbe217fce
commit 30dab9051a
6 changed files with 76 additions and 70 deletions

View File

@@ -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<number, Season[]>();
@@ -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<number, Show> = {};
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 (
<View style={[styles.mainContainer]}>
<View style={[styles.mainContainer]}>
<View style={styles.header}>
<Text style={[styles.title, { fontSize: 28 }]}>Durchsuchen</Text>
</View>
@@ -188,7 +194,7 @@ export default function ExploreScreen() {
<View style={{ width: "100%", paddingHorizontal: 10, marginBottom: 12 }}>
<Text style={{ color: "white", fontSize: 18, fontWeight: "600", marginBottom: 6 }}>Personen</Text>
{persons.slice(0, 5).map((p) => (
<PersonRow key={`p-${p.personId ?? p.id}`} person={p} />
<PersonRow key={`p-${p.personId ?? p.id}`} person={p}/>
))}
</View>
)}
@@ -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 (
<SeasonCarousel
key={`sc-${showId}`}
show={{ showId: showId as any, title: "blaaa", description: "", genre: "", thumbnailUrl: "", running: false } as any}
seasons={seasons}
renderItem={(s) => <ShowBox show={{ showId: showId as any, title: `Show #${showId}`, description: "", genre: "", thumbnailUrl: "", running: false } as any} displayedSeason={s} shadow={false} />}
/>
<SeasonCarousel
key={`sc-${showId}`}
show={{ showId: showId as any, title: "blaaa", description: "", genre: "", thumbnailUrl: "", running: false } as any}
seasons={seasons}
renderItem={(s) => <ShowBox show={{ showId: showId as any, title: `Show #${showId}`, description: "", genre: "", thumbnailUrl: "", running: false } as any} displayedSeason={s} shadow={false} />}
/>
);
}
return (
<SeasonCarousel
key={`sc-${showId}`}
show={show}
seasons={seasons}
renderItem={(s) => <ShowBox show={show} displayedSeason={s} shadow={false} />}
/>
<SeasonCarousel
key={`sc-${showId}`}
show={show}
seasons={seasons}
renderItem={(s) => <ShowBox show={show} displayedSeason={s} shadow={false} />}
/>
);
})}

View File

@@ -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
};