import { tc } from "@/utils/textTools"; import { BaseItemDto, MediaSourceInfo, } from "@jellyfin/sdk/lib/generated-client/models"; import { useEffect, useMemo } from "react"; import { TouchableOpacity, View } from "react-native"; import * as DropdownMenu from "@/components/DropdownMenu"; import { Text } from "./common/Text"; import { convertBitsToMegabitsOrGigabits } from "@/utils/bToMb"; interface Props extends React.ComponentProps { item: BaseItemDto; onChange: (value: MediaSourceInfo) => void; selected?: MediaSourceInfo | null; } export const MediaSourceSelector: React.FC = ({ item, onChange, selected, ...props }) => { const selectedName = useMemo( () => item.MediaSources?.find((x) => x.Id === selected?.Id)?.MediaStreams?.find( (x) => x.Type === "Video" )?.DisplayTitle || "", [item, selected] ); return ( Video {selectedName} Media sources {item.MediaSources?.map((source, idx: number) => ( { onChange(source); }} > {`${name(source.Name)} - ${convertBitsToMegabitsOrGigabits( source.Size )}`} ))} ); }; const name = (name?: string | null) => { if (name && name.length > 40) return name.substring(0, 20) + " [...] " + name.substring(name.length - 20); return name; };