"use client"; import { useRouter } from "next/navigation"; import { useState } from "react"; export interface PanelCheck { id: string; app: string; name: string; url: string; paused: boolean; state: string; status_url: string; last_checked_at: string | null; } async function post(body: Record): Promise { const res = await fetch("/api/watch", { method: "POST", headers: { "content-type": "application/json" }, body: JSON.stringify(body) }); if (res.ok) return null; return ((await res.json().catch(() => ({}))) as { error?: string }).error ?? "Could not save. Try again."; } const LABEL: Record = { up: "Up", down: "Down", waiting: "Waiting" }; /** Uptime checks: add one by address, pause or resume, open the status page (PY2.2). */ export function WatchPanel({ apps, checks }: { apps: string[]; checks: PanelCheck[] }) { const router = useRouter(); const [app, setApp] = useState(apps[0] ?? ""); const [url, setUrl] = useState(""); const [busy, setBusy] = useState(false); const [error, setError] = useState(null); const run = async (body: Record) => { setBusy(true); setError(null); const e = await post(body); setBusy(false); if (e) setError(e); else { setUrl(""); router.refresh(); } }; return ( <> {checks.length ? (
    {checks.map((c) => (
  • {c.name} {c.url} {c.paused ? "Paused" : LABEL[c.state] ?? c.state} Status page
  • ))}
) : (

No checks yet. Add your app's address; we check it every minute.

)} {apps.length ? (
{ e.preventDefault(); void run({ app, url }); }} > setUrl(e.target.value)} />
) : (

Add an app first.

)} {error ?

{error}

: null} ); }