import { apiAtom } from "@/providers/JellyfinProvider"; 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 { useMemo } from "react"; import type React from "react"; import { View } from "react-native"; 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") { if (item.ParentBackdropItemId && item.ParentThumbImageTag) { return `${api?.basePath}/Items/${item.ParentBackdropItemId}/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`; }, [item]); const progress = useMemo(() => { if (item.Type === "Program") { const startDate = new Date(item.StartDate || ""); const endDate = new Date(item.EndDate || ""); const now = new Date(); const total = endDate.getTime() - startDate.getTime(); const elapsed = now.getTime() - startDate.getTime(); return (elapsed / total) * 100; } return item.UserData?.PlayedPercentage || 0; }, [item]); if (!url) return ; return ( {showPlayButton && ( )} {!progress && } {progress > 0 && ( <> )} ); }; export default ContinueWatchingPoster;