mirror of
https://github.com/DI0IK/homepage-plus.git
synced 2025-07-11 23:58:46 +00:00
Simplify sonarr / radarr queues, better handle some errors
This commit is contained in:
parent
5b3d1cc6e0
commit
dd4ee44302
8 changed files with 64 additions and 116 deletions
|
@ -5,9 +5,12 @@ import QueueEntry from "../../components/widgets/queue/queueEntry";
|
|||
|
||||
import Container from "components/services/widget/container";
|
||||
import Block from "components/services/widget/block";
|
||||
import BlockList from "components/services/widget/block-list";
|
||||
import useWidgetAPI from "utils/proxy/use-widget-api";
|
||||
|
||||
function getProgress(sizeLeft, size) {
|
||||
return sizeLeft === 0 ? 100 : (1 - sizeLeft / size) * 100
|
||||
}
|
||||
|
||||
export default function Component({ service }) {
|
||||
const { t } = useTranslation();
|
||||
const { widget } = service;
|
||||
|
@ -16,7 +19,6 @@ export default function Component({ service }) {
|
|||
const { data: queuedData, error: queuedError } = useWidgetAPI(widget, "queue/status");
|
||||
const { data: queueDetailsData, error: queueDetailsError } = useWidgetAPI(widget, "queue/details");
|
||||
|
||||
// information taken from the Radarr docs: https://radarr.video/docs/api/
|
||||
const formatDownloadState = useCallback((downloadState) => {
|
||||
switch (downloadState) {
|
||||
case "importPending":
|
||||
|
@ -33,26 +35,19 @@ export default function Component({ service }) {
|
|||
return <Container service={service} error={finalError} />;
|
||||
}
|
||||
|
||||
const enableQueue = widget?.enableQueue;
|
||||
|
||||
if (!moviesData || !queuedData || !queueDetailsData) {
|
||||
return (
|
||||
<>
|
||||
<Container service={service}>
|
||||
<Block label="radarr.wanted" />
|
||||
<Block label="radarr.missing" />
|
||||
<Block label="radarr.queued" />
|
||||
<Block label="radarr.movies" />
|
||||
</Container>
|
||||
{ enableQueue &&
|
||||
<Container service={service}>
|
||||
<BlockList label="radarr.queued" />
|
||||
</Container>
|
||||
}
|
||||
</>
|
||||
<Container service={service}>
|
||||
<Block label="radarr.wanted" />
|
||||
<Block label="radarr.missing" />
|
||||
<Block label="radarr.queued" />
|
||||
<Block label="radarr.movies" />
|
||||
</Container>
|
||||
);
|
||||
}
|
||||
|
||||
const enableQueue = widget?.enableQueue && Array.isArray(queueDetailsData) && queueDetailsData.length > 0;
|
||||
|
||||
return (
|
||||
<>
|
||||
<Container service={service}>
|
||||
|
@ -61,21 +56,16 @@ export default function Component({ service }) {
|
|||
<Block label="radarr.queued" value={t("common.number", { value: queuedData.totalCount })} />
|
||||
<Block label="radarr.movies" value={t("common.number", { value: moviesData.have })} />
|
||||
</Container>
|
||||
{ enableQueue &&
|
||||
<Container service={service}>
|
||||
<BlockList label="radarr.queue" childHeight={24}>
|
||||
{Array.isArray(queueDetailsData) ? queueDetailsData.map((queueEntry) => (
|
||||
<QueueEntry
|
||||
progress={(1 - queueEntry.sizeLeft / queueEntry.size) * 100}
|
||||
status={queueEntry.status}
|
||||
timeLeft={queueEntry.timeLeft}
|
||||
title={moviesData.all.find((entry) => entry.id === queueEntry.movieId)?.title}
|
||||
activity={formatDownloadState(queueEntry.trackedDownloadState)}
|
||||
key={queueEntry.movieId}
|
||||
/>
|
||||
)) : undefined}
|
||||
</BlockList>
|
||||
</Container>
|
||||
{enableQueue &&
|
||||
queueDetailsData.map((queueEntry) => (
|
||||
<QueueEntry
|
||||
progress={getProgress(queueEntry.sizeLeft, queueEntry.size)}
|
||||
timeLeft={queueEntry.timeLeft}
|
||||
title={moviesData.all.find((entry) => entry.id === queueEntry.movieId)?.title ?? t("radarr.unknown")}
|
||||
activity={formatDownloadState(queueEntry.trackedDownloadState)}
|
||||
key={`${queueEntry.movieId}-${queueEntry.sizeLeft}`}
|
||||
/>
|
||||
))
|
||||
}
|
||||
</>
|
||||
);
|
||||
|
|
|
@ -29,7 +29,7 @@ const widget = {
|
|||
timeLeft: entry.timeleft,
|
||||
size: entry.size,
|
||||
sizeLeft: entry.sizeleft,
|
||||
movieId: entry.movieId,
|
||||
movieId: entry.movieId ?? entry.id,
|
||||
status: entry.status
|
||||
})).sort((a, b) => {
|
||||
const downloadingA = a.trackedDownloadState === "downloading"
|
||||
|
|
|
@ -6,7 +6,20 @@ import QueueEntry from "../../components/widgets/queue/queueEntry";
|
|||
import Container from "components/services/widget/container";
|
||||
import Block from "components/services/widget/block";
|
||||
import useWidgetAPI from "utils/proxy/use-widget-api";
|
||||
import BlockList from 'components/services/widget/block-list';
|
||||
|
||||
function getProgress(sizeLeft, size) {
|
||||
return sizeLeft === 0 ? 100 : (1 - sizeLeft / size) * 100
|
||||
}
|
||||
|
||||
function getTitle(queueEntry, seriesData) {
|
||||
let title = ''
|
||||
const seriesTitle = seriesData.find((entry) => entry.id === queueEntry.seriesId)?.title;
|
||||
if (seriesTitle) title += `${seriesTitle}: `;
|
||||
const { episodeTitle } = queueEntry;
|
||||
if (episodeTitle) title += episodeTitle;
|
||||
if (title === '') return null;
|
||||
return title;
|
||||
}
|
||||
|
||||
export default function Component({ service }) {
|
||||
const { t } = useTranslation();
|
||||
|
@ -17,7 +30,6 @@ export default function Component({ service }) {
|
|||
const { data: seriesData, error: seriesError } = useWidgetAPI(widget, "series");
|
||||
const { data: queueDetailsData, error: queueDetailsError } = useWidgetAPI(widget, "queue/details");
|
||||
|
||||
// information taken from the Sonarr docs: https://sonarr.tv/docs/api/
|
||||
const formatDownloadState = useCallback((downloadState) => {
|
||||
switch (downloadState) {
|
||||
case "importPending":
|
||||
|
@ -34,25 +46,18 @@ export default function Component({ service }) {
|
|||
return <Container service={service} error={finalError} />;
|
||||
}
|
||||
|
||||
const enableQueue = widget?.enableQueue;
|
||||
|
||||
if (!wantedData || !queuedData || !seriesData || !queueDetailsData) {
|
||||
return (
|
||||
<>
|
||||
<Container service={service}>
|
||||
<Block label="sonarr.wanted" />
|
||||
<Block label="sonarr.queued" />
|
||||
<Block label="sonarr.series" />
|
||||
</Container>
|
||||
{ enableQueue &&
|
||||
<Container service={service}>
|
||||
<BlockList label="sonarr.queued" />
|
||||
</Container>
|
||||
}
|
||||
</>
|
||||
<Container service={service}>
|
||||
<Block label="sonarr.wanted" />
|
||||
<Block label="sonarr.queued" />
|
||||
<Block label="sonarr.series" />
|
||||
</Container>
|
||||
);
|
||||
}
|
||||
|
||||
const enableQueue = widget?.enableQueue && Array.isArray(queueDetailsData) && queueDetailsData.length > 0;
|
||||
|
||||
return (
|
||||
<>
|
||||
<Container service={service}>
|
||||
|
@ -60,21 +65,16 @@ export default function Component({ service }) {
|
|||
<Block label="sonarr.queued" value={t("common.number", { value: queuedData.totalRecords })} />
|
||||
<Block label="sonarr.series" value={t("common.number", { value: seriesData.length })} />
|
||||
</Container>
|
||||
{ enableQueue &&
|
||||
<Container service={service}>
|
||||
<BlockList label="sonarr.queue" childHeight={24}>
|
||||
{Array.isArray(queueDetailsData) ? queueDetailsData.map((queueEntry) => (
|
||||
<QueueEntry
|
||||
progress={(1 - queueEntry.sizeLeft / queueEntry.size) * 100}
|
||||
status={queueEntry.status}
|
||||
timeLeft={queueEntry.timeLeft}
|
||||
title={`${seriesData.find((entry) => entry.id === queueEntry.seriesId)?.title } • ${ queueEntry.episodeTitle}`}
|
||||
activity={formatDownloadState(queueEntry.trackedDownloadState)}
|
||||
key={queueEntry.episodeId}
|
||||
/>
|
||||
)) : undefined}
|
||||
</BlockList>
|
||||
</Container>
|
||||
{enableQueue &&
|
||||
queueDetailsData.map((queueEntry) => (
|
||||
<QueueEntry
|
||||
progress={getProgress(queueEntry.sizeLeft, queueEntry.size)}
|
||||
timeLeft={queueEntry.timeLeft}
|
||||
title={getTitle(queueEntry, seriesData) ?? t("sonarr.unknown")}
|
||||
activity={formatDownloadState(queueEntry.trackedDownloadState)}
|
||||
key={`${queueEntry.seriesId}-${queueEntry.sizeLeft}`}
|
||||
/>
|
||||
))
|
||||
}
|
||||
</>
|
||||
);
|
||||
|
|
|
@ -34,9 +34,9 @@ const widget = {
|
|||
size: entry.size,
|
||||
sizeLeft: entry.sizeleft,
|
||||
seriesId: entry.seriesId,
|
||||
episodeTitle: entry.episode?.title,
|
||||
episodeId: entry.episodeId,
|
||||
status: entry.status
|
||||
episodeTitle: entry.episode?.title ?? entry.title,
|
||||
episodeId: entry.episodeId ?? entry.id,
|
||||
status: entry.status,
|
||||
})).sort((a, b) => {
|
||||
const downloadingA = a.trackedDownloadState === "downloading"
|
||||
const downloadingB = b.trackedDownloadState === "downloading"
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue