import { apiAtom } from "@/providers/JellyfinProvider"; import { BaseItemDto } from "@jellyfin/sdk/lib/generated-client/models"; import { Image } from "expo-image"; import { useAtom } from "jotai"; import { useMemo, useState } from "react"; import { View } from "react-native"; import { WatchedIndicator } from "./WatchedIndicator"; type ContinueWatchingPosterProps = { item: BaseItemDto; width?: number; }; const ContinueWatchingPoster: React.FC = ({ item, width = 176, }) => { const [api] = useAtom(apiAtom); /** * Get horrizontal poster for movie and episode, with failover to primary. */ const url = useMemo(() => { if (!api) return; if (item.Type === "Episode") { if (item.ParentBackdropItemId && item.ParentThumbImageTag) return `${api?.basePath}/Items/${item.ParentBackdropItemId}/Images/Thumb?fillHeight=389&quality=80&tag=${item.ParentThumbImageTag}`; else 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"]}`; else return `${api?.basePath}/Items/${item.Id}/Images/Primary?fillHeight=389&quality=80`; } }, [item]); const [progress, setProgress] = useState( item.UserData?.PlayedPercentage || 0 ); if (!url) return ( ); return ( {!progress && } {progress > 0 && ( <> )} ); }; export default ContinueWatchingPoster;