mirror of
https://github.com/gethomepage/homepage.git
synced 2026-10-17 16:01:43 -07:00
Lint / Linting Checks (push) Has been cancelled
Release Drafter / Update Release Draft (push) Has been cancelled
Docker CI / Docker Build & Push (push) Has been cancelled
Tests / vitest (1) (push) Has been cancelled
Tests / vitest (2) (push) Has been cancelled
Release Drafter / Auto Label PR (push) Has been cancelled
Tests / vitest (3) (push) Has been cancelled
Tests / vitest (4) (push) Has been cancelled
Co-authored-by: shamoon <4887959+shamoon@users.noreply.github.com> Signed-off-by: dependabot[bot] <support@github.com>
53 lines
1.8 KiB
React
53 lines
1.8 KiB
React
import { useTranslation } from "next-i18next/pages";
|
|
|
|
import Block from "components/services/widget/block";
|
|
import Container from "components/services/widget/container";
|
|
import useWidgetAPI from "utils/proxy/use-widget-api";
|
|
import withWidgetFields from "utils/widget-fields";
|
|
|
|
const DEFAULT_FIELDS = ["queries", "blocked", "gravity"];
|
|
|
|
export default function Component({ service: configuredService }) {
|
|
const { t } = useTranslation();
|
|
|
|
const service = withWidgetFields(configuredService, DEFAULT_FIELDS);
|
|
const { widget } = service;
|
|
|
|
const { data: piholeData, error: piholeError } = useWidgetAPI(widget);
|
|
|
|
if (piholeError) {
|
|
return <Container service={service} error={piholeError} />;
|
|
}
|
|
|
|
if (!piholeData) {
|
|
return (
|
|
<Container service={service}>
|
|
<Block label="pihole.queries" />
|
|
<Block label="pihole.blocked" />
|
|
<Block label="pihole.blocked_percent" />
|
|
<Block label="pihole.gravity" />
|
|
</Container>
|
|
);
|
|
}
|
|
|
|
let blockedValue = `${t("common.number", { value: parseInt(piholeData.ads_blocked_today, 10) })}`;
|
|
if (!widget.fields.includes("blocked_percent")) {
|
|
blockedValue += ` (${t("common.percent", { value: parseFloat(piholeData.ads_percentage_today).toPrecision(3) })})`;
|
|
}
|
|
|
|
return (
|
|
<Container service={service}>
|
|
<Block label="pihole.queries" value={t("common.number", { value: parseInt(piholeData.dns_queries_today, 10) })} />
|
|
<Block label="pihole.blocked" value={blockedValue} />
|
|
<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) })}
|
|
/>
|
|
</Container>
|
|
);
|
|
}
|