Komga Widget (#922)
Co-authored-by: shamoon <4887959+shamoon@users.noreply.github.com>pull/934/head
parent
aee8ba1e1d
commit
f851085ebf
@ -0,0 +1,37 @@
|
|||||||
|
import { useTranslation } from "next-i18next";
|
||||||
|
|
||||||
|
import Container from "components/services/widget/container";
|
||||||
|
import Block from "components/services/widget/block";
|
||||||
|
import useWidgetAPI from "utils/proxy/use-widget-api";
|
||||||
|
|
||||||
|
export default function Component({ service }) {
|
||||||
|
const { t } = useTranslation();
|
||||||
|
const { widget } = service;
|
||||||
|
|
||||||
|
const { data: libraryData, error: libraryError } = useWidgetAPI(widget, "libraries");
|
||||||
|
const { data: seriesData, error: seriesError } = useWidgetAPI(widget, "series");
|
||||||
|
const { data: bookData, error: bookError } = useWidgetAPI(widget, "books");
|
||||||
|
|
||||||
|
if (libraryError || seriesError || bookError) {
|
||||||
|
const finalError = libraryError ?? seriesError ?? bookError;
|
||||||
|
return <Container error={finalError} />;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (!libraryData || !seriesData || !bookData) {
|
||||||
|
return (
|
||||||
|
<Container service={service}>
|
||||||
|
<Block label="komga.libraries" />
|
||||||
|
<Block label="komga.series" />
|
||||||
|
<Block label="komga.books" />
|
||||||
|
</Container>
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
return (
|
||||||
|
<Container service={service}>
|
||||||
|
<Block label="komga.libraries" value={t("common.number", { value: libraryData.total })} />
|
||||||
|
<Block label="komga.series" value={t("common.number", { value: seriesData.totalElements })} />
|
||||||
|
<Block label="komga.books" value={t("common.number", { value: bookData.totalElements })} />
|
||||||
|
</Container>
|
||||||
|
);
|
||||||
|
}
|
@ -0,0 +1,30 @@
|
|||||||
|
import genericProxyHandler from "utils/proxy/handlers/generic";
|
||||||
|
import { jsonArrayFilter } from "utils/proxy/api-helpers";
|
||||||
|
|
||||||
|
const widget = {
|
||||||
|
api: "{url}/api/v1/{endpoint}",
|
||||||
|
proxyHandler: genericProxyHandler,
|
||||||
|
|
||||||
|
mappings: {
|
||||||
|
libraries: {
|
||||||
|
endpoint: "libraries",
|
||||||
|
map: (data) => ({
|
||||||
|
total: jsonArrayFilter(data, (item) => !item.unavailable).length,
|
||||||
|
}),
|
||||||
|
},
|
||||||
|
series: {
|
||||||
|
endpoint: "series",
|
||||||
|
validate: [
|
||||||
|
"totalElements"
|
||||||
|
]
|
||||||
|
},
|
||||||
|
books: {
|
||||||
|
endpoint: "books",
|
||||||
|
validate: [
|
||||||
|
"totalElements"
|
||||||
|
]
|
||||||
|
},
|
||||||
|
},
|
||||||
|
};
|
||||||
|
|
||||||
|
export default widget;
|
Loading…
Reference in new issue