2022-12-23 14:20:12 +01:00
|
|
|
import { useTranslation } from "next-i18next";
|
2023-06-02 14:57:27 +02:00
|
|
|
import classNames from 'classnames';
|
|
|
|
import { useCallback } from 'react';
|
2022-12-23 14:20:12 +01:00
|
|
|
|
2022-09-26 15:25:10 +03:00
|
|
|
import Container from "components/services/widget/container";
|
|
|
|
import Block from "components/services/widget/block";
|
2022-09-27 22:59:14 +03:00
|
|
|
import useWidgetAPI from "utils/proxy/use-widget-api";
|
2023-06-02 14:57:27 +02:00
|
|
|
import BlockList from 'components/services/widget/block-list';
|
2022-09-25 10:13:31 -07:00
|
|
|
|
|
|
|
export default function Component({ service }) {
|
2022-12-23 14:20:12 +01:00
|
|
|
const { t } = useTranslation();
|
2022-09-27 22:59:14 +03:00
|
|
|
const { widget } = service;
|
2022-09-25 10:13:31 -07:00
|
|
|
|
2022-09-27 22:59:14 +03:00
|
|
|
const { data: wantedData, error: wantedError } = useWidgetAPI(widget, "wanted/missing");
|
|
|
|
const { data: queuedData, error: queuedError } = useWidgetAPI(widget, "queue");
|
|
|
|
const { data: seriesData, error: seriesError } = useWidgetAPI(widget, "series");
|
2023-06-02 14:57:27 +02:00
|
|
|
const { data: queueDetailsData, error: queueDetailsError } = useWidgetAPI(widget, "queue/details");
|
2022-09-25 10:13:31 -07:00
|
|
|
|
2023-06-02 14:57:27 +02:00
|
|
|
// information taken from the Sonarr docs: https://sonarr.tv/docs/api/
|
|
|
|
const formatDownloadState = useCallback((downloadState) => {
|
|
|
|
switch (downloadState) {
|
|
|
|
case "importPending":
|
|
|
|
return "import pending";
|
|
|
|
case "failedPending":
|
|
|
|
return "failed pending";
|
|
|
|
default:
|
|
|
|
return downloadState;
|
|
|
|
}
|
|
|
|
}, []);
|
|
|
|
|
|
|
|
if (wantedError || queuedError || seriesError || queueDetailsError) {
|
|
|
|
const finalError = wantedError ?? queuedError ?? seriesError ?? queueDetailsError;
|
2023-04-30 19:09:37 -04:00
|
|
|
return <Container service={service} error={finalError} />;
|
2022-09-25 10:13:31 -07:00
|
|
|
}
|
|
|
|
|
2023-06-02 14:57:27 +02:00
|
|
|
if (!wantedData || !queuedData || !seriesData || !queueDetailsData) {
|
2022-09-25 10:13:31 -07:00
|
|
|
return (
|
2023-06-02 14:57:27 +02:00
|
|
|
<>
|
|
|
|
<Container service={service}>
|
|
|
|
<Block label="sonarr.wanted" />
|
|
|
|
<Block label="sonarr.queued" />
|
|
|
|
<Block label="sonarr.series" />
|
|
|
|
</Container>
|
|
|
|
<Container service={service}>
|
|
|
|
<BlockList label="sonarr.queued" />
|
|
|
|
</Container>
|
|
|
|
</>
|
2022-09-25 10:13:31 -07:00
|
|
|
);
|
|
|
|
}
|
|
|
|
|
|
|
|
return (
|
2023-06-02 14:57:27 +02:00
|
|
|
<>
|
|
|
|
<Container service={service}>
|
|
|
|
<Block label="sonarr.wanted" value={t("common.number", { value: wantedData.totalRecords })} />
|
|
|
|
<Block label="sonarr.queued" value={t("common.number", { value: queuedData.totalRecords })} />
|
|
|
|
<Block label="sonarr.series" value={t("common.number", { value: seriesData.length })} />
|
|
|
|
</Container>
|
|
|
|
<Container service={service}>
|
|
|
|
<BlockList label="sonarr.queued" childHeight={52}>
|
|
|
|
{Array.isArray(queueDetailsData) ? queueDetailsData.map((queueEntry) => (
|
|
|
|
<div className="my-0.5 w-full flex flex-col justify-between items-center" key={queueEntry.episodeId}>
|
|
|
|
<div className="h-6 w-full flex flex-row justify-between items-center">
|
2023-06-02 15:46:43 +02:00
|
|
|
<div className="w-full mr-5 overflow-hidden">
|
|
|
|
<div className="whitespace-nowrap text-left w-0">{seriesData.find((entry) => entry.id === queueEntry.seriesId).title} • {queueEntry.episodeTitle}</div>
|
|
|
|
</div>
|
2023-06-02 14:57:27 +02:00
|
|
|
<div>{formatDownloadState(queueEntry.trackedDownloadState)}</div>
|
|
|
|
</div>
|
|
|
|
<div className="h-6 w-full flex flex-row justify-between items-center">
|
|
|
|
<div className="mr-5 w-full bg-theme-800/30 rounded-full h-full dark:bg-theme-200/20">
|
|
|
|
<div
|
|
|
|
className={classNames(
|
|
|
|
"h-full rounded-full transition-all duration-1000",
|
|
|
|
queueEntry.trackedDownloadStatus === "ok" ? "bg-blue-500/80" : "bg-orange-500/80"
|
|
|
|
)}
|
|
|
|
style={{
|
|
|
|
width: `${(1 - queueEntry.sizeLeft / queueEntry.size) * 100}%`,
|
|
|
|
}}
|
|
|
|
/>
|
|
|
|
</div>
|
|
|
|
<div className="w-24 text-right">{queueEntry.timeLeft}</div>
|
|
|
|
</div>
|
|
|
|
</div>
|
|
|
|
)) : undefined}
|
|
|
|
</BlockList>
|
|
|
|
</Container>
|
|
|
|
</>
|
2022-09-25 10:13:31 -07:00
|
|
|
);
|
|
|
|
}
|