feat: add health indicator and localhost auto-detect
Surfaces live connection health for the active instance in the sidebar and probes localhost:8000 on the first-run choose-type screen so users running Honcho locally can connect in one tap. - useHealthStatus hook polls checkConnection every 30s via TanStack Query - HealthDot component renders a colored status dot with tooltip - choose-type screen silently probes http://localhost:8000 once; on success it surfaces a "Detected Honcho at localhost:8000 — tap to connect" banner that opens the self-hosted form
This commit is contained in:
20
packages/web/src/hooks/useHealthStatus.ts
Normal file
20
packages/web/src/hooks/useHealthStatus.ts
Normal file
@@ -0,0 +1,20 @@
|
||||
import { useQuery } from "@tanstack/react-query";
|
||||
import { useInstances } from "@/hooks/useInstances";
|
||||
import { checkConnection } from "@/lib/config";
|
||||
|
||||
const POLL_INTERVAL_MS = 30_000;
|
||||
|
||||
export function useHealthStatus() {
|
||||
const { active } = useInstances();
|
||||
return useQuery({
|
||||
queryKey: ["health", active?.id, active?.baseUrl, active?.token],
|
||||
queryFn: async () => {
|
||||
if (!active) throw new Error("No active instance");
|
||||
return checkConnection(active.baseUrl, active.token || undefined);
|
||||
},
|
||||
enabled: !!active,
|
||||
refetchInterval: POLL_INTERVAL_MS,
|
||||
refetchOnWindowFocus: true,
|
||||
staleTime: 0,
|
||||
});
|
||||
}
|
||||
Reference in New Issue
Block a user