From 222ba13529fedf8ece4afd3aa4ca3e75dbdefc41 Mon Sep 17 00:00:00 2001 From: Fredrik Burmester Date: Tue, 11 Nov 2025 09:51:10 +0100 Subject: [PATCH] fix: episode list --- .../(tabs)/(home)/downloads/[seriesId].tsx | 82 ++++++++++++------- 1 file changed, 52 insertions(+), 30 deletions(-) diff --git a/app/(auth)/(tabs)/(home)/downloads/[seriesId].tsx b/app/(auth)/(tabs)/(home)/downloads/[seriesId].tsx index 14ec23ec..e870f5c0 100644 --- a/app/(auth)/(tabs)/(home)/downloads/[seriesId].tsx +++ b/app/(auth)/(tabs)/(home)/downloads/[seriesId].tsx @@ -4,6 +4,7 @@ import { FlashList } from "@shopify/flash-list"; import { router, useLocalSearchParams, useNavigation } from "expo-router"; import { useCallback, useEffect, useMemo, useState } from "react"; import { Alert, Platform, TouchableOpacity, View } from "react-native"; +import { useSafeAreaInsets } from "react-native-safe-area-context"; import { Text } from "@/components/common/Text"; import { EpisodeCard } from "@/components/downloads/EpisodeCard"; import { @@ -25,6 +26,7 @@ export default function page() { {}, ); const { downloadedItems, deleteItems } = useDownload(); + const insets = useSafeAreaInsets(); const series = useMemo(() => { try { @@ -72,8 +74,9 @@ export default function page() { }, [seasonGroups]); const seasonIndex = - seasonIndexState[series?.[0]?.item?.ParentId ?? ""] || - episodeSeasonIndex || + seasonIndexState[series?.[0]?.item?.ParentId ?? ""] ?? + episodeSeasonIndex ?? + series?.[0]?.item?.ParentIndexNumber ?? ""; const groupBySeason = useMemo(() => { @@ -82,9 +85,9 @@ export default function page() { const initialSeasonIndex = useMemo( () => - Object.values(groupBySeason)?.[0]?.ParentIndexNumber ?? + groupBySeason?.[0]?.ParentIndexNumber ?? series?.[0]?.item?.ParentIndexNumber, - [groupBySeason], + [groupBySeason, series], ); useEffect(() => { @@ -121,38 +124,57 @@ export default function page() { ); }, [groupBySeason, deleteItems]); - return ( - - {series.length > 0 && ( - - { - setSeasonIndexState((prev) => ({ - ...prev, - [series[0].item.ParentId ?? ""]: season.ParentIndexNumber, - })); - }} - /> - - {groupBySeason.length} - - - - - - + const ListHeaderComponent = useCallback(() => { + if (series.length === 0) return null; + + return ( + + { + setSeasonIndexState((prev) => ({ + ...prev, + [series[0].item.ParentId ?? ""]: season.ParentIndexNumber, + })); + }} + /> + + {groupBySeason.length} - )} + + + + + + + ); + }, [ + series, + uniqueSeasons, + seasonIndexState, + initialSeasonIndex, + groupBySeason, + deleteSeries, + ]); + + return ( + } keyExtractor={(item, index) => item.Id ?? `episode-${index}`} - contentContainerStyle={{ paddingHorizontal: 16 }} + ListHeaderComponent={ListHeaderComponent} + contentInsetAdjustmentBehavior='automatic' + contentContainerStyle={{ + paddingHorizontal: 16, + paddingLeft: insets.left + 16, + paddingRight: insets.right + 16, + paddingTop: Platform.OS === "android" ? 10 : 8, + }} /> );