import React, { useState } from "react"; import PropTypes from "prop-types"; import Dropdown from "react-bootstrap/Dropdown"; import { prettySize, upperCaseFirst } from "../../utils"; export const SubtitlesButton = ({ subtitles, inLibrary, search, fetchingSubtitles, }) => { if (inLibrary === false) { return null; } /* eslint-disable */ const [show, setShow] = useState(false); /* eslint-enable */ const onToggle = (isOpen, event, metadata) => { // Don't close on select if (metadata && metadata.source !== "select") { setShow(isOpen); } }; const searchAll = () => { const langs = ["fr_FR", "en_US"]; for (const lang of langs) { search(lang); } }; const count = subtitles && subtitles.size !== 0 ? subtitles.size : 0; const searching = fetchingSubtitles.length > 0; return ( Subtitles {count}
Automatic search
{count > 0 && ( Available subtitles )} {count > 0 && [...subtitles.entries()].map(([lang, subtitle]) => ( ))} ); }; SubtitlesButton.propTypes = { subtitles: PropTypes.object, inLibrary: PropTypes.bool.isRequired, fetchingSubtitles: PropTypes.array.isRequired, search: PropTypes.func.isRequired, }; export const SubtitleEntry = ({ subtitle, search }) => { const lang = upperCaseFirst(subtitle.lang.split("_")[0]); const size = subtitle.size ? subtitle.size : 0; const embedded = subtitle.embedded ? subtitle.embedded : false; const handleRefresh = () => { search(subtitle.lang); }; return (
{lang} {embedded && (Inside the video)} {size !== 0 && ({prettySize(size)})} {!embedded && (
)}
); }; SubtitleEntry.propTypes = { search: PropTypes.func.isRequired, subtitle: PropTypes.object, };