import React, { useCallback } from "react"; import { TouchableOpacity } from "react-native"; import { BaseItemDto } from "@jellyfin/sdk/lib/generated-client/models"; import * as ContextMenu from "zeego/context-menu"; import * as Haptics from "expo-haptics"; import * as FileSystem from "expo-file-system"; import { useAtom } from "jotai"; import { Text } from "../common/Text"; import { useFiles } from "@/hooks/useFiles"; import { useSettings } from "@/utils/atoms/settings"; import { usePlayback } from "@/providers/PlaybackProvider"; interface EpisodeCardProps { item: BaseItemDto; } /** * EpisodeCard component displays an episode with context menu options. * @param {EpisodeCardProps} props - The component props. * @returns {React.ReactElement} The rendered EpisodeCard component. */ export const EpisodeCard: React.FC = ({ item }) => { const { deleteFile } = useFiles(); const { setCurrentlyPlayingState } = usePlayback(); const handleOpenFile = useCallback(async () => { setCurrentlyPlayingState({ item, url: `${FileSystem.documentDirectory}/${item.Id}.mp4`, }); }, [item, setCurrentlyPlayingState]); /** * 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 contextMenuOptions = [ { label: "Delete", onSelect: handleDeleteFile, destructive: true, }, ]; return ( {item.Name} Episode {item.IndexNumber} {contextMenuOptions.map((option) => ( {option.label} ))} ); };