mirror of
https://github.com/streamyfin/streamyfin.git
synced 2026-01-15 15:48:05 +00:00
Some checks failed
🤖 Android APK Build (Phone + TV) / 🏗️ Build Android APK (phone) (push) Has been cancelled
🤖 Android APK Build (Phone + TV) / 🏗️ Build Android APK (tv) (push) Has been cancelled
🤖 iOS IPA Build (Phone + TV) / 🏗️ Build iOS IPA (phone) (push) Has been cancelled
🔒 Lockfile Consistency Check / 🔍 Check bun.lock and package.json consistency (push) Has been cancelled
🛡️ CodeQL Analysis / 🔎 Analyze with CodeQL (actions) (push) Has been cancelled
🛡️ CodeQL Analysis / 🔎 Analyze with CodeQL (javascript-typescript) (push) Has been cancelled
🏷️🔀Merge Conflict Labeler / 🏷️ Labeling Merge Conflicts (push) Has been cancelled
🚦 Security & Quality Gate / 🚑 Expo Doctor Check (push) Has been cancelled
🚦 Security & Quality Gate / 🔍 Vulnerable Dependencies (push) Has been cancelled
🚦 Security & Quality Gate / 📝 Validate PR Title (push) Has been cancelled
🚦 Security & Quality Gate / 🔍 Lint & Test (check) (push) Has been cancelled
🚦 Security & Quality Gate / 🔍 Lint & Test (format) (push) Has been cancelled
🚦 Security & Quality Gate / 🔍 Lint & Test (lint) (push) Has been cancelled
🚦 Security & Quality Gate / 🔍 Lint & Test (typecheck) (push) Has been cancelled
76 lines
2.4 KiB
TypeScript
76 lines
2.4 KiB
TypeScript
import type {
|
|
BaseItemDto,
|
|
MediaSourceInfo,
|
|
} from "@jellyfin/sdk/lib/generated-client/models";
|
|
import { useCallback, 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<typeof View> {
|
|
item: BaseItemDto;
|
|
onChange: (value: MediaSourceInfo) => void;
|
|
selected?: MediaSourceInfo | null;
|
|
}
|
|
|
|
export const MediaSourceSheet: React.FC<Props> = ({
|
|
item,
|
|
onChange,
|
|
selected,
|
|
...props
|
|
}) => {
|
|
const isTv = Platform.isTV;
|
|
const { t } = useTranslation();
|
|
const [open, setOpen] = useState(false);
|
|
|
|
const getDisplayName = useCallback((source: MediaSourceInfo) => {
|
|
const videoStream = source.MediaStreams?.find((x) => x.Type === "Video");
|
|
if (source.Name) return source.Name;
|
|
if (videoStream?.DisplayTitle) return videoStream.DisplayTitle;
|
|
return `Source ${source.Id}`;
|
|
}, []);
|
|
|
|
const selectedName = useMemo(() => {
|
|
if (!selected) return "";
|
|
return getDisplayName(selected);
|
|
}, [selected, getDisplayName]);
|
|
|
|
if (isTv || (item.MediaSources && item.MediaSources.length <= 1)) return null;
|
|
|
|
return (
|
|
<View className='flex shrink' style={{ minWidth: 75 }}>
|
|
<View className='flex flex-col' {...props}>
|
|
<Text className='opacity-50 mb-1 text-xs'>{t("item_card.video")}</Text>
|
|
<TouchableOpacity
|
|
className='bg-neutral-900 h-10 rounded-xl border-neutral-800 border px-3 py-2 flex flex-row items-center'
|
|
onPress={() => setOpen(true)}
|
|
>
|
|
<Text numberOfLines={1}>{selectedName}</Text>
|
|
</TouchableOpacity>
|
|
</View>
|
|
|
|
<FilterSheet
|
|
open={open}
|
|
setOpen={setOpen}
|
|
title={t("item_card.video")}
|
|
data={item.MediaSources || []}
|
|
values={selected ? [selected] : []}
|
|
multiple={false}
|
|
searchFilter={(src, query) =>
|
|
getDisplayName(src as MediaSourceInfo)
|
|
.toLowerCase()
|
|
.includes(query.toLowerCase())
|
|
}
|
|
renderItemLabel={(src) => (
|
|
<Text>{getDisplayName(src as MediaSourceInfo)}</Text>
|
|
)}
|
|
set={(vals) => {
|
|
const chosen = vals[0] as MediaSourceInfo | undefined;
|
|
if (chosen) onChange(chosen);
|
|
}}
|
|
/>
|
|
</View>
|
|
);
|
|
};
|