2022-09-26 00:35:54 +03:00
|
|
|
import { useTranslation } from "next-i18next";
|
|
|
|
|
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-26 00:35:54 +03:00
|
|
|
|
|
|
|
export default function Component({ service }) {
|
|
|
|
const { t } = useTranslation();
|
|
|
|
|
2022-09-27 22:59:14 +03:00
|
|
|
const { widget } = service;
|
2022-09-26 00:35:54 +03:00
|
|
|
|
2022-09-27 22:59:14 +03:00
|
|
|
const { data: booksData, error: booksError } = useWidgetAPI(widget, "book");
|
|
|
|
const { data: wantedData, error: wantedError } = useWidgetAPI(widget, "wanted/missing");
|
|
|
|
const { data: queueData, error: queueError } = useWidgetAPI(widget, "queue/status");
|
2022-09-26 00:35:54 +03:00
|
|
|
|
|
|
|
if (booksError || wantedError || queueError) {
|
2022-09-26 15:25:10 +03:00
|
|
|
return <Container error={t("widget.api_error")} />;
|
2022-09-26 00:35:54 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
if (!booksData || !wantedData || !queueData) {
|
|
|
|
return (
|
2022-09-29 21:15:25 -07:00
|
|
|
<Container service={service}>
|
|
|
|
<Block label="readarr.wanted" />
|
|
|
|
<Block label="readarr.queued" />
|
|
|
|
<Block label="readarr.books" />
|
2022-09-26 15:25:10 +03:00
|
|
|
</Container>
|
2022-09-26 00:35:54 +03:00
|
|
|
);
|
|
|
|
}
|
|
|
|
|
|
|
|
return (
|
2022-09-29 21:15:25 -07:00
|
|
|
<Container service={service}>
|
|
|
|
<Block label="readarr.wanted" value={t("common.number", { value: wantedData.totalRecords })} />
|
|
|
|
<Block label="readarr.queued" value={t("common.number", { value: queueData.totalCount })} />
|
|
|
|
<Block label="readarr.books" value={t("common.number", { value: booksData.have })} />
|
2022-09-26 15:25:10 +03:00
|
|
|
</Container>
|
2022-09-26 00:35:54 +03:00
|
|
|
);
|
|
|
|
}
|