mirror of
https://github.com/Stremio/stremio-web.git
synced 2026-05-10 23:50:42 +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,
|
||||
};
|
||||
|
||||
const hasValidLabel = (label?: string) => label && label.length > 0 && !label.startsWith('http');
|
||||
|
||||
const SubtitleVariant = ({ track, selected, onSelect }: Props) => {
|
||||
const { t } = useTranslation();
|
||||
const toast = useToast();
|
||||
const buttonRef = useRef<HTMLElement>(null);
|
||||
const triggers = useMemo(() => [buttonRef], []);
|
||||
|
||||
const downloadUrl = useMemo(() => {
|
||||
return track.fallbackUrl || track.url;
|
||||
}, [track.fallbackUrl, track.url]);
|
||||
|
||||
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 downloadUrl = track.fallbackUrl || track.url;
|
||||
const variantLabel = hasValidLabel(track.label) ? track.label : languages.label(track.lang);
|
||||
const downloadFileName = hasValidLabel(track.label) ? track.label : `subtitle-${track.lang || 'unknown'}`;
|
||||
const canCopyUrl = typeof downloadUrl === 'string' && !downloadUrl.startsWith('blob:');
|
||||
|
||||
const onSelectClick = useCallback(() => {
|
||||
onSelect(track);
|
||||
|
|
|
|||
|
|
@ -113,7 +113,7 @@ const SubtitlesMenu = React.memo(React.forwardRef((props, ref) => {
|
|||
props.onExtraSubtitlesTrackSelected(track.id);
|
||||
}
|
||||
}
|
||||
}, [subtitlesTracksForLanguage, props.onSubtitlesTrackSelected, props.onExtraSubtitlesTrackSelected]);
|
||||
}, [props.onSubtitlesTrackSelected, props.onExtraSubtitlesTrackSelected]);
|
||||
const onSubtitlesDelayChanged = React.useCallback((value) => {
|
||||
if (typeof props.selectedExtraSubtitlesTrackId === 'string') {
|
||||
if (props.extraSubtitlesDelay !== null && !isNaN(props.extraSubtitlesDelay)) {
|
||||
|
|
|
|||
Loading…
Reference in a new issue