homepage/src/widgets/pihole/component.jsx

37 lines
1.1 KiB
React
Raw Normal View History

2022-08-25 18:37:22 +03:00
import useSWR from "swr";
2022-09-25 19:43:00 +03:00
import { useTranslation } from "next-i18next";
2022-08-25 18:37:22 +03:00
2022-09-26 02:23:02 +03:00
import Widget from "components/services/widgets/widget";
import Block from "components/services/widgets/block";
import { formatProxyUrl } from "utils/proxy/api-helpers";
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-08-25 18:37:22 +03:00
const config = service.widget;
2022-09-25 19:43:47 +03:00
const { data: piholeData, error: piholeError } = useSWR(formatProxyUrl(config, "api.php"));
2022-08-25 18:37:22 +03:00
if (piholeError) {
2022-09-08 11:48:16 +03:00
return <Widget error={t("widget.api_error")} />;
2022-08-25 18:37:22 +03:00
}
if (!piholeData) {
return (
<Widget>
2022-09-08 11:48:16 +03:00
<Block label={t("pihole.queries")} />
<Block label={t("pihole.blocked")} />
<Block label={t("pihole.gravity")} />
2022-08-25 18:37:22 +03:00
</Widget>
);
}
return (
<Widget>
2022-09-08 11:48:16 +03:00
<Block label={t("pihole.queries")} value={t("common.number", { value: piholeData.dns_queries_today })} />
<Block label={t("pihole.blocked")} value={t("common.number", { value: piholeData.ads_blocked_today })} />
<Block label={t("pihole.gravity")} value={t("common.number", { value: piholeData.domains_being_blocked })} />
2022-08-25 18:37:22 +03:00
</Widget>
);
}