import { ActionSheetProvider, useActionSheet, } from "@expo/react-native-action-sheet"; import type { BaseItemDto } from "@jellyfin/sdk/lib/generated-client/models"; import type React from "react"; import { useCallback, useMemo } from "react"; import { TouchableOpacity, type TouchableOpacityProps, View, } from "react-native"; import { Text } from "@/components/common/Text"; import { DownloadSize } from "@/components/downloads/DownloadSize"; import { useDownloadedFileOpener } from "@/hooks/useDownloadedFileOpener"; import { useHaptic } from "@/hooks/useHaptic"; import { useDownload } from "@/providers/DownloadProvider"; import { storage } from "@/utils/mmkv"; import { runtimeTicksToSeconds } from "@/utils/time"; import ContinueWatchingPoster from "../ContinueWatchingPoster"; interface EpisodeCardProps extends TouchableOpacityProps { item: BaseItemDto; } export const EpisodeCard: React.FC = ({ item }) => { const { deleteFile } = useDownload(); const { openFile } = useDownloadedFileOpener(); const { showActionSheetWithOptions } = useActionSheet(); const successHapticFeedback = useHaptic("success"); const _base64Image = useMemo(() => { return storage.getString(item.Id!); }, [item]); const handleOpenFile = useCallback(() => { openFile(item); }, [item, openFile]); /** * Handles deleting the file with haptic feedback. */ const handleDeleteFile = useCallback(() => { if (item.Id) { deleteFile(item.Id); successHapticFeedback(); } }, [deleteFile, item.Id]); const showActionSheet = useCallback(() => { const options = ["Delete", "Cancel"]; const destructiveButtonIndex = 0; const cancelButtonIndex = 1; showActionSheetWithOptions( { options, cancelButtonIndex, destructiveButtonIndex, }, (selectedIndex) => { switch (selectedIndex) { case destructiveButtonIndex: // Delete handleDeleteFile(); break; case cancelButtonIndex: // Cancelled break; } }, ); }, [showActionSheetWithOptions, handleDeleteFile]); return ( {item.Name} {`S${item.ParentIndexNumber?.toString()}:E${item.IndexNumber?.toString()}`} {runtimeTicksToSeconds(item.RunTimeTicks)} {item.Overview} ); }; // Wrap the parent component with ActionSheetProvider export const EpisodeCardWithActionSheet: React.FC = ( props, ) => ( );