feat(web): one row primitive and a mobile shell
Every list now uses the row primitive with a fixed action column, so actions never wrap. Rows use icons, headers use words. Status slots, skeletons and a fixed hero grid stop the page jumping. Below 40rem a bottom tab bar holds the four destinations. Tooltip-only meaning moves to tap-to-explain. Co-Authored-By: Claude Opus 5.5 (1M context) <noreply@anthropic.com>
This commit is contained in:
co-authored by
Claude Opus 5.5
parent
ce6d38d044
commit
52b11fda93
+1290
-1390
File diff suppressed because it is too large
Load Diff
@@ -115,4 +115,24 @@ export function navigate(route: Route, options: { replace?: boolean } = {}) {
|
||||
} else {
|
||||
history.pushState(null, "", path);
|
||||
}
|
||||
window.dispatchEvent(new Event(ROUTE_EVENT));
|
||||
}
|
||||
|
||||
/** Fired after every `navigate` and on popstate: the shell repaints its active tab. */
|
||||
export const ROUTE_EVENT = "arr:route";
|
||||
|
||||
/** Which of the four destinations a route belongs to. */
|
||||
export type Destination = "library" | "search" | "queues" | "settings";
|
||||
|
||||
export function destinationOf(route: Route): Destination {
|
||||
switch (route.kind) {
|
||||
case "queues":
|
||||
return "queues";
|
||||
case "settings":
|
||||
return "settings";
|
||||
case "search":
|
||||
return "search";
|
||||
default:
|
||||
return "library";
|
||||
}
|
||||
}
|
||||
|
||||
+82
-118
@@ -6,6 +6,7 @@ import { armedDeleteIcon, icon } from "./icons";
|
||||
import { navigate } from "./router";
|
||||
import type { Root } from "./search";
|
||||
import { forgetSubtitleOptions } from "./subtitles";
|
||||
import { control, type RowDom, row, setSlot, chip as uiChip } from "./ui";
|
||||
|
||||
/** One policy row: the JSON columns as the API returns them. */
|
||||
export interface PolicyDoc {
|
||||
@@ -166,13 +167,7 @@ function el<K extends keyof HTMLElementTagNameMap>(
|
||||
}
|
||||
|
||||
function chip(text: string): HTMLSpanElement {
|
||||
return el("span", "chip readout", text);
|
||||
}
|
||||
|
||||
function rowTitle(title: string): HTMLElement {
|
||||
const wrap = el("span", "row-id");
|
||||
wrap.append(el("span", "row-title", title));
|
||||
return wrap;
|
||||
return uiChip(text);
|
||||
}
|
||||
|
||||
function field(labelText: string, control: HTMLElement): HTMLDivElement {
|
||||
@@ -226,10 +221,9 @@ function listValue(input: HTMLInputElement): string[] {
|
||||
|
||||
/** Icon-only edit toggle for one row; the label names the row it opens. */
|
||||
function editIcon(label: string): HTMLButtonElement {
|
||||
const button = el("button", "control control-quiet control-icon");
|
||||
const button = el("button", "control control-icon");
|
||||
button.type = "button";
|
||||
button.setAttribute("aria-label", label);
|
||||
button.title = label;
|
||||
button.setAttribute("aria-expanded", "false");
|
||||
button.append(icon("pencil"));
|
||||
return button;
|
||||
@@ -243,8 +237,6 @@ interface SettingsView {
|
||||
export function settingsMain(views: { hide: () => void }[], goHome: () => void): SettingsView {
|
||||
const view = must<HTMLElement>("#settings");
|
||||
const deck = must<HTMLElement>("#deck");
|
||||
const nav = must<HTMLButtonElement>("#nav-settings");
|
||||
nav.append(icon("cog"));
|
||||
const summary = must<HTMLElement>("#settings-summary");
|
||||
const status = must<HTMLElement>("#settings-status");
|
||||
const rootsSection = must<HTMLElement>("#group-roots");
|
||||
@@ -261,13 +253,7 @@ export function settingsMain(views: { hide: () => void }[], goHome: () => void):
|
||||
let sequence = 0;
|
||||
|
||||
function setStatus(text: string | null, tone?: "fault") {
|
||||
status.hidden = text === null;
|
||||
status.textContent = text ?? "";
|
||||
if (tone) {
|
||||
status.dataset.tone = tone;
|
||||
} else {
|
||||
delete status.dataset.tone;
|
||||
}
|
||||
setSlot(status, text, tone);
|
||||
}
|
||||
|
||||
function clearGroups() {
|
||||
@@ -327,54 +313,65 @@ export function settingsMain(views: { hide: () => void }[], goHome: () => void):
|
||||
|
||||
/* -- roots -------------------------------------------------------------- */
|
||||
|
||||
/** The row's line: identity, chips right, the icon action pair, feedback. */
|
||||
function rowLine(
|
||||
item: HTMLLIElement,
|
||||
/**
|
||||
* One settings row: identity, chips, then the edit and delete pair in the
|
||||
* row's fixed action column. The edit panel opens in the row's tray.
|
||||
*/
|
||||
function settingsRow(
|
||||
title: string,
|
||||
chips: HTMLSpanElement,
|
||||
del: HTMLButtonElement,
|
||||
edit: HTMLButtonElement,
|
||||
): HTMLParagraphElement {
|
||||
const actions = el("div", "settings-row-actions");
|
||||
actions.append(edit, del);
|
||||
const note = el("p", "add-note readout");
|
||||
note.setAttribute("role", "status");
|
||||
note.hidden = true;
|
||||
item.append(rowTitle(title), chips, actions, note);
|
||||
return note;
|
||||
}
|
||||
|
||||
function rootRow(root: Root): HTMLLIElement {
|
||||
const item = el("li", "queue-item settings-row");
|
||||
const chips = el("span", "row-chips");
|
||||
chips.append(chip(root.kind), chip(root.audience), chip(root.policy_name));
|
||||
|
||||
const del = armedDeleteIcon(`delete root ${root.path}`, () => {
|
||||
void deleteRow("roots", root.id).then((detail) => {
|
||||
if (detail !== null) {
|
||||
note.hidden = false;
|
||||
note.dataset.tone = "fault";
|
||||
note.textContent = detail;
|
||||
return;
|
||||
}
|
||||
void load();
|
||||
});
|
||||
chips: HTMLSpanElement[],
|
||||
label: string,
|
||||
remove: () => Promise<string | null>,
|
||||
panel: () => HTMLElement,
|
||||
): HTMLLIElement {
|
||||
let say: RowDom["say"] = () => {};
|
||||
const del = armedDeleteIcon(
|
||||
`delete ${label}`,
|
||||
() => {
|
||||
void remove().then((detail) => {
|
||||
if (detail !== null) {
|
||||
del.disabled = false;
|
||||
say(detail, "fault");
|
||||
return;
|
||||
}
|
||||
void load();
|
||||
});
|
||||
},
|
||||
{ explain: (text) => say(text, "warn") },
|
||||
);
|
||||
const edit = editIcon(`edit ${label}`);
|
||||
const parts = row({
|
||||
kind: "setting",
|
||||
title,
|
||||
meta: chips,
|
||||
actions: [
|
||||
{ node: edit, width: "icon" },
|
||||
{ node: del, width: "icon" },
|
||||
],
|
||||
});
|
||||
|
||||
const edit = editIcon(`edit root ${root.path}`);
|
||||
say = parts.say;
|
||||
parts.body.querySelector(".r-title")?.classList.add("readout");
|
||||
edit.addEventListener("click", () => {
|
||||
const existing = item.querySelector(".edit-panel");
|
||||
const existing = parts.tray.querySelector(".edit-panel");
|
||||
if (existing) {
|
||||
existing.remove();
|
||||
edit.setAttribute("aria-expanded", "false");
|
||||
return;
|
||||
}
|
||||
item.append(rootPanel(root));
|
||||
parts.tray.append(panel());
|
||||
edit.setAttribute("aria-expanded", "true");
|
||||
});
|
||||
return parts.item;
|
||||
}
|
||||
|
||||
const note = rowLine(item, root.path, chips, del, edit);
|
||||
return item;
|
||||
function rootRow(root: Root): HTMLLIElement {
|
||||
return settingsRow(
|
||||
root.path,
|
||||
[chip(root.kind), chip(root.audience), chip(root.policy_name)],
|
||||
`root ${root.path}`,
|
||||
() => deleteRow("roots", root.id),
|
||||
() => rootPanel(root),
|
||||
);
|
||||
}
|
||||
|
||||
function rootPanel(root: Root | null): HTMLElement {
|
||||
@@ -407,8 +404,7 @@ export function settingsMain(views: { hide: () => void }[], goHome: () => void):
|
||||
note.setAttribute("role", "status");
|
||||
note.hidden = true;
|
||||
|
||||
const save = el("button", "control readout", root === null ? "create root" : "save root");
|
||||
save.type = "button";
|
||||
const save = control(root === null ? "create root" : "save root");
|
||||
save.addEventListener("click", () => {
|
||||
save.disabled = true;
|
||||
note.hidden = false;
|
||||
@@ -432,8 +428,7 @@ export function settingsMain(views: { hide: () => void }[], goHome: () => void):
|
||||
});
|
||||
});
|
||||
|
||||
const cancel = el("button", "control control-quiet readout", "cancel");
|
||||
cancel.type = "button";
|
||||
const cancel = control("cancel", { quiet: true });
|
||||
cancel.addEventListener("click", () => {
|
||||
panel.remove();
|
||||
});
|
||||
@@ -455,39 +450,18 @@ export function settingsMain(views: { hide: () => void }[], goHome: () => void):
|
||||
}
|
||||
|
||||
function policyRow(policy: PolicyDoc): HTMLLIElement {
|
||||
const item = el("li", "queue-item settings-row");
|
||||
const chips = el("span", "row-chips");
|
||||
chips.append(chip(policy.resolution_pref.join(" › ") || "no resolutions"));
|
||||
chips.append(chip(requiredAudioLabel(policy)));
|
||||
const bandCount = Object.keys(policy.size_bands).length;
|
||||
chips.append(chip(`${bandCount} band${bandCount === 1 ? "" : "s"}`));
|
||||
|
||||
const del = armedDeleteIcon(`delete policy ${policy.name}`, () => {
|
||||
void deleteRow("policies", policy.id).then((detail) => {
|
||||
if (detail !== null) {
|
||||
note.hidden = false;
|
||||
note.dataset.tone = "fault";
|
||||
note.textContent = detail;
|
||||
return;
|
||||
}
|
||||
void load();
|
||||
});
|
||||
});
|
||||
|
||||
const edit = editIcon(`edit policy ${policy.name}`);
|
||||
edit.addEventListener("click", () => {
|
||||
const existing = item.querySelector(".edit-panel");
|
||||
if (existing) {
|
||||
existing.remove();
|
||||
edit.setAttribute("aria-expanded", "false");
|
||||
return;
|
||||
}
|
||||
item.append(policyPanel(policy));
|
||||
edit.setAttribute("aria-expanded", "true");
|
||||
});
|
||||
|
||||
const note = rowLine(item, policy.name, chips, del, edit);
|
||||
return item;
|
||||
return settingsRow(
|
||||
policy.name,
|
||||
[
|
||||
chip(policy.resolution_pref.join(" › ") || "no resolutions"),
|
||||
chip(requiredAudioLabel(policy)),
|
||||
chip(`${bandCount} band${bandCount === 1 ? "" : "s"}`),
|
||||
],
|
||||
`policy ${policy.name}`,
|
||||
() => deleteRow("policies", policy.id),
|
||||
() => policyPanel(policy),
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -635,8 +609,7 @@ export function settingsMain(views: { hide: () => void }[], goHome: () => void):
|
||||
scoreInputs[key] = input;
|
||||
}
|
||||
|
||||
const save = el("button", "control readout", policy === null ? "create policy" : "save policy");
|
||||
save.type = "button";
|
||||
const save = control(policy === null ? "create policy" : "save policy");
|
||||
save.addEventListener("click", () => {
|
||||
const bad = panel.querySelector<HTMLElement>("[data-invalid]");
|
||||
if (bad !== null) {
|
||||
@@ -704,8 +677,7 @@ export function settingsMain(views: { hide: () => void }[], goHome: () => void):
|
||||
});
|
||||
});
|
||||
|
||||
const cancel = el("button", "control control-quiet readout", "cancel");
|
||||
cancel.type = "button";
|
||||
const cancel = control("cancel", { quiet: true });
|
||||
cancel.addEventListener("click", () => {
|
||||
panel.remove();
|
||||
});
|
||||
@@ -730,11 +702,10 @@ export function settingsMain(views: { hide: () => void }[], goHome: () => void):
|
||||
* ordinal selector would quietly disable the wrong control.
|
||||
*/
|
||||
function moveButton(direction: "up" | "down", label: string): HTMLButtonElement {
|
||||
const button = el("button", "control control-quiet control-icon provider-move");
|
||||
const button = el("button", "control control-icon provider-move");
|
||||
button.type = "button";
|
||||
button.dataset.move = direction;
|
||||
button.setAttribute("aria-label", label);
|
||||
button.title = label;
|
||||
button.append(icon(direction === "up" ? "chevronUp" : "chevronDown"));
|
||||
return button;
|
||||
}
|
||||
@@ -750,23 +721,31 @@ export function settingsMain(views: { hide: () => void }[], goHome: () => void):
|
||||
enabled: boolean,
|
||||
budget: number,
|
||||
): { item: HTMLLIElement; enabledInput: HTMLInputElement; budgetInput: HTMLInputElement } {
|
||||
const item = el("li", "provider-row");
|
||||
item.dataset.provider = provider;
|
||||
|
||||
const enabledInput = document.createElement("input");
|
||||
enabledInput.type = "checkbox";
|
||||
enabledInput.className = "provider-toggle";
|
||||
enabledInput.checked = enabled;
|
||||
enabledInput.setAttribute("aria-label", `enable ${provider}`);
|
||||
|
||||
const name = el("span", "row-title provider-name", provider);
|
||||
|
||||
const budgetInput = numberControl(budget);
|
||||
budgetInput.classList.add("provider-budget");
|
||||
budgetInput.setAttribute("aria-label", `${provider} daily budget`);
|
||||
|
||||
const up = moveButton("up", `move ${provider} up`);
|
||||
const down = moveButton("down", `move ${provider} down`);
|
||||
const toggleWrap = el("label", "provider-check");
|
||||
toggleWrap.append(enabledInput);
|
||||
const { item } = row({
|
||||
kind: "provider",
|
||||
lead: toggleWrap,
|
||||
title: provider,
|
||||
actions: [
|
||||
{ node: budgetInput, width: "word" },
|
||||
{ node: up, width: "icon" },
|
||||
{ node: down, width: "icon" },
|
||||
],
|
||||
});
|
||||
item.dataset.provider = provider;
|
||||
|
||||
up.addEventListener("click", () => {
|
||||
const previous = item.previousElementSibling;
|
||||
@@ -783,7 +762,6 @@ export function settingsMain(views: { hide: () => void }[], goHome: () => void):
|
||||
}
|
||||
});
|
||||
|
||||
item.append(enabledInput, name, budgetInput, up, down);
|
||||
return { item, enabledInput, budgetInput };
|
||||
}
|
||||
|
||||
@@ -885,8 +863,7 @@ export function settingsMain(views: { hide: () => void }[], goHome: () => void):
|
||||
note.setAttribute("role", "status");
|
||||
note.hidden = true;
|
||||
|
||||
const save = el("button", "control readout", "save subtitles");
|
||||
save.type = "button";
|
||||
const save = control("save subtitles");
|
||||
save.addEventListener("click", () => {
|
||||
const providerOrder = [...list.children].map(
|
||||
(item) => (item as HTMLElement).dataset.provider ?? "",
|
||||
@@ -956,32 +933,19 @@ export function settingsMain(views: { hide: () => void }[], goHome: () => void):
|
||||
}
|
||||
deck.hidden = true;
|
||||
view.hidden = false;
|
||||
nav.setAttribute("aria-pressed", "true");
|
||||
void load();
|
||||
}
|
||||
|
||||
function hide() {
|
||||
view.hidden = true;
|
||||
nav.setAttribute("aria-pressed", "false");
|
||||
sequence += 1;
|
||||
}
|
||||
|
||||
function close() {
|
||||
hide();
|
||||
goHome();
|
||||
nav.focus();
|
||||
}
|
||||
|
||||
nav.addEventListener("click", () => {
|
||||
if (view.hidden) {
|
||||
navigate({ kind: "settings" });
|
||||
open();
|
||||
} else {
|
||||
navigate({ kind: "library" });
|
||||
close();
|
||||
}
|
||||
});
|
||||
|
||||
must<HTMLButtonElement>("#root-add").addEventListener("click", () => {
|
||||
rootsSection.append(rootPanel(null));
|
||||
});
|
||||
|
||||
Reference in New Issue
Block a user