update: gemini fixes
This commit is contained in:
@@ -1,13 +1,15 @@
|
||||
import { getShowById, Show } from "@/apis/showApi";
|
||||
|
||||
import ParticipantDetails from "@/components/ui/ParticipantDeatails";
|
||||
|
||||
import ShowInfo from "@/components/ui/ShowInfo";
|
||||
import StackHeader from "@/components/ui/StackHeader";
|
||||
import { useSeasonContext } from "@/contexts/SeasonContext";
|
||||
import {
|
||||
useSeasonCount,
|
||||
useSeasonDates,
|
||||
useSeasonParticipants,
|
||||
} from "@/hooks/useSeason";
|
||||
import { useShow } from "@/hooks/useShow";
|
||||
import * as Haptics from "expo-haptics";
|
||||
import { router, useLocalSearchParams } from "expo-router";
|
||||
import React, { useState } from "react";
|
||||
import React from "react";
|
||||
import {
|
||||
Dimensions,
|
||||
Image,
|
||||
@@ -19,93 +21,34 @@ import {
|
||||
import styles from "./stackStyles/showDetailStyles";
|
||||
|
||||
export default function ShowDetails() {
|
||||
const {
|
||||
// bannerUri,
|
||||
// description,
|
||||
// concept,
|
||||
// genres,
|
||||
// streamingService,
|
||||
id,
|
||||
// endDate,
|
||||
} = useLocalSearchParams();
|
||||
|
||||
const [show, setShow] = useState<Show | null>(null);
|
||||
const [, setLoading] = useState(true);
|
||||
const { id } = useLocalSearchParams();
|
||||
const showId = Number(id);
|
||||
|
||||
const [selectedParticipants, setSelectedParticipants] =
|
||||
React.useState<boolean>(true);
|
||||
const [selectedSeason, setSelectedSeason] = React.useState<number>(1);
|
||||
const showId = Number(id);
|
||||
const { fetchSeasonParticipants, fetchSeasonCount, fetchSeasonDates } =
|
||||
useSeasonContext();
|
||||
const [seasonCount, setSeasonCount] = React.useState<number>(0);
|
||||
const [participants, setParticipants] = React.useState<
|
||||
{ id: number; name: string; imageUri: string }[]
|
||||
>([]);
|
||||
const [startDate, setStartDate] = React.useState<string | undefined>(
|
||||
undefined
|
||||
);
|
||||
const [pLoading, setPLoading] = React.useState(false);
|
||||
const [pError, setPError] = React.useState<string | null>(null);
|
||||
|
||||
const { data: show } = useShow(showId);
|
||||
const { data: seasonCount = 0 } = useSeasonCount(showId);
|
||||
const {
|
||||
data: participants,
|
||||
isLoading: pLoading,
|
||||
isError: pError,
|
||||
} = useSeasonParticipants(showId, selectedSeason);
|
||||
const { data: dates } = useSeasonDates(showId, selectedSeason);
|
||||
const startDate = dates?.startDate;
|
||||
|
||||
const sortedParticipants = React.useMemo(() => {
|
||||
return participants.sort((a, b) =>
|
||||
return [...participants].sort((a, b) =>
|
||||
a.name.localeCompare(b.name, "de", { sensitivity: "base" })
|
||||
);
|
||||
}, [participants]);
|
||||
|
||||
React.useEffect(() => {
|
||||
if (!showId) return;
|
||||
|
||||
const fetchShow = async () => {
|
||||
try {
|
||||
const data = await getShowById(showId);
|
||||
setShow(data);
|
||||
} finally {
|
||||
setLoading(false);
|
||||
}
|
||||
};
|
||||
|
||||
fetchShow();
|
||||
|
||||
let active = true;
|
||||
(async () => {
|
||||
const count = await fetchSeasonCount(showId);
|
||||
if (active) {
|
||||
setSeasonCount(count);
|
||||
if (count > 0 && selectedSeason > count) setSelectedSeason(1);
|
||||
}
|
||||
})();
|
||||
return () => {
|
||||
active = false;
|
||||
};
|
||||
}, [showId, fetchSeasonCount, selectedSeason]);
|
||||
|
||||
React.useEffect(() => {
|
||||
if (!showId || !selectedSeason) return;
|
||||
let active = true;
|
||||
(async () => {
|
||||
setPError(null);
|
||||
setPLoading(true);
|
||||
try {
|
||||
const [data, dates] = await Promise.all([
|
||||
fetchSeasonParticipants(showId, selectedSeason),
|
||||
fetchSeasonDates(showId, selectedSeason),
|
||||
]);
|
||||
if (active) {
|
||||
setParticipants(data);
|
||||
setStartDate(dates?.startDate);
|
||||
}
|
||||
} catch {
|
||||
if (active) setPError("Fehler beim Laden");
|
||||
} finally {
|
||||
if (active) setPLoading(false);
|
||||
}
|
||||
})();
|
||||
return () => {
|
||||
active = false;
|
||||
};
|
||||
}, [showId, selectedSeason, fetchSeasonParticipants, fetchSeasonDates]);
|
||||
if (seasonCount > 0 && selectedSeason > seasonCount) {
|
||||
setSelectedSeason(1);
|
||||
}
|
||||
}, [seasonCount, selectedSeason]);
|
||||
|
||||
const formattedStartDate = React.useMemo(() => {
|
||||
if (!startDate) return "";
|
||||
|
||||
Reference in New Issue
Block a user