update: gemini fixes
This commit is contained in:
@@ -1,7 +1,6 @@
|
||||
import { getPersonHistory, type PersonMini } from "@/apis/personHistoryApi";
|
||||
import { getShowById } from "@/apis/showApi";
|
||||
import { PersonMini } from "@/apis/personHistoryApi";
|
||||
import styles from "@/app/stackStyles/participantStyles";
|
||||
import { useShowContext } from "@/contexts/ShowContext";
|
||||
import { usePersonHistory, AppearanceGroup } from "@/hooks/usePersonHistory";
|
||||
import Ionicons from "@expo/vector-icons/Ionicons";
|
||||
import { router, useLocalSearchParams } from "expo-router";
|
||||
import * as WebBrowser from "expo-web-browser";
|
||||
@@ -12,35 +11,14 @@ import {
|
||||
ScrollView,
|
||||
} from "react-native-gesture-handler";
|
||||
|
||||
type SeasonEntry = {
|
||||
seasonNumber: number;
|
||||
partner: PersonMini | null;
|
||||
participants: PersonMini[];
|
||||
startDate: string | null;
|
||||
};
|
||||
|
||||
type AppearanceGroup = {
|
||||
show: {
|
||||
id: number;
|
||||
title: string;
|
||||
bannerUri: string;
|
||||
thumbnailUri: string;
|
||||
};
|
||||
seasons: SeasonEntry[];
|
||||
};
|
||||
|
||||
export default function ParticipantScreen() {
|
||||
const { shows } = useShowContext();
|
||||
const { name, participantId } = useLocalSearchParams();
|
||||
|
||||
const pid = Array.isArray(participantId)
|
||||
? Number(participantId[0])
|
||||
: Number(participantId);
|
||||
|
||||
const [, setLoading] = React.useState(false);
|
||||
const [, setError] = React.useState<string | null>(null);
|
||||
|
||||
const [appearances, setAppearances] = React.useState<AppearanceGroup[]>([]);
|
||||
const { data: appearances = [], isLoading, isError } = usePersonHistory(pid);
|
||||
|
||||
const formatYear = (iso?: string | null) => {
|
||||
if (!iso) return null;
|
||||
@@ -48,104 +26,6 @@ export default function ParticipantScreen() {
|
||||
return y || null;
|
||||
};
|
||||
|
||||
React.useEffect(() => {
|
||||
if (!pid || Number.isNaN(pid)) return;
|
||||
const controller = new AbortController();
|
||||
setLoading(true);
|
||||
setError(null);
|
||||
|
||||
(async () => {
|
||||
try {
|
||||
const hist = await getPersonHistory(pid, controller.signal);
|
||||
|
||||
const grouped = new Map<number, Map<number, SeasonEntry>>();
|
||||
for (const h of hist) {
|
||||
if (!Number.isFinite(h.showId) || h.showId <= 0) continue;
|
||||
const seasonsForShow =
|
||||
grouped.get(h.showId) ?? new Map<number, SeasonEntry>();
|
||||
|
||||
const existing = seasonsForShow.get(h.seasonNumber);
|
||||
if (existing) {
|
||||
seasonsForShow.set(h.seasonNumber, {
|
||||
seasonNumber: h.seasonNumber,
|
||||
partner: existing.partner ?? h.partner ?? null,
|
||||
participants: existing.participants.length
|
||||
? existing.participants
|
||||
: (h.seasonParticipants ?? []),
|
||||
startDate: existing.startDate ?? h.startDate ?? null,
|
||||
});
|
||||
} else {
|
||||
seasonsForShow.set(h.seasonNumber, {
|
||||
seasonNumber: h.seasonNumber,
|
||||
partner: h.partner ?? null,
|
||||
participants: h.seasonParticipants ?? [],
|
||||
startDate: h.startDate ?? null,
|
||||
});
|
||||
}
|
||||
|
||||
grouped.set(h.showId, seasonsForShow);
|
||||
}
|
||||
|
||||
const showIds = Array.from(grouped.keys());
|
||||
|
||||
const fromContext = showIds
|
||||
.map((id) => shows.find((s) => s.id === id))
|
||||
.filter((s): s is (typeof shows)[number] => !!s);
|
||||
|
||||
const missingIds = showIds.filter(
|
||||
(id) => !fromContext.some((s) => s.id === id)
|
||||
);
|
||||
|
||||
const fetched = await Promise.all(
|
||||
missingIds.map(async (id) => {
|
||||
try {
|
||||
const s = await getShowById(id);
|
||||
return s;
|
||||
} catch {
|
||||
return null;
|
||||
}
|
||||
})
|
||||
);
|
||||
|
||||
const allShows = [
|
||||
...fromContext,
|
||||
...fetched.filter(Boolean),
|
||||
] as typeof shows;
|
||||
|
||||
const result: AppearanceGroup[] = allShows.map((s) => {
|
||||
const seasonsMap = grouped.get(s.id)!;
|
||||
const seasonsSorted = Array.from(seasonsMap.values()).sort(
|
||||
(a, b) => a.seasonNumber - b.seasonNumber
|
||||
);
|
||||
return {
|
||||
show: {
|
||||
id: s.id,
|
||||
title: s.title,
|
||||
bannerUri: s.bannerUri,
|
||||
thumbnailUri: s.thumbnailUri,
|
||||
},
|
||||
seasons: seasonsSorted,
|
||||
};
|
||||
});
|
||||
|
||||
result.sort((a, b) =>
|
||||
a.show.title.localeCompare(b.show.title, "de", {
|
||||
sensitivity: "base",
|
||||
})
|
||||
);
|
||||
|
||||
setAppearances(result);
|
||||
} catch (e: any) {
|
||||
if (!controller.signal.aborted)
|
||||
setError(e?.message || "Fehler beim Laden");
|
||||
} finally {
|
||||
if (!controller.signal.aborted) setLoading(false);
|
||||
}
|
||||
})();
|
||||
|
||||
return () => controller.abort();
|
||||
}, [pid, shows]);
|
||||
|
||||
const [expandedShows, setExpandedShows] = React.useState<Set<number>>(
|
||||
new Set()
|
||||
);
|
||||
|
||||
Reference in New Issue
Block a user