mirror of
https://github.com/Stremio/stremio-web.git
synced 2026-05-17 18:21:57 +00:00
refactor: simplify
This commit is contained in:
parent
e2d1654f49
commit
b18df103fa
2 changed files with 7 additions and 20 deletions
|
|
@ -27,31 +27,18 @@ type Props = {
|
||||||
onSelect: (track: SubtitlesTrack) => void,
|
onSelect: (track: SubtitlesTrack) => void,
|
||||||
};
|
};
|
||||||
|
|
||||||
|
const hasValidLabel = (label?: string) => label && label.length > 0 && !label.startsWith('http');
|
||||||
|
|
||||||
const SubtitleVariant = ({ track, selected, onSelect }: Props) => {
|
const SubtitleVariant = ({ track, selected, onSelect }: Props) => {
|
||||||
const { t } = useTranslation();
|
const { t } = useTranslation();
|
||||||
const toast = useToast();
|
const toast = useToast();
|
||||||
const buttonRef = useRef<HTMLElement>(null);
|
const buttonRef = useRef<HTMLElement>(null);
|
||||||
const triggers = useMemo(() => [buttonRef], []);
|
const triggers = useMemo(() => [buttonRef], []);
|
||||||
|
|
||||||
const downloadUrl = useMemo(() => {
|
const downloadUrl = track.fallbackUrl || track.url;
|
||||||
return track.fallbackUrl || track.url;
|
const variantLabel = hasValidLabel(track.label) ? track.label : languages.label(track.lang);
|
||||||
}, [track.fallbackUrl, track.url]);
|
const downloadFileName = hasValidLabel(track.label) ? track.label : `subtitle-${track.lang || 'unknown'}`;
|
||||||
|
const canCopyUrl = typeof downloadUrl === 'string' && !downloadUrl.startsWith('blob:');
|
||||||
const variantLabel = useMemo(() => {
|
|
||||||
return (track.label && track.label.length > 0 && !track.label.startsWith('http'))
|
|
||||||
? track.label
|
|
||||||
: languages.label(track.lang);
|
|
||||||
}, [track.label, track.lang]);
|
|
||||||
|
|
||||||
const downloadFileName = useMemo(() => {
|
|
||||||
return (track.label && track.label.length > 0 && !track.label.startsWith('http'))
|
|
||||||
? track.label
|
|
||||||
: `subtitle-${track.lang || 'unknown'}`;
|
|
||||||
}, [track.label, track.lang]);
|
|
||||||
|
|
||||||
const canCopyUrl = useMemo(() => {
|
|
||||||
return typeof downloadUrl === 'string' && !downloadUrl.startsWith('blob:');
|
|
||||||
}, [downloadUrl]);
|
|
||||||
|
|
||||||
const onSelectClick = useCallback(() => {
|
const onSelectClick = useCallback(() => {
|
||||||
onSelect(track);
|
onSelect(track);
|
||||||
|
|
|
||||||
|
|
@ -113,7 +113,7 @@ const SubtitlesMenu = React.memo(React.forwardRef((props, ref) => {
|
||||||
props.onExtraSubtitlesTrackSelected(track.id);
|
props.onExtraSubtitlesTrackSelected(track.id);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}, [subtitlesTracksForLanguage, props.onSubtitlesTrackSelected, props.onExtraSubtitlesTrackSelected]);
|
}, [props.onSubtitlesTrackSelected, props.onExtraSubtitlesTrackSelected]);
|
||||||
const onSubtitlesDelayChanged = React.useCallback((value) => {
|
const onSubtitlesDelayChanged = React.useCallback((value) => {
|
||||||
if (typeof props.selectedExtraSubtitlesTrackId === 'string') {
|
if (typeof props.selectedExtraSubtitlesTrackId === 'string') {
|
||||||
if (props.extraSubtitlesDelay !== null && !isNaN(props.extraSubtitlesDelay)) {
|
if (props.extraSubtitlesDelay !== null && !isNaN(props.extraSubtitlesDelay)) {
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue