"use client"; // The official instances' numbers, composed at hub build time // (common/bin/compose-hub.ts -> /hub-summary.json) from the same summary the // homepage renders. Same-origin, fetched once. OPTIONAL: an older hub build or // a hub composed with no index has no file, and every failure — 404, bad JSON, // an unknown version — reads as "no numbers", never as an error on the page. // // `settled` turns true once the answer is in, whatever it was: the hub lists // its official instances in the summary's order (useHubSites), so it waits for // this before listing them rather than reordering them a moment later. import { useQuery } from "@tanstack/react-query"; import { HUB_SUMMARY_FILE, parseHubSummary, type HubSummary, } from "yt-dlp-transcript-common/lib/hubSummary"; async function fetchHubSummary(): Promise { try { const res = await fetch(`/${HUB_SUMMARY_FILE}`); if (!res.ok) return null; return parseHubSummary(await res.json()); } catch { return null; } } export function useHubSummary(): { summary: HubSummary | null; settled: boolean; } { const { data, isPending } = useQuery({ queryKey: ["hub-summary"], queryFn: fetchHubSummary, staleTime: Infinity, retry: false, // Always run it, even while the browser reports itself offline: TanStack's // default ("online") would PAUSE the query then, leaving it pending and the // official instances unlisted until the connection returned. The fetch // never throws — offline it settles at once as "no summary". networkMode: "always", }); return { summary: data ?? null, settled: !isPending }; }