mirror of
https://github.com/DI0IK/homepage-plus.git
synced 2025-07-13 08:20:34 +00:00
Add Lidarr widget
This commit is contained in:
parent
15a8c4f0d7
commit
1f2639fbb5
5 changed files with 50 additions and 0 deletions
41
src/components/services/widgets/service/lidarr.jsx
Normal file
41
src/components/services/widgets/service/lidarr.jsx
Normal file
|
@ -0,0 +1,41 @@
|
|||
import useSWR from "swr";
|
||||
import { useTranslation } from "react-i18next";
|
||||
|
||||
import Widget from "../widget";
|
||||
import Block from "../block";
|
||||
|
||||
import { formatApiUrl } from "utils/api-helpers";
|
||||
|
||||
export default function Lidarr({ service }) {
|
||||
const { t } = useTranslation();
|
||||
|
||||
const config = service.widget;
|
||||
|
||||
const { data: albumsData, error: albumsError } = useSWR(formatApiUrl(config, "album"));
|
||||
const { data: wantedData, error: wantedError } = useSWR(formatApiUrl(config, "wanted/missing"));
|
||||
const { data: queueData, error: queueError } = useSWR(formatApiUrl(config, "queue/status"));
|
||||
|
||||
if (albumsError || wantedError || queueError) {
|
||||
return <Widget error={t("widget.api_error")} />;
|
||||
}
|
||||
|
||||
if (!albumsData || !wantedData || !queueData) {
|
||||
return (
|
||||
<Widget>
|
||||
<Block label={t("lidarr.wanted")} />
|
||||
<Block label={t("lidarr.queued")} />
|
||||
<Block label={t("lidarr.albums")} />
|
||||
</Widget>
|
||||
);
|
||||
}
|
||||
|
||||
const have = albumsData.filter((album) => album.statistics.trackFileCount > 0);
|
||||
|
||||
return (
|
||||
<Widget>
|
||||
<Block label={t("lidarr.wanted")} value={wantedData.totalRecords} />
|
||||
<Block label={t("lidarr.queued")} value={queueData.totalCount} />
|
||||
<Block label={t("lidarr.albums")} value={have.length} />
|
||||
</Widget>
|
||||
);
|
||||
}
|
Loading…
Add table
Add a link
Reference in a new issue