bazarr/frontend/src/components/modals/HistoryModal.tsx

236 lines
5.5 KiB
TypeScript
Raw Normal View History

import {
useEpisodeAddBlacklist,
useEpisodeHistory,
useMovieAddBlacklist,
useMovieHistory,
} from "@/apis/hooks";
2022-05-31 15:49:04 +00:00
import { withModal } from "@/modules/modals";
import { faFileExcel } from "@fortawesome/free-solid-svg-icons";
import { Badge, Center, Text } from "@mantine/core";
import { FunctionComponent, useMemo } from "react";
2021-03-25 14:22:43 +00:00
import { Column } from "react-table";
2022-05-31 15:49:04 +00:00
import { PageTable } from "..";
import MutateAction from "../async/MutateAction";
import QueryOverlay from "../async/QueryOverlay";
import { HistoryIcon } from "../bazarr";
import Language from "../bazarr/Language";
2022-05-31 15:49:04 +00:00
import TextPopover from "../TextPopover";
2021-03-25 14:22:43 +00:00
2022-05-31 15:49:04 +00:00
interface MovieHistoryViewProps {
movie: Item.Movie;
}
2021-03-25 14:22:43 +00:00
2022-05-31 15:49:04 +00:00
const MovieHistoryView: FunctionComponent<MovieHistoryViewProps> = ({
movie,
}) => {
const history = useMovieHistory(movie.radarrId);
2021-03-25 14:22:43 +00:00
const { data } = history;
2021-03-25 14:22:43 +00:00
const columns = useMemo<Column<History.Movie>[]>(
() => [
{
accessor: "action",
2022-05-31 15:49:04 +00:00
Cell: (row) => (
<Center>
<HistoryIcon action={row.value}></HistoryIcon>
</Center>
),
2021-03-25 14:22:43 +00:00
},
{
Header: "Language",
accessor: "language",
Cell: ({ value }) => {
if (value) {
2022-05-31 15:49:04 +00:00
return (
<Badge>
<Language.Text value={value} long></Language.Text>
</Badge>
);
2021-03-25 14:22:43 +00:00
} else {
return null;
}
},
},
{
Header: "Provider",
accessor: "provider",
},
{
Header: "Score",
accessor: "score",
},
{
Header: "Date",
accessor: "timestamp",
2022-05-31 15:49:04 +00:00
Cell: ({ value, row }) => {
return (
<TextPopover text={row.original.parsed_timestamp}>
<Text>{value}</Text>
</TextPopover>
);
},
2021-03-25 14:22:43 +00:00
},
{
// Actions
accessor: "blacklisted",
2022-05-31 15:49:04 +00:00
Cell: ({ row, value }) => {
const add = useMovieAddBlacklist();
const { radarrId, provider, subs_id, language, subtitles_path } =
row.original;
if (subs_id && provider && language) {
return (
<MutateAction
disabled={value}
icon={faFileExcel}
mutation={add}
args={() => ({
id: radarrId,
form: {
provider,
subs_id,
subtitles_path,
language: language.code2,
},
})}
></MutateAction>
);
} else {
return null;
}
2021-03-25 14:22:43 +00:00
},
},
],
2022-05-31 15:49:04 +00:00
[]
2021-03-25 14:22:43 +00:00
);
return (
2022-05-31 15:49:04 +00:00
<QueryOverlay result={history}>
<PageTable
columns={columns}
data={data ?? []}
tableStyles={{ emptyText: "No history found" }}
></PageTable>
</QueryOverlay>
2021-03-25 14:22:43 +00:00
);
};
2022-05-31 15:49:04 +00:00
export const MovieHistoryModal = withModal(MovieHistoryView, "movie-history", {
size: "xl",
title: "Movie History",
});
2022-03-27 06:42:28 +00:00
2022-05-31 15:49:04 +00:00
interface EpisodeHistoryViewProps {
episode: Item.Episode;
}
2021-03-25 14:22:43 +00:00
2022-05-31 15:49:04 +00:00
const EpisodeHistoryView: FunctionComponent<EpisodeHistoryViewProps> = ({
episode,
}) => {
const history = useEpisodeHistory(episode.sonarrEpisodeId);
2021-03-25 14:22:43 +00:00
const { data } = history;
2021-03-25 14:22:43 +00:00
const columns = useMemo<Column<History.Episode>[]>(
() => [
{
accessor: "action",
2022-05-31 15:49:04 +00:00
Cell: (row) => (
<Center>
<HistoryIcon action={row.value}></HistoryIcon>
</Center>
),
2021-03-25 14:22:43 +00:00
},
{
Header: "Language",
accessor: "language",
Cell: ({ value }) => {
if (value) {
2022-05-31 15:49:04 +00:00
return (
<Badge>
<Language.Text value={value} long></Language.Text>
</Badge>
);
2021-03-25 14:22:43 +00:00
} else {
return null;
}
},
},
{
Header: "Provider",
accessor: "provider",
},
{
Header: "Score",
accessor: "score",
},
{
Header: "Date",
accessor: "timestamp",
2022-05-31 15:49:04 +00:00
Cell: ({ row, value }) => {
return (
<TextPopover text={row.original.parsed_timestamp}>
<Text>{value}</Text>
</TextPopover>
);
},
2021-03-25 14:22:43 +00:00
},
{
// Actions
accessor: "blacklisted",
2022-05-31 15:49:04 +00:00
Cell: ({ row, value }) => {
const {
sonarrEpisodeId,
sonarrSeriesId,
provider,
subs_id,
language,
subtitles_path,
} = row.original;
const add = useEpisodeAddBlacklist();
2022-05-31 15:49:04 +00:00
if (subs_id && provider && language) {
return (
<MutateAction
disabled={value}
icon={faFileExcel}
mutation={add}
args={() => ({
seriesId: sonarrSeriesId,
episodeId: sonarrEpisodeId,
2022-05-31 15:49:04 +00:00
form: {
provider,
subs_id,
subtitles_path,
language: language.code2,
},
})}
></MutateAction>
);
} else {
return null;
}
2021-03-25 14:22:43 +00:00
},
},
],
[]
2021-03-25 14:22:43 +00:00
);
return (
2022-05-31 15:49:04 +00:00
<QueryOverlay result={history}>
<PageTable
tableStyles={{ emptyText: "No history found", placeholder: 5 }}
columns={columns}
data={data ?? []}
></PageTable>
</QueryOverlay>
2021-03-25 14:22:43 +00:00
);
};
2022-03-27 06:42:28 +00:00
export const EpisodeHistoryModal = withModal(
EpisodeHistoryView,
2022-05-31 15:49:04 +00:00
"episode-history",
{ size: "xl" }
2022-03-27 06:42:28 +00:00
);