Add Sonarr refactor

pull/302/head
Jason Fischer 2 years ago
parent 5cfadaea7f
commit f999f4a467
No known key found for this signature in database

@ -3,6 +3,7 @@ import dynamic from "next/dynamic";
const components = {
overseerr: dynamic(() => import("./overseerr/component")),
radarr: dynamic(() => import("./radarr/component")),
sonarr: dynamic(() => import("./sonarr/component")),
};
export default components;

@ -0,0 +1,38 @@
import useSWR from "swr";
import { useTranslation } from "next-i18next";
import Widget from "components/services/widgets/widget";
import Block from "components/services/widgets/block";
import { formatProxyUrl } from "utils/api-helpers";
export default function Component({ service }) {
const { t } = useTranslation();
const config = service.widget;
const { data: wantedData, error: wantedError } = useSWR(formatProxyUrl(config, "wanted/missing"));
const { data: queuedData, error: queuedError } = useSWR(formatProxyUrl(config, "queue"));
const { data: seriesData, error: seriesError } = useSWR(formatProxyUrl(config, "series"));
if (wantedError || queuedError || seriesError) {
return <Widget error={t("widget.api_error")} />;
}
if (!wantedData || !queuedData || !seriesData) {
return (
<Widget>
<Block label={t("sonarr.wanted")} />
<Block label={t("sonarr.queued")} />
<Block label={t("sonarr.series")} />
</Widget>
);
}
return (
<Widget>
<Block label={t("sonarr.wanted")} value={wantedData.totalRecords} />
<Block label={t("sonarr.queued")} value={queuedData.totalRecords} />
<Block label={t("sonarr.series")} value={seriesData.total} />
</Widget>
);
}

@ -0,0 +1,24 @@
import genericProxyHandler from "utils/proxies/generic";
import { asJson } from "utils/api-helpers";
const widget = {
api: "{url}/api/v3/{endpoint}?apikey={key}",
proxyHandler: genericProxyHandler,
mappings: {
"series": {
endpoint: "series",
map: (data) => ({
total: asJson(data).length,
}),
},
"queue": {
endpoint: "queue",
},
"wanted/missing": {
endpoint: "wanted/missing",
},
},
};
export default widget;

@ -1,9 +1,11 @@
import overseerr from "./overseerr/widget";
import radarr from "./radarr/widget";
import sonarr from "./sonarr/widget"
const widgets = {
overseerr,
radarr,
sonarr,
};
export default widgets;

Loading…
Cancel
Save