import { faSearch, faTrash } from "@fortawesome/free-solid-svg-icons"; import { FontAwesomeIcon } from "@fortawesome/react-fontawesome"; import React, { FunctionComponent, useMemo } from "react"; import { Badge } from "react-bootstrap"; import { Column } from "react-table"; import { useProfileItemsToLanguages } from "../../@redux/hooks"; import { useShowOnlyDesired } from "../../@redux/hooks/site"; import { MoviesApi } from "../../apis"; import { AsyncButton, LanguageText, SimpleTable } from "../../components"; import { filterSubtitleBy } from "../../utilities"; const missingText = "Missing Subtitles"; interface Props { movie: Item.Movie; disabled?: boolean; profile?: Language.Profile; } const Table: FunctionComponent = ({ movie, profile, disabled }) => { const onlyDesired = useShowOnlyDesired(); const profileItems = useProfileItemsToLanguages(profile); const columns: Column[] = useMemo[]>( () => [ { Header: "Subtitle Path", accessor: "path", Cell: ({ value }) => { if (value === null || value.length === 0) { return "Video File Subtitle Track"; } else if (value === missingText) { return {value}; } else { return value; } }, }, { Header: "Language", accessor: "name", Cell: ({ row }) => { if (row.original.path === missingText) { return ( ); } else { return ( ); } }, }, { accessor: "code2", Cell: (row) => { const { original } = row.row; if (original.path === null || original.path.length === 0) { return null; } else if (original.path === missingText) { return ( MoviesApi.downloadSubtitles(movie.radarrId, { language: original.code2, hi: original.hi, forced: original.forced, }) } variant="light" size="sm" > ); } else { return ( MoviesApi.deleteSubtitles(movie.radarrId, { language: original.code2, hi: original.hi, forced: original.forced, path: original.path ?? "", }) } > ); } }, }, ], [movie, disabled] ); const data: Subtitle[] = useMemo(() => { const missing = movie.missing_subtitles.map((item) => ({ ...item, path: missingText, })); let raw_subtitles = movie.subtitles; if (onlyDesired) { raw_subtitles = filterSubtitleBy(raw_subtitles, profileItems); } return [...raw_subtitles, ...missing]; }, [movie.missing_subtitles, movie.subtitles, onlyDesired, profileItems]); return ( ); }; export default Table;