import { Ionicons } from "@expo/vector-icons"; import type { BaseItemDto } from "@jellyfin/sdk/lib/generated-client/models"; import { Image } from "expo-image"; import { useAtomValue } from "jotai"; import type React from "react"; import { useMemo } from "react"; import { View } from "react-native"; import { apiAtom } from "@/providers/JellyfinProvider"; import { ProgressBar } from "./common/ProgressBar"; import { WatchedIndicator } from "./WatchedIndicator"; type ContinueWatchingPosterProps = { item: BaseItemDto; useEpisodePoster?: boolean; size?: "small" | "normal"; showPlayButton?: boolean; }; const ContinueWatchingPoster: React.FC = ({ item, useEpisodePoster = false, size = "normal", showPlayButton = false, }) => { const api = useAtomValue(apiAtom); /** * Get horizontal poster for movie and episode, with failover to primary. */ const url = useMemo(() => { if (!api) { return; } if (item.Type === "Episode" && useEpisodePoster) { return `${api?.basePath}/Items/${item.Id}/Images/Primary?fillHeight=389&quality=80`; } if (item.Type === "Episode") { // Matched pair: the parent that owns the Thumb (ParentThumbItemId), not the // backdrop owner — otherwise the Thumb tag is requested on the wrong item → black. if (item.ParentThumbItemId && item.ParentThumbImageTag) { return `${api?.basePath}/Items/${item.ParentThumbItemId}/Images/Thumb?fillHeight=389&quality=80&tag=${item.ParentThumbImageTag}`; } return `${api?.basePath}/Items/${item.Id}/Images/Primary?fillHeight=389&quality=80`; } if (item.Type === "Movie") { if (item.ImageTags?.Thumb) { return `${api?.basePath}/Items/${item.Id}/Images/Thumb?fillHeight=389&quality=80&tag=${item.ImageTags?.Thumb}`; } return `${api?.basePath}/Items/${item.Id}/Images/Primary?fillHeight=389&quality=80`; } if (item.Type === "Program") { if (item.ImageTags?.Thumb) { return `${api?.basePath}/Items/${item.Id}/Images/Thumb?fillHeight=389&quality=80&tag=${item.ImageTags?.Thumb}`; } return `${api?.basePath}/Items/${item.Id}/Images/Primary?fillHeight=389&quality=80`; } if (item.ImageTags?.Thumb) { return `${api?.basePath}/Items/${item.Id}/Images/Thumb?fillHeight=389&quality=80&tag=${item.ImageTags?.Thumb}`; } return `${api?.basePath}/Items/${item.Id}/Images/Primary?fillHeight=389&quality=80`; // useEpisodePoster in deps so flipping the setting re-computes the URL live // (no app restart needed). }, [item, useEpisodePoster]); if (!url) return ; return ( {showPlayButton && ( )} {!item.UserData?.Played && } ); }; export default ContinueWatchingPoster;