import { convertBitsToMegabitsOrGigabits } from "@/utils/bToMb"; import { Ionicons } from "@expo/vector-icons"; import { BaseItemDto, MediaSourceInfo, } from "@jellyfin/sdk/lib/generated-client/models"; import { useMemo, useState } from "react"; import { Modal, TouchableOpacity, View } from "react-native"; import { Text } from "./common/Text"; interface Props extends React.ComponentProps { item: BaseItemDto; onChange: (value: MediaSourceInfo) => void; selected?: MediaSourceInfo | null; } export const MediaSourceSelector: React.FC = ({ item, onChange, selected, ...props }) => { const [isModalVisible, setIsModalVisible] = useState(false); const selectedName = useMemo( () => item.MediaSources?.find((x) => x.Id === selected?.Id)?.MediaStreams?.find( (x) => x.Type === "Video" )?.DisplayTitle || "", [item, selected] ); return ( <> Video setIsModalVisible(true)} > {selectedName} setIsModalVisible(false)} > setIsModalVisible(false)} > Media Sources {item.MediaSources?.map((source, idx: number) => ( { onChange(source); setIsModalVisible(false); }} > {`${name(source.Name)} - ${convertBitsToMegabitsOrGigabits( source.Size )}`} {source.Id === selected?.Id && ( )} ))} setIsModalVisible(false)} > Cancel ); }; const name = (name?: string | null) => { if (name && name.length > 40) return name.substring(0, 20) + " [...] " + name.substring(name.length - 20); return name; };