import { For, Show, onSettled, type Component } from "solid-js"; import { hideLadderAudit, ladderAudits, stepLadderAudit, type LadderAudit, type LadderRung, type LadderVeto, } from "../lib/lyrics/audit"; /** * The ladder, on screen: every question the lyric client asked about one track, and what each one * brought back. * * `:lyricsaudit` raises it. The lyric column can say *there is no lyric*; this says **why the four * questions did not find the one that is there**, which is the question you actually ask once a * track has gone unanswered and you can see the lyric on the website. The ladder asks up to four * questions per track and each can lose the record for a different reason — a 404, an empty list, a * candidate whose length is fifty seconds off, a candidate that has no length to check — and a * status code does not distinguish any of them. * * So the unit here is the question, and the column that matters is the one on the right: what came * back, how much of it had timings, and what was refused. A rung that says `6 hits · 3 timed · 3 * refused` with `off by 112s · by length` under it is a ceiling you can argue with; a rung that says * `nothing` is a wall. * * Three things it deliberately does not do: * * - **It does not judge.** Nothing here says the ladder was right to refuse. The reasons are printed * in the host's vocabulary — its field names, the candidate's own seconds — so the reader is * arguing with the same facts the client saw, not with the client's summary of them. * - **It does not plot.** The load audit earns a flamegraph because a load overlaps itself; a ladder * is sequential by construction — one request on the wire, always — so a timing bar would be four * bars in a row under a table that already says which ran first. The milliseconds are a column. * - **It does not open itself.** A modal that appears because something failed is a modal that * teaches a listener to close things. It is raised by a verb, on purpose, by the person who wants * it. */ /** What a rung's status is worth saying, in the colour it deserves. */ const STATUS = { records: "answered", none: "nothing", unreachable: "no answer", } as const; /** The one-line description of a refusal, in the host's units rather than the app's. */ function vetoLine(veto: LadderVeto): string { const length = veto.offSeconds === null ? "no length published" : `${veto.offSeconds}s off${veto.why === "length" ? "" : " (not the reason)"}`; return `${veto.artistName || "unknown"} — ${veto.trackName || "untitled"} · ${length} · ${ veto.timed ? "timed" : "no timings" } · refused for its ${veto.why}`; } function queryChips(rung: LadderRung): [string, string][] { return Object.entries(rung.asked); } export const LadderAuditModal: Component<{ audit: LadderAudit }> = (props) => { let backdrop: HTMLDivElement | undefined; /** * Focus and the keyboard, both after the settle. * * Focus cannot come from a `ref` — a ref runs while the element is still detached, and focus on a * detached element is refused. The keys are bound in the **capture** phase for the reason the load * graph gives: the library view binds `j`/`k`/Escape on the window in the bubble phase, and a * capture listener on the same target runs first, so `←`/`→` walk the recorded attempts instead of * moving a list cursor nobody can see behind the overlay. Tab is left to the browser — a dialog you * cannot leave is worse than one whose keys leak. */ onSettled(() => { backdrop?.focus(); const onKey = (e: KeyboardEvent) => { if (e.metaKey || e.ctrlKey || e.altKey || e.key === "Tab") return; if (e.key === "Escape" || e.key === "ArrowLeft" || e.key === "ArrowRight") { e.preventDefault(); e.stopImmediatePropagation(); if (e.key === "Escape") hideLadderAudit(); else stepLadderAudit(e.key === "ArrowLeft" ? -1 : 1); } }; window.addEventListener("keydown", onKey, true); // Returned rather than handed to `onCleanup`, which Solid 2 refuses inside `onSettled` — and the // refusal is the reason the idiom is a returned function: the cleanup belongs to the settle, not // to whatever scope happens to be current when it runs. return () => window.removeEventListener("keydown", onKey, true); }); /** Where this attempt sits in the session, for the footer's `3 of 12`. */ const position = () => { const at = ladderAudits().findIndex((a) => a.seq === props.audit.seq); return at < 0 ? null : { at: at + 1, of: ladderAudits().length }; }; const verdict = () => props.audit.outcome === "found" ? `found · ${props.audit.pickedName ?? `#${props.audit.pickedId}`}` : props.audit.says ? `${props.audit.outcome} · ${props.audit.says}` : props.audit.outcome; return (
nothing was asked ·{" "} {props.audit.outcome === "cached" ? "answered from what the app already remembered" : props.audit.outcome === "off" ? "lyrics are switched off" : props.audit.outcome === "unasked" ? "the tags were too thin to ask with" : "no question was put"}