diff --git a/app/(auth)/(tabs)/(home)/downloads/[seriesId].tsx b/app/(auth)/(tabs)/(home)/downloads/[seriesId].tsx index 2699354d..9de3b673 100644 --- a/app/(auth)/(tabs)/(home)/downloads/[seriesId].tsx +++ b/app/(auth)/(tabs)/(home)/downloads/[seriesId].tsx @@ -1,37 +1,48 @@ -import {Text} from "@/components/common/Text"; -import {useDownload} from "@/providers/DownloadProvider"; -import {router, useLocalSearchParams, useNavigation} from "expo-router"; -import React, {useCallback, useEffect, useMemo, useState} from "react"; -import {ScrollView, TouchableOpacity, View} from "react-native"; -import {EpisodeCard} from "@/components/downloads/EpisodeCard"; -import {BaseItemDto} from "@jellyfin/sdk/lib/generated-client/models"; -import {SeasonDropdown, SeasonIndexState} from "@/components/series/SeasonDropdown"; -import {storage} from "@/utils/mmkv"; -import {Ionicons} from "@expo/vector-icons"; +import { Text } from "@/components/common/Text"; +import { useDownload } from "@/providers/DownloadProvider"; +import { router, useLocalSearchParams, useNavigation } from "expo-router"; +import React, { useCallback, useEffect, useMemo, useState } from "react"; +import { ScrollView, TouchableOpacity, View } from "react-native"; +import { EpisodeCard } from "@/components/downloads/EpisodeCard"; +import { BaseItemDto } from "@jellyfin/sdk/lib/generated-client/models"; +import { + SeasonDropdown, + SeasonIndexState, +} from "@/components/series/SeasonDropdown"; +import { storage } from "@/utils/mmkv"; +import { Ionicons } from "@expo/vector-icons"; export default function page() { const navigation = useNavigation(); const local = useLocalSearchParams(); - const {seriesId, episodeSeasonIndex} = local as { - seriesId: string, - episodeSeasonIndex: number | string | undefined + const { seriesId, episodeSeasonIndex } = local as { + seriesId: string; + episodeSeasonIndex: number | string | undefined; }; - const [seasonIndexState, setSeasonIndexState] = useState({}); - const {downloadedFiles, deleteItems} = useDownload(); + const [seasonIndexState, setSeasonIndexState] = useState( + {} + ); + const { downloadedFiles, deleteItems } = useDownload(); const series = useMemo(() => { try { - return downloadedFiles + return ( + downloadedFiles ?.filter((f) => f.item.SeriesId == seriesId) - ?.sort((a, b) => a?.item.ParentIndexNumber! - b.item.ParentIndexNumber!) - || []; + ?.sort( + (a, b) => a?.item.ParentIndexNumber! - b.item.ParentIndexNumber! + ) || [] + ); } catch { return []; } }, [downloadedFiles]); - const seasonIndex = seasonIndexState[series?.[0]?.item?.ParentId ?? ""] || episodeSeasonIndex || ""; + const seasonIndex = + seasonIndexState[series?.[0]?.item?.ParentId ?? ""] || + episodeSeasonIndex || + ""; const groupBySeason = useMemo(() => { const seasons: Record = {}; @@ -43,13 +54,16 @@ export default function page() { seasons[episode.item.ParentIndexNumber!].push(episode.item); }); - return seasons[seasonIndex] - ?.sort((a, b) => a.IndexNumber! - b.IndexNumber!) - ?? [] + return ( + seasons[seasonIndex]?.sort((a, b) => a.IndexNumber! - b.IndexNumber!) ?? + [] + ); }, [series, seasonIndex]); - const initialSeasonIndex = useMemo(() => - Object.values(groupBySeason)?.[0]?.ParentIndexNumber ?? series?.[0]?.item?.ParentIndexNumber, + const initialSeasonIndex = useMemo( + () => + Object.values(groupBySeason)?.[0]?.ParentIndexNumber ?? + series?.[0]?.item?.ParentIndexNumber, [groupBySeason] ); @@ -58,8 +72,7 @@ export default function page() { navigation.setOptions({ title: series[0].item.SeriesName, }); - } - else { + } else { storage.delete(seriesId); router.back(); } @@ -70,37 +83,38 @@ export default function page() { [groupBySeason] ); return ( - <> - {series.length > 0 && - s.item)} - state={seasonIndexState} - initialSeasonIndex={initialSeasonIndex!} - onSelect={(season) => { - setSeasonIndexState((prev) => ({ - ...prev, - [series[0].item.ParentId ?? ""]: season.ParentIndexNumber, - })); - }}/> - - - {groupBySeason.length} - - - - - - + + {series.length > 0 && ( + + s.item)} + state={seasonIndexState} + initialSeasonIndex={initialSeasonIndex!} + onSelect={(season) => { + setSeasonIndexState((prev) => ({ + ...prev, + [series[0].item.ParentId ?? ""]: season.ParentIndexNumber, + })); + }} + /> + + {groupBySeason.length} - } + + + + + + + )} {groupBySeason.map((episode, index) => ( - - + + ))} - + ); -} \ No newline at end of file +} diff --git a/components/series/SeasonDropdown.tsx b/components/series/SeasonDropdown.tsx index 1d007c64..574048d4 100644 --- a/components/series/SeasonDropdown.tsx +++ b/components/series/SeasonDropdown.tsx @@ -44,7 +44,11 @@ export const SeasonDropdown: React.FC = ({ }, [item] ); - const seasonIndex = useMemo(() => state[item[keys.id] ?? ""], [state]); + + const seasonIndex = useMemo( + () => state[(item[keys.id] as string) ?? ""], + [state] + ); useEffect(() => { if (seasons && seasons.length > 0 && seasonIndex === undefined) { @@ -80,12 +84,12 @@ export const SeasonDropdown: React.FC = ({ }, [seasons, seasonIndex, item[keys.id], initialSeasonIndex]); const sortByIndex = (a: BaseItemDto, b: BaseItemDto) => - a[keys.index] - b[keys.index]; + Number(a[keys.index]) - Number(b[keys.index]); return ( - + Season {seasonIndex}