commit
ee95c23c3d
@ -0,0 +1,33 @@
|
|||||||
|
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: minifluxData, error: minifluxError } = useWidgetAPI(widget, "counters");
|
||||||
|
|
||||||
|
if (minifluxError) {
|
||||||
|
return <Container error={minifluxError} />;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (!minifluxData) {
|
||||||
|
return (
|
||||||
|
<Container service={service}>
|
||||||
|
<Block label="miniflux.unread" />
|
||||||
|
<Block label="miniflux.read" />
|
||||||
|
</Container>
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
return (
|
||||||
|
<Container service={service}>
|
||||||
|
<Block label="miniflux.unread" value={t("common.number", { value: minifluxData.unread })} />
|
||||||
|
<Block label="miniflux.read" value={t("common.number", { value: minifluxData.read })} />
|
||||||
|
</Container>
|
||||||
|
);
|
||||||
|
}
|
@ -0,0 +1,19 @@
|
|||||||
|
import { asJson } from "utils/proxy/api-helpers";
|
||||||
|
import credentialedProxyHandler from "utils/proxy/handlers/credentialed";
|
||||||
|
|
||||||
|
const widget = {
|
||||||
|
api: "{url}/v1/{endpoint}",
|
||||||
|
proxyHandler: credentialedProxyHandler,
|
||||||
|
|
||||||
|
mappings: {
|
||||||
|
counters: {
|
||||||
|
endpoint: "feeds/counters",
|
||||||
|
map: (data) => ({
|
||||||
|
read: Object.values(asJson(data).reads).reduce((acc, i) => acc + i, 0),
|
||||||
|
unread: Object.values(asJson(data).unreads).reduce((acc, i) => acc + i, 0)
|
||||||
|
}),
|
||||||
|
},
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
|
export default widget;
|
Loading…
Reference in new issue