Something went wrong. Try again.
Something went wrong. Try again.
123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267import { 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 ( <div ref={(el) => { backdrop = el; }} class="la-modal" role="dialog" aria-modal="true" aria-label="How the lyric ladder looked for this track" tabindex={-1} onMouseDown={(e) => { if (e.target === backdrop) hideLadderAudit(); }} > <div class="la-panel"> <header class="la-head"> <div class="la-who"> <span class="la-title">{props.audit.tags.trackName || "untitled"}</span> <span class="la-by"> {props.audit.tags.artistName || "unknown"} {props.audit.tags.albumName ? ` · ${props.audit.tags.albumName}` : ""} {props.audit.tags.duration !== undefined ? ` · ${Math.round(props.audit.tags.duration)}s` : ""} </span> </div> {/* The verdict, in the same word the bar's readout uses, so the two can be compared without having to translate between them. */} <span class="la-verdict" data-outcome={props.audit.outcome}> {verdict()} </span> <button type="button" class="la-close" aria-label="Close" onClick={() => hideLadderAudit()} > × </button> </header>
{/* The tags are what the library said; this line is what the ladder asked with once the credit had come off, which is the edit the whole loose half of the ladder turns on. Absent when the ladder never got as far as stripping anything. */} <Show when={props.audit.bare || props.audit.credited.length > 0}> <div class="la-stripped"> <span class="la-stripped-label">asked with</span> <span class="la-stripped-title">{props.audit.bare || "\u2014"}</span> <Show when={props.audit.credited.length > 0}> <span class="la-stripped-credited">credited: {props.audit.credited.join(", ")}</span> </Show> </div> </Show>
<div class="la-rungs"> <div class="la-row la-row--head"> <span>#</span> <span>question</span> <span>asked</span> <span class="la-num">hits</span> <span class="la-num">timed</span> <span class="la-num">refused</span> <span class="la-num">ms</span> </div> <For each={props.audit.rungs}> {(rung) => ( <div class="la-rung" data-status={rung.status}> <div class="la-row"> <span class="la-n">{rung.n}</span> <span class="la-name"> {rung.name} {/* The ceiling in force, printed where it can be argued with: every refusal under this row was measured against this number. */} <Show when={rung.ceiling !== undefined}> <span class="la-ceiling">±{rung.ceiling}s</span> </Show> <Show when={rung.picked !== undefined}> <span class="la-picked">picked #{rung.picked}</span> </Show> </span> <span class="la-asked"> <span class="la-endpoint">{rung.endpoint}</span> <For each={queryChips(rung)}> {([field, value]) => ( <span class="la-chip"> <span class="la-chip-key">{field}</span> {value} </span> )} </For> <Show when={rung.says}> <span class="la-says">{rung.says}</span> </Show> </span> <span class="la-num" data-empty={rung.hits === 0 || undefined}> {rung.hits} </span> <span class="la-num" data-empty={rung.timed === 0 || undefined}> {rung.timed} </span> <span class="la-num" data-empty={rung.vetoed.length === 0 || undefined} title={STATUS[rung.status]} > {rung.vetoed.length} </span> <span class="la-num la-ms">{Math.round(rung.ms)}</span> </div> {/* The refusals, spelled out. This is the table's reason for existing: a rung that found six records and sang none of them is only diagnosable if the six are named, with the seconds that condemned them. */} <Show when={rung.vetoed.length > 0}> <ul class="la-vetoes"> <For each={rung.vetoed}> {(veto) => ( <li class="la-veto" data-timed={veto.timed ? "yes" : "no"}> {vetoLine(veto)} </li> )} </For> </ul> </Show> </div> )} </For> <Show when={props.audit.rungs.length === 0}> {/* The three ways an attempt ends without asking anything are the store's doing, and are worth saying rather than leaving as an empty table. */} <p class="la-empty"> 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"} </p> </Show> </div>
<Show when={props.audit.notes.length > 0}> <ul class="la-notes"> <For each={props.audit.notes}>{(note) => <li class="la-note">{note}</li>}</For> </ul> </Show>
<footer class="la-foot"> <span class="la-count"> {position() ? `attempt ${position()!.at} of ${position()!.of}` : "forgotten · the table was cleared"} </span> <span class="la-hint">← → walk the attempts · Esc closes</span> </footer> </div> </div> );};