homepage/src/widgets/lidarr/component.jsx

41 lines
1.6 KiB
React
Raw Normal View History

2022-09-25 19:43:00 +03:00
import { useTranslation } from "next-i18next";
2022-09-14 19:30:51 -07: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";
2022-09-14 19:30:51 -07:00
2022-09-26 10:58:14 +03:00
export default function Component({ service }) {
2022-09-14 19:30:51 -07:00
const { t } = useTranslation();
2022-09-27 22:59:14 +03:00
const { widget } = service;
2022-09-14 19:30:51 -07:00
// album API endpoint can get massive, so we prevent calling if not included in fields see https://github.com/benphelps/homepage/discussions/1577
const showAlbums = widget.fields?.includes('albums') || !widget.fields;
const { data: albumsData, error: albumsError } = useWidgetAPI(widget, showAlbums ? "album" : "");
2022-09-27 22:59:14 +03:00
const { data: wantedData, error: wantedError } = useWidgetAPI(widget, "wanted/missing");
const { data: queueData, error: queueError } = useWidgetAPI(widget, "queue/status");
2022-09-14 19:30:51 -07:00
2022-11-07 09:24:15 -08:00
if (albumsError || wantedError || queueError) {
const finalError = albumsError ?? wantedError ?? queueError;
2023-04-30 19:09:37 -04:00
return <Container service={service} error={finalError} />;
2022-09-14 19:30:51 -07:00
}
if ((showAlbums && !albumsData) || !wantedData || !queueData) {
2022-09-14 19:30:51 -07:00
return (
<Container service={service}>
<Block label="lidarr.wanted" />
<Block label="lidarr.queued" />
<Block label="lidarr.albums" />
2022-09-26 15:25:10 +03:00
</Container>
2022-09-14 19:30:51 -07:00
);
}
return (
<Container service={service}>
<Block label="lidarr.wanted" value={t("common.number", { value: wantedData.totalRecords })} />
<Block label="lidarr.queued" value={t("common.number", { value: queueData.totalCount })} />
{showAlbums && <Block label="lidarr.albums" value={t("common.number", { value: albumsData?.have })} />}
2022-09-26 15:25:10 +03:00
</Container>
2022-09-14 19:30:51 -07:00
);
}