every section was clickable and every one of them showed the same connection form, because the panel forced it and the nav did not know. nine doors onto one message taught nobody anything and made a setup step look like nine faults. so there is now a gate, `useReady`, and both panels read it. that is the point of putting it in a hook rather than in either panel: a nav that offers a row the detail panel then refuses is worse than one that does not offer it. the nav DECLINES TO OFFER — a locked section is a <div>, not a <Link>, so there is no href to hover, no cmd-click into a new tab and nothing to focus. rendering a link and swallowing the click leaves a row that looks navigable and behaves like one everywhere except the click. the detail panel HOLDS THE LOCK, and it has to, because `?section=gallery` typed into the address bar or arriving from an old bookmark never passes through the nav. one line of copy in the foot rather than a badge on nine dimmed rows. without it a locked nav reads as broken instead of as one step not done: the rows go grey and nothing says why or what to do about it. THE CONDITION IS HARDCODED FALSE, as asked. the plumbing around it is real — it asks /status, re-asks when the connection changes, and reports while it is still asking — so switching the gate on is one line. it returns a single boolean and not its parts deliberately: "all the info needed in Administration" will grow past `configured && lastProbeOk`, and callers must not start assembling their own version of it out of the pieces. Co-Authored-By: Claude Opus 5 <noreply@anthropic.com>
83 lines
4.1 KiB
TypeScript
83 lines
4.1 KiB
TypeScript
import { useCallback, useEffect, useRef, useState } from 'react';
|
|
import { useClient } from 'hooks/useClient';
|
|
import { useFofosChanged } from './channel';
|
|
|
|
/**
|
|
* Is this plugin ready to be USED — that is, may anything but Administration be opened?
|
|
*
|
|
* ── One condition, read in two places ──
|
|
*
|
|
* The nav decides whether a section is clickable and the detail panel decides what to render. Those
|
|
* are two answers to the same question, and a nav that lets you click a row the panel then refuses is
|
|
* worse than one that does not offer it. So the condition lives here and both panels read it, rather
|
|
* than each deciding for itself — the panels are siblings and neither may own the other.
|
|
*
|
|
* ── It is a GATE, not a hint ──
|
|
*
|
|
* Not ready means the site sections cannot be reached at all, by clicking or by typing `?section=` in
|
|
* the address bar. Every one of them is a window onto fofos, and without a working connection there is
|
|
* nothing behind any of them; offering nine doors onto the same "not connected" message taught nobody
|
|
* anything and made a setup step look like nine faults.
|
|
*
|
|
* ── Hardcoded false, deliberately, for now ──
|
|
*
|
|
* The shape is real and the plumbing is real: it asks `/status`, it re-asks whenever the connection
|
|
* changes, and it reports while it is still asking. Only the final verdict is pinned, so turning the
|
|
* gate on is one line rather than a feature.
|
|
*
|
|
* ── Both panels call this, so `/status` is fetched twice ──
|
|
*
|
|
* Known and accepted for now: two cheap GETs that answer the same question, kept in step because both
|
|
* re-run on the same `useFofosChanged` signal. The alternative is a context provider around the two
|
|
* panels, which is a shared-state boundary this does not yet need — and the duplication is visible
|
|
* here rather than hidden in a wrapper. If the condition grows expensive, that is the moment to fix
|
|
* it, not before.
|
|
*
|
|
* What it will become is roughly `configured && lastProbeOk` — the connection is stored AND the last
|
|
* probe reached fofos — but "all the info needed in Administration" is not settled yet and will grow
|
|
* past those two. That is why this returns a single boolean and not the parts: callers must not start
|
|
* assembling their own version of the condition out of the pieces.
|
|
*/
|
|
|
|
type Status = { configured: boolean; lastProbeOk: boolean | null };
|
|
|
|
export type Readiness = {
|
|
/** True only when every section may be opened. */
|
|
ready: boolean;
|
|
/** Still asking. Callers should render nothing rather than guess — see below. */
|
|
loading: boolean;
|
|
};
|
|
|
|
export const useReady = (): Readiness => {
|
|
const client = useClient();
|
|
const clientRef = useRef(client);
|
|
clientRef.current = client;
|
|
|
|
const [status, setStatus] = useState<Status | null>(null);
|
|
const [signal] = useFofosChanged();
|
|
|
|
const check = useCallback(async () => {
|
|
try {
|
|
setStatus(await clientRef.current.get<Status>('/fofos-admin/status'));
|
|
} catch {
|
|
/*
|
|
Cannot tell. Treated as CONFIGURED rather than not — a transient failure must never present as
|
|
"you have not set this up", which is a far more alarming thing to be told and invites somebody
|
|
to re-enter a connection that was never the problem.
|
|
*/
|
|
setStatus({ configured: true, lastProbeOk: null });
|
|
}
|
|
}, []);
|
|
|
|
useEffect(() => {
|
|
void check();
|
|
}, [check, signal]);
|
|
|
|
// ────────────────────────────────────────────────────────────────────────────────────────────────
|
|
// The gate. Replace `false` with the real condition — nothing else here has to change.
|
|
// ────────────────────────────────────────────────────────────────────────────────────────────────
|
|
const ready = false;
|
|
|
|
return { ready, loading: status === null };
|
|
};
|