import type { MediaSourceInfo } from "@jellyfin/sdk/lib/generated-client/models"; import { useMemo, useState } from "react"; import { useTranslation } from "react-i18next"; import { Platform, TouchableOpacity, View } from "react-native"; import { Text } from "./common/Text"; import { FilterSheet } from "./filters/FilterSheet"; interface Props extends React.ComponentProps { source?: MediaSourceInfo; onChange: (value: number) => void; selected?: number | undefined; streamType?: string; title: string; } export const TrackSheet: React.FC = ({ source, onChange, selected, streamType, title, ...props }) => { const isTv = Platform.isTV; const { t } = useTranslation(); const streams = useMemo( () => source?.MediaStreams?.filter((x) => x.Type === streamType), [source], ); const selectedSteam = useMemo( () => streams?.find((x) => x.Index === selected), [streams, selected], ); const noneOption = useMemo( () => ({ Index: -1, DisplayTitle: t("common.none") }), [t], ); // Creates a modified data array that includes a "None" option for subtitles // We might want to possibly do this for other places, like audio? const addNoneToSubtitles = useMemo(() => { if (streamType === "Subtitle") { const result = streams ? [noneOption, ...streams] : [noneOption]; return result; } return streams; }, [streams, streamType, noneOption]); const [open, setOpen] = useState(false); if (isTv || (streams && streams.length === 0)) return null; return ( {title} setOpen(true)} > {selected === -1 && streamType === "Subtitle" ? t("common.none") : selectedSteam?.DisplayTitle || t("common.select", "Select")} { const label = (item as any).DisplayTitle || ""; return label.toLowerCase().includes(query.toLowerCase()); }} renderItemLabel={(item) => ( {(item as any).DisplayTitle || ""} )} set={(vals) => { const chosen = vals[0] as any; if (chosen && chosen.Index !== null && chosen.Index !== undefined) { onChange(chosen.Index); } }} /> ); };