import { FunctionComponent, useCallback, useRef } from "react"; import { Navigate, useParams } from "react-router-dom"; import { Container, Group, Menu, Stack } from "@mantine/core"; import { Dropzone } from "@mantine/dropzone"; import { useDocumentTitle } from "@mantine/hooks"; import { showNotification } from "@mantine/notifications"; import { faCloudUploadAlt, faEllipsis, faHistory, faSearch, faSync, faToolbox, faUser, faWrench, } from "@fortawesome/free-solid-svg-icons"; import { FontAwesomeIcon } from "@fortawesome/react-fontawesome"; import { isNumber } from "lodash"; import { useDownloadMovieSubtitles, useIsMovieActionRunning, useMoviesProvider, } from "@/apis/hooks"; import { useMovieAction, useMovieById, useMovieModification, } from "@/apis/hooks/movies"; import { Action, DropContent, Toolbox } from "@/components"; import { QueryOverlay } from "@/components/async"; import { ItemEditModal } from "@/components/forms/ItemEditForm"; import { MovieUploadModal } from "@/components/forms/MovieUploadForm"; import { MovieHistoryModal, SubtitleToolsModal } from "@/components/modals"; import { MovieSearchModal } from "@/components/modals/ManualSearchModal"; import { useModals } from "@/modules/modals"; import { notification, task, TaskGroup } from "@/modules/task"; import ItemOverview from "@/pages/views/ItemOverview"; import { RouterNames } from "@/Router/RouterNames"; import { useLanguageProfileBy } from "@/utilities/languages"; import Table from "./table"; const MovieDetailView: FunctionComponent = () => { const param = useParams(); const id = Number.parseInt(param.id ?? ""); const movieQuery = useMovieById(id); const { data: movie, isFetched } = movieQuery; const profile = useLanguageProfileBy(movie?.profileId); const modals = useModals(); const mutation = useMovieModification(); const { mutateAsync: action } = useMovieAction(); const { mutateAsync: downloadAsync } = useDownloadMovieSubtitles(); const download = useCallback( (item: Item.Movie, result: SearchResultType) => { const { language, hearing_impaired: hi, forced, provider, subtitle, original_format: originalFormat, } = result; const { radarrId } = item; return downloadAsync({ radarrId, form: { language, hi, forced, provider, subtitle, // eslint-disable-next-line camelcase original_format: originalFormat, }, }); }, [downloadAsync], ); const onDrop = useCallback( (files: File[]) => { if (movie && profile) { modals.openContextModal(MovieUploadModal, { files, movie, }); } else { showNotification( notification.warn( "Cannot Upload Files", "movie or language profile is not ready", ), ); } }, [modals, movie, profile], ); const hasTask = useIsMovieActionRunning(); useDocumentTitle(`${movie?.title ?? "Unknown Movie"} - Bazarr (Movies)`); const openDropzone = useRef(null); if (isNaN(id) || (isFetched && !movie)) { return ; } const allowEdit = movie?.profileId !== undefined; return ( { if (movie) { task.create(movie.title, TaskGroup.ScanDisk, action, { action: "scan-disk", radarrid: id, }); } }} > Scan Disk { if (movie) { task.create(movie.title, TaskGroup.SearchSubtitle, action, { action: "search-missing", radarrid: id, }); } }} > Search { if (movie) { modals.openContextModal(MovieSearchModal, { item: movie, download, query: useMoviesProvider, }); } }} > Manual openDropzone.current?.()} > Upload { if (movie) { modals.openContextModal( ItemEditModal, { item: movie, mutation, }, { title: movie.title }, ); } }} > Edit Movie } onClick={() => { if (movie) { modals.openContextModal(SubtitleToolsModal, { payload: [movie], }); } }} > Mass Edit } onClick={() => { if (movie) { modals.openContextModal(MovieHistoryModal, { movie }); } }} > History
); }; export default MovieDetailView;