fixed search

This commit is contained in:
DevOFVictory
2025-11-12 19:25:21 +01:00
parent b287f19686
commit 9516642beb
2 changed files with 32 additions and 7 deletions

View File

@@ -39,7 +39,6 @@ export default function ExploreScreen() {
data: results = [], data: results = [],
error, error,
refetch, refetch,
// isLoading, // optional, falls benötigt
} = useSearch(tagStrings as string[]); } = useSearch(tagStrings as string[]);
// Lokaler Show-Cache // Lokaler Show-Cache
@@ -67,7 +66,7 @@ export default function ExploreScreen() {
for (const r of results) { for (const r of results) {
if (r.type === "SHOW") { if (r.type === "SHOW") {
const uiShow = mapApiShowToUI(r.data); const uiShow = mapApiShowToUI(r.data);
if (uiShow.showId != null) fromResults[Number(uiShow.showId)] = uiShow as Show; if (uiShow?.showId != null) fromResults[Number(uiShow.showId)] = uiShow as Show;
} }
} }
if (Object.keys(fromResults).length) { if (Object.keys(fromResults).length) {
@@ -135,6 +134,23 @@ export default function ExploreScreen() {
.sort((a, b) => (a.name || "").localeCompare(b.name || "")); .sort((a, b) => (a.name || "").localeCompare(b.name || ""));
}, [results]); }, [results]);
// SHOW-Resultate, die KEINE Staffeln haben -> als einzelne ShowBox anzeigen
const standaloneShows: Show[] = React.useMemo(() => {
const seen = new Set<number>();
const list: Show[] = [];
for (const r of results) {
if (r.type !== "SHOW") continue;
const ui = mapApiShowToUI(r.data) as Show | undefined;
if (!ui?.id) continue;
const id = Number(ui.id);
if (seasonsByShowId.has(id)) continue; // bereits als Carousel vorhanden -> nicht doppelt
if (seen.has(id)) continue;
seen.add(id);
list.push(ui);
}
return list;
}, [results, seasonsByShowId]);
// Moderner Fehlerblock // Moderner Fehlerblock
if (error) { if (error) {
return ( return (
@@ -195,7 +211,8 @@ export default function ExploreScreen() {
); );
} }
const noResults = persons.length === 0 && seasonsByShowId.size === 0; const noResults =
persons.length === 0 && seasonsByShowId.size === 0 && standaloneShows.length === 0;
return ( return (
<View style={[styles.mainContainer]}> <View style={[styles.mainContainer]}>
@@ -301,10 +318,11 @@ export default function ExploreScreen() {
)} )}
<View style={styles.sectionContainer}> <View style={styles.sectionContainer}>
{seasonsByShowId.size > 0 && ( {(seasonsByShowId.size > 0 || standaloneShows.length > 0) && (
<Text style={styles.sectionTitle}>Staffeln</Text> <Text style={styles.sectionTitle}>Staffeln &amp; Shows</Text>
)} )}
{/* Carousels für Shows mit Staffeln */}
{Array.from(seasonsByShowId.entries()).map(([showId, seasons]) => { {Array.from(seasonsByShowId.entries()).map(([showId, seasons]) => {
const show = showsById[Number(showId)]; const show = showsById[Number(showId)];
if (!seasons || seasons.length === 0) return null; if (!seasons || seasons.length === 0) return null;
@@ -355,6 +373,13 @@ export default function ExploreScreen() {
); );
})} })}
{/* Einzelne Shows (ohne Staffeln) */}
{standaloneShows.map((show) => (
<View key={`show-${show.id}`} style={{ marginTop: 12 }}>
<ShowBox show={show} shadow={false} />
</View>
))}
{/* Schöner Empty-State */} {/* Schöner Empty-State */}
{noResults && ( {noResults && (
<View <View

View File

@@ -41,11 +41,11 @@ export function mapApiSeasonToUI(data: any) {
export function mapApiShowToUI(data: any) { export function mapApiShowToUI(data: any) {
return { return {
showId: data?.showId ?? data?.id, id: data.showId ?? data.id, // <-- hier der Fix
title: data?.title ?? data?.name ?? `Show #${data?.showId ?? data?.id ?? "?"}`, title: data?.title ?? data?.name ?? `Show #${data?.showId ?? data?.id ?? "?"}`,
description: data?.description ?? "", description: data?.description ?? "",
genre: data?.genre ?? "", genre: data?.genre ?? "",
thumbnailUrl: data?.thumbnailUrl ?? data?.imageUrl ?? "", thumbnailUri: data?.thumbnailUrl ?? data?.imageUrl ?? "",
running: data?.running ?? false, running: data?.running ?? false,
} as any; } as any;
} }