import { useEffect, useState } from "react"; import { Link } from "react-router-dom"; import { api, type AdguardInstance } from "../api/client"; import EmptyState from "../components/EmptyState"; import TimeAgo from "../components/TimeAgo"; import { BlockSkeleton } from "../components/Skeleton"; import { ErrorNotice } from "../components/Notice"; import { formatAgo } from "../utils/duration"; import { readableError } from "../utils/errors"; function Badge({ a }: { a: AdguardInstance }) { if (!a.enabled) return Off; if (!a.state) return Not read yet; if (!a.fresh) return Can’t be read; if (a.problems.some((x) => x.severity === "critical")) return Needs a look; if (a.problems.length > 0) return Needs a look; return In order; } function Tile({ label, value, sub, tone }: { label: string; value: string; sub?: string | null; tone?: "bad" | "warn" }) { return (
{label}
{value}
{sub &&
{sub}
}
); } function Counted({ title, items, empty }: { title: string; items: { name: string; count: number }[]; empty: string }) { const top = items[0]?.count ?? 0; return (

{title}

{items.length === 0 &&
{empty}
} {items.slice(0, 7).map((i) => (
{i.name} {i.count.toLocaleString()}
0 ? Math.max(2, (i.count / top) * 100) : 0}%` }} />
))}
); } function Card({ a }: { a: AdguardInstance }) { const s = a.state; const st = s?.stats ?? null; const lists = s?.filters?.lists ?? []; const on = lists.filter((l) => l.enabled); const oldest = on.map((l) => l.updated).filter((u): u is string => u !== null).sort()[0] ?? null; return (

{a.name} {s?.version ?? ""}

{a.status ? <>read : "not read yet"}
{a.status && !a.status.ok &&
The last attempt to read it failed: {a.status.error ?? "no answer"}.
} {a.problems.length > 0 && (
    {a.problems.map((x) => (
  • {x.message}
  • ))}
)} {s && ( <>
= 48 ? `${Math.round(st.periodHours / 24)} days` : `${st.periodHours} h`}` : ""}`} value={st ? st.queries.toLocaleString() : "—"} sub={st && st.avgMs !== null ? `${st.avgMs} ms on average` : st ? null : "could not be read"} />
{st && (st.topBlocked.length > 0 || st.topClients.length > 0 || st.topQueried.length > 0) && (
)}

Filter lists

{s.filters === null ? (
They could not be read.
) : ( <>
Filtering is {s.filters.enabled ? "on" : "off"}; {on.length} of {lists.length} lists switched on {oldest ? ( <> , the longest since an update ) : ( "" )} .
{s.staleLists.length > 0 &&
Not updated for over a week: {s.staleLists.join(", ")}.
}
    {lists.map((l) => (
  • {l.name} {!l.enabled && off}{" "} {l.rules !== null ? `${l.rules.toLocaleString()} rules · ` : ""} {l.updated ? ( <> updated ) : ( "never updated" )}
  • ))}
)} )}
); } /** AdGuard Home: whether DNS really answers, whether it protects, what it has done and whether its lists are kept up to date. */ export default function AdguardHome() { const [data, setData] = useState(null); const [error, setError] = useState(null); useEffect(() => { const load = () => api.adguard .list() .then((r) => { setData(r.instances); setError(null); }) .catch((err) => setError(readableError(err))); void load(); const t = setInterval(load, 60_000); return () => clearInterval(t); }, []); return ( <>

AdGuard Home

Read every two minutes (see Integrations), with a real DNS question put to it each time — its web interface can be up while DNS is not. Nothing is changed. DNS that stops answering, a DNS server that is not running,{" "} protection left off for an hour and filter lists that stopped updating are alerts — see Alerts.

{!data && !error && } {data && data.length === 0 && (
)} {data?.map((a) => )} ); }