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 { currentlyPlayingItemAtom, fullScreenAtom, playingAtom, } from "../CurrentlyPlayingBar"; import { useSettings } from "@/utils/atoms/settings"; 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 [, setCurrentlyPlaying] = useAtom(currentlyPlayingItemAtom); const [, setPlaying] = useAtom(playingAtom); const [, setFullscreen] = useAtom(fullScreenAtom); const [settings] = useSettings(); /** * Handles opening the file for playback. */ const handleOpenFile = useCallback(async () => { setCurrentlyPlaying({ item, playbackUrl: `${FileSystem.documentDirectory}/${item.Id}.mp4`, }); setPlaying(true); if (settings?.openFullScreenVideoPlayerByDefault === true) setFullscreen(true); }, [item, setCurrentlyPlaying, settings]); /** * 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} ))} ); };