import { BaseItemDto } from "@jellyfin/sdk/lib/generated-client/models"; import * as Haptics from "expo-haptics"; import React, { useCallback, useMemo } from "react"; import { TouchableOpacity, View } from "react-native"; import { ActionSheetProvider, useActionSheet, } from "@expo/react-native-action-sheet"; import { runtimeTicksToMinutes } from "@/utils/time"; import { Text } from "../common/Text"; import { useFileOpener } from "@/hooks/useDownloadedFileOpener"; import { useDownload } from "@/providers/DownloadProvider"; import { storage } from "@/utils/mmkv"; import { Image } from "expo-image"; import { Ionicons } from "@expo/vector-icons"; import { ItemCardText } from "../ItemCardText"; interface MovieCardProps { item: BaseItemDto; } /** * MovieCard component displays a movie with action sheet options. * @param {MovieCardProps} props - The component props. * @returns {React.ReactElement} The rendered MovieCard component. */ export const MovieCard: React.FC = ({ item }) => { const { deleteFile } = useDownload(); const { openFile } = useFileOpener(); const { showActionSheetWithOptions } = useActionSheet(); const handleOpenFile = useCallback(() => { openFile(item); }, [item, openFile]); const base64Image = useMemo(() => { return storage.getString(item.Id!); }, []); /** * Handles deleting the file with haptic feedback. */ const handleDeleteFile = useCallback(() => { if (item.Id) { deleteFile(item.Id); Haptics.notificationAsync(Haptics.NotificationFeedbackType.Success); } }, [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 ( {base64Image ? ( ) : ( )} ); }; // Wrap the parent component with ActionSheetProvider export const MovieCardWithActionSheet: React.FC = (props) => ( );