homepage/src/widgets/pihole/component.jsx

38 lines
1.3 KiB
React
Raw Normal View History

2022-09-25 19:43:00 +03:00
import { useTranslation } from "next-i18next";
2022-08-25 18:37:22 +03: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-26 02:23:02 +03:00
export default function Component({ service }) {
2022-09-08 11:48:16 +03:00
const { t } = useTranslation();
2022-09-27 22:59:14 +03:00
const { widget } = service;
2022-08-25 18:37:22 +03:00
const { data: piholeData, error: piholeError } = useWidgetAPI(widget, "summaryRaw");
2022-08-25 18:37:22 +03:00
2022-11-07 09:24:15 -08:00
if (piholeError) {
2023-04-30 19:09:37 -04:00
return <Container service={service} error={piholeError} />;
2022-08-25 18:37:22 +03:00
}
if (!piholeData) {
return (
<Container service={service}>
<Block label="pihole.queries" />
<Block label="pihole.blocked" />
<Block label="pihole.blocked_percent" />
<Block label="pihole.gravity" />
2022-09-26 15:25:10 +03:00
</Container>
2022-08-25 18:37:22 +03:00
);
}
return (
<Container service={service}>
<Block label="pihole.queries" value={t("common.number", { value: parseInt(piholeData.dns_queries_today, 10) })} />
<Block label="pihole.blocked" value={t("common.number", { value: parseInt(piholeData.ads_blocked_today, 10) })} />
<Block label="pihole.blocked_percent" value={t("common.percent", { value: parseFloat(piholeData.ads_percentage_today.toPrecision(3)) })} />
<Block label="pihole.gravity" value={t("common.number", { value: parseInt(piholeData.domains_being_blocked, 10) })} />
2022-09-26 15:25:10 +03:00
</Container>
2022-08-25 18:37:22 +03:00
);
}