diff --git a/web/src/jobs/jobProgress.ts b/web/src/jobs/jobProgress.ts index 32c6322..bdb7c90 100644 --- a/web/src/jobs/jobProgress.ts +++ b/web/src/jobs/jobProgress.ts @@ -7,11 +7,11 @@ import { api } from '../api/client' import type { JobProgress as Progress, JobState } from '../api/jobContract' import { q } from '../api/queries' -import { commandLabel, findCommand } from '../commands/catalog' +import { COMMAND_ICON, commandLabel, findCommand } from '../commands/catalog' import { Action } from '../lib/action' import { define, h } from '../lib/dom' import { LiveElement } from '../lib/element' -import { errorNotice, notice } from '../ui/build' +import { errorNotice, glyph, notice } from '../ui/build' import { clock, duration } from '../ui/format' import { hub, type LiveJob } from './hub' import { progressBar, stateBadge } from './progress' @@ -130,7 +130,8 @@ export class JobProgressElement extends LiveElement { f.section.className = compact ? 'job job-compact' : 'job' f.section.dataset.state = state f.section.setAttribute('aria-label', `Job ${job ? commandLabel(job.command) : id}`) - f.title.textContent = title + // Textgate: the command's glyph painted, its name spoken. + f.title.replaceChildren(...(job ? [glyph(COMMAND_ICON[job.command], title)] : [])) f.badge.replaceChildren(stateBadge(state)) f.meta.replaceChildren( job ? duration(job.started_at, job.ended_at, now) : '', @@ -141,11 +142,14 @@ export class JobProgressElement extends LiveElement { { class: live.connected ? 'dot dot-live' : 'dot dot-off', role: 'img', 'aria-label': live.connected ? 'Live' : 'Reconnecting' }, ), ) + // The server's phase sentence is spoken only; the bar, step count and + // state glyph carry it on screen. f.phase.replaceChildren( h( 'span', { class: 'job-label' }, - isDone(state) ? DONE_LABEL[state] : waiting ? '⏳' : (progress?.label ?? ''), + isDone(state) ? DONE_LABEL[state] : waiting ? '⏳' : progress ? '▶️' : '', + progress?.label && !finished ? h('span', { class: 'sr-only' }, progress.label) : null, ), !finished && progress && progress.total !== null ? h('span', { class: 'job-step' }, `${progress.step}/${progress.total}`) @@ -171,7 +175,7 @@ export class JobProgressElement extends LiveElement { this.updatePrompt(f, live, state) f.result.replaceChildren( ...(live.result - ? [notice(live.result.ok ? 'success' : 'danger', null, live.result.summary)] + ? [notice(live.result.ok ? 'success' : 'danger', null, h('span', { class: 'sr-only' }, live.result.summary))] : []), ) f.actions.replaceChildren( diff --git a/web/src/jobs/promptForm.ts b/web/src/jobs/promptForm.ts index db0b946..71376ec 100644 --- a/web/src/jobs/promptForm.ts +++ b/web/src/jobs/promptForm.ts @@ -10,9 +10,15 @@ import { PhraseField } from '../commands/phraseField' import { Action } from '../lib/action' import { h, hx } from '../lib/dom' import type { GameBrowserElement } from '../library/pick' -import { errorNotice } from '../ui/build' +import { errorNotice, glyph } from '../ui/build' import { hub, type PromptEvent } from './hub' +/** A glyph-only button: `icon` painted, `spoken` its accessible name. */ +function sendButton(btn: HTMLButtonElement, spoken: string, icon: string): void { + btn.setAttribute('aria-label', spoken) + btn.textContent = icon +} + function answerAction(jobId: string, prompt: PromptEvent, onChange: () => void): Action<[string], void> { return new Action(async (value: string) => { await api.answer(jobId, { prompt_id: prompt.prompt_id, value }) @@ -34,7 +40,8 @@ function answerForm(jobId: string, prompt: PromptEvent): HTMLFormElement { const submit = (v: string = value) => { void send.run(v) } - const form = h('form', { class: 'prompt', 'aria-label': 'Job question' }, h('p', { class: 'prompt-msg' }, prompt.message)) + // Textgate: the server's question is spoken; ❓ marks that the job waits on you. + const form = h('form', { class: 'prompt', 'aria-label': 'Job question' }, h('p', { class: 'prompt-msg' }, glyph('❓', prompt.message))) form.addEventListener('submit', (e) => { e.preventDefault() if (ready()) submit() @@ -57,8 +64,9 @@ function answerForm(jobId: string, prompt: PromptEvent): HTMLFormElement { 'label', { class: 'choice' }, radio, - h('span', { class: 'choice-label' }, o.label), - o.detail ? h('span', { class: 'choice-detail' }, o.detail) : null, + // Option labels are game names (content); the "own game" escape is a glyph. + o.value === 'own' ? glyph('🗂️', o.label, 'choice-label') : h('span', { class: 'choice-label' }, o.label), + o.detail ? h('span', { class: 'choice-detail sr-only' }, o.detail) : null, ) label.dataset.value = o.value labels.push(label) @@ -95,14 +103,14 @@ function answerForm(jobId: string, prompt: PromptEvent): HTMLFormElement { errorSlot.replaceChildren(...(send.error ? [errorNotice(send.error)] : [])) if (prompt.kind === 'confirm') { actions.replaceChildren( - h('button', { type: 'button', class: 'btn btn-primary', autofocus: prompt.default !== 'no', disabled: send.pending, onclick: () => { submit('yes') } }, 'Yes'), - h('button', { type: 'button', class: 'btn btn-ghost', autofocus: prompt.default === 'no', disabled: send.pending, onclick: () => { submit('no') } }, 'No'), + h('button', { type: 'button', class: 'btn btn-primary', 'aria-label': 'Yes', autofocus: prompt.default !== 'no', disabled: send.pending, onclick: () => { submit('yes') } }, '✔️'), + h('button', { type: 'button', class: 'btn btn-ghost', 'aria-label': 'No', autofocus: prompt.default === 'no', disabled: send.pending, onclick: () => { submit('no') } }, '✖️'), ) return } const btn = actions.querySelector('button') ?? actions.appendChild(h('button', { type: 'submit', class: 'btn btn-primary' })) btn.disabled = !ready() || send.pending - btn.textContent = send.pending ? 'Sending…' : 'Answer' + sendButton(btn, send.pending ? 'Sending…' : 'Answer', send.pending ? '⏳' : '↵') } refresh() return form @@ -127,12 +135,18 @@ function gamePrompt(jobId: string, prompt: PromptEvent): HTMLFormElement { } browser.pick = { appIds, selected, onSelect: pick } const pickBtn = h('button', { type: 'submit', class: 'btn btn-primary' }) - const backBtn = h('button', { type: 'button', class: 'btn btn-ghost', onclick: () => void send.run('') }, 'Back to the list') + const backBtn = h('button', { type: 'button', class: 'btn btn-ghost', 'aria-label': 'Back to the list', onclick: () => void send.run('') }, '↩️') const errorSlot = h('div', { class: 'contents' }) const form = h( 'form', { class: 'prompt prompt-game', 'aria-label': 'Job question' }, - h('p', { class: 'prompt-msg' }, prompt.message, ' ', h('span', { class: 'muted' }, `· ${appIds.size} games can be picked`)), + h( + 'p', + { class: 'prompt-msg' }, + glyph('❓', prompt.message), + ' ', + h('span', { class: 'muted' }, h('span', { 'aria-hidden': 'true' }, `· 🎮 ${appIds.size}`), h('span', { class: 'sr-only' }, `· ${appIds.size} games can be picked`)), + ), browser, errorSlot, h('div', { class: 'actions prompt-game-bar' }, pickBtn, backBtn), @@ -145,7 +159,13 @@ function gamePrompt(jobId: string, prompt: PromptEvent): HTMLFormElement { function refresh(): void { const name = q.library.state.data?.games.find((g) => g.app_id === selected)?.name ?? String(selected) pickBtn.disabled = selected === null || send.pending - pickBtn.textContent = send.pending ? 'Sending…' : selected === null ? 'Select a game' : `Pick ${name}` + // 🎯 + the chosen game's name (content) painted; the verb is spoken. + if (send.pending) sendButton(pickBtn, 'Sending…', '⏳') + else if (selected === null) sendButton(pickBtn, 'Select a game', '🎯') + else { + pickBtn.setAttribute('aria-label', `Pick ${name}`) + pickBtn.replaceChildren(h('span', { 'aria-hidden': 'true' }, `🎯 ${name}`)) + } backBtn.disabled = send.pending errorSlot.replaceChildren(...(send.error ? [errorNotice(send.error)] : [])) } diff --git a/web/src/library/browserState.ts b/web/src/library/browserState.ts index dffcd86..755d806 100644 --- a/web/src/library/browserState.ts +++ b/web/src/library/browserState.ts @@ -5,11 +5,11 @@ import { readHash } from './hashState' import { NO_FILTERS, SORTS, type Filters, type SortKey } from './view' -/** Filter key, checkbox label, and its token in the hash's `f=` list. */ -export const FILTERS: [keyof Filters, string, string][] = [ - ['hideCompleted', 'Hide completed', 'completed'], - ['installedOnly', 'Installed only', 'installed'], - ['pickableOnly', 'Pickable only', 'pickable'], +/** Filter key, spoken checkbox label, its token in the hash's `f=` list, painted glyph. */ +export const FILTERS: [keyof Filters, string, string, string][] = [ + ['hideCompleted', 'Hide completed', 'completed', '🙈🏆'], + ['installedOnly', 'Installed only', 'installed', '💾'], + ['pickableOnly', 'Pickable only', 'pickable', '🎯'], ] export interface BrowserState { diff --git a/web/src/library/browserToolbar.ts b/web/src/library/browserToolbar.ts index d9171c8..14d545d 100644 --- a/web/src/library/browserToolbar.ts +++ b/web/src/library/browserToolbar.ts @@ -4,6 +4,7 @@ import type { LibraryGame } from '../api/contract' import { h } from '../lib/dom' +import { glyph } from '../ui/build' import { FILTERS, type BrowserState } from './browserState' import { SearchBox, type SearchBoxOptions } from './searchBox' import { SORTS, type Filters, type SortKey } from './view' @@ -30,7 +31,7 @@ export class BrowserToolbar { opts.onSort(this.sortSelect.value as SortKey) }, }, - SORTS.map((s) => h('option', { value: s.key }, s.label)), + SORTS.map((s) => h('option', { value: s.key, 'aria-label': s.label }, s.icon)), ) this.checks = new Map( FILTERS.map(([key]) => [ @@ -47,12 +48,12 @@ export class BrowserToolbar { 'div', { class: 'lib-toolbar' }, this.searchBox.el, - h('label', { class: 'lib-sort' }, h('span', { class: 'field-label' }, 'Sort'), this.sortSelect), + h('label', { class: 'lib-sort' }, glyph('↕️', 'Sort', 'field-label'), this.sortSelect), h( 'fieldset', { class: 'lib-filters' }, h('legend', { class: 'sr-only' }, 'Filters'), - FILTERS.map(([key, label]) => h('label', { class: 'check' }, this.checks.get(key), label)), + FILTERS.map(([key, label, , icon]) => h('label', { class: 'check' }, this.checks.get(key), glyph(icon, label))), ), this.count, ) @@ -74,7 +75,12 @@ export class BrowserToolbar { this.searchBox.setSuggestions(games) } - setCount(text: string): void { - this.count.textContent = text + /** "🎮 3/5" (+ 🔍 while a search ranks by relevance); the sentence is spoken. */ + setCount(shown: number, total: number, byRelevance: boolean): void { + const spoken = `${shown} of ${total} games${byRelevance ? ' · by relevance' : ''}` + this.count.replaceChildren( + h('span', { 'aria-hidden': 'true' }, `🎮 ${shown}/${total}${byRelevance ? ' 🔍' : ''}`), + h('span', { class: 'sr-only' }, spoken), + ) } } diff --git a/web/src/library/gameBrowser.ts b/web/src/library/gameBrowser.ts index 1a7ba8f..82629f8 100644 --- a/web/src/library/gameBrowser.ts +++ b/web/src/library/gameBrowser.ts @@ -15,7 +15,7 @@ import type { LibraryGame } from '../api/contract' import { q } from '../api/queries' import { define, h } from '../lib/dom' import { LiveElement } from '../lib/element' -import { errorNotice, loading } from '../ui/build' +import { empty, errorNotice, loading } from '../ui/build' import { stateFromHash, stateToHash, type BrowserState } from './browserState' import { BrowserToolbar } from './browserToolbar' import { buildIndex, search, type Searchable } from './fuzzy' @@ -191,8 +191,8 @@ export class GameBrowser extends LiveElement implements GameBrowserElement { } this.grid.show(this.visible.map((g) => this.card(g))) const query = this.state.query.trim() - this.toolbar.setCount(`${this.visible.length} of ${games.length} games${query ? ' · by relevance' : ''}`) - this.none.replaceChildren(...(this.visible.length === 0 ? [h('p', { class: 'muted' }, 'No game matches.')] : [])) + this.toolbar.setCount(this.visible.length, games.length, query !== '') + this.none.replaceChildren(...(this.visible.length === 0 ? [empty('No game matches.')] : [])) } /** A click: becomes the tab stop; in pick mode an eligible card is selected. */ diff --git a/web/src/library/gameCard.test.ts b/web/src/library/gameCard.test.ts index 4114222..2bb5a82 100644 --- a/web/src/library/gameCard.test.ts +++ b/web/src/library/gameCard.test.ts @@ -1,6 +1,7 @@ import { fireEvent } from '@testing-library/dom' import { describe, expect, it } from 'vitest' import { makeLibGame } from '../test/fixtures' +import { visibleWords } from '../test/visibleWords' import { gameCard, paintCard, placeCard, type CardPaint } from './gameCard' const PLAIN: CardPaint = { reason: null, selected: false, pickMode: false } @@ -70,8 +71,17 @@ describe('gameCard', () => { it('shows only the badge that applies', () => { const card = make({ installed: true }) - expect(card.querySelector('.game-badges')).toHaveTextContent(/^installed$/) - expect(make({ assigned: true }).querySelector('.game-badges')).toHaveTextContent(/^assigned$/) + expect(card.querySelectorAll('.game-badges .pill')).toHaveLength(1) + expect(card.querySelector('.game-badges .pill-neutral')).toHaveTextContent('💾installed') + const assigned = make({ assigned: true }) + expect(assigned.querySelectorAll('.game-badges .pill')).toHaveLength(1) + expect(assigned.querySelector('.game-badges .pill-accent')).toHaveTextContent('🎯assigned') + }) + + it('paints glyphs and numbers only; reasons and meta words are spoken', () => { + const card = make({ assigned: true, installed: true }, { pickMode: true, selected: false, reason: 'Skipped until 2026-10-17' }) + expect(visibleWords(card, [card.querySelector('.game-title')?.textContent ?? ''])).toEqual([]) + expect(card.querySelector('.game-reason')).toHaveTextContent('⏭️ 2026-10-17') }) it('has no badge row for a plain game', () => { diff --git a/web/src/library/gameCard.ts b/web/src/library/gameCard.ts index e5c160d..e5ce184 100644 --- a/web/src/library/gameCard.ts +++ b/web/src/library/gameCard.ts @@ -4,7 +4,8 @@ import { ENDPOINTS, type LibraryGame } from '../api/contract' import { h } from '../lib/dom' -import { metaLine } from './view' +import { pill } from '../ui/build' +import { metaGlyphs, metaLine, reasonGlyph, spokenGlyphs } from './view' export interface CardPaint { /** Why it cannot be picked here, or null. Greys the card out. */ @@ -36,13 +37,13 @@ export function gameCard(game: LibraryGame): HTMLButtonElement { { type: 'button', class: 'game-card', 'data-app-id': game.app_id, tabindex: -1 }, cover(game), h('span', { class: 'game-title' }, game.name), - h('span', { class: 'game-meta' }, metaLine(game)), + spokenGlyphs(metaGlyphs(game), metaLine(game), 'game-meta'), game.assigned || game.installed ? h( 'span', { class: 'game-badges' }, - game.assigned ? h('span', { class: 'pill pill-accent' }, 'assigned') : null, - game.installed ? h('span', { class: 'pill pill-neutral' }, 'installed') : null, + game.assigned ? pill('accent', 'assigned', '🎯') : null, + game.installed ? pill('neutral', 'installed', '💾') : null, ) : null, ) @@ -56,13 +57,15 @@ export function paintCard(card: HTMLButtonElement, { reason, selected, pickMode else card.removeAttribute('aria-pressed') if (pickMode && reason !== null) card.setAttribute('aria-disabled', 'true') else card.removeAttribute('aria-disabled') - let line = card.querySelector('.game-reason') + const line = card.querySelector('.game-reason') if (reason === null) { line?.remove() return } - line ??= card.appendChild(h('span', { class: 'game-reason' })) - line.textContent = reason + // The reason is spoken; the card paints its glyph (and any date) greyed out. + const fresh = spokenGlyphs(reasonGlyph(reason), reason, 'game-reason') + if (line) line.replaceWith(fresh) + else card.append(fresh) } /** Place the card in the grid: its position and whether it is the tab stop. */ diff --git a/web/src/library/searchBox.ts b/web/src/library/searchBox.ts index 4e90424..ac0dec9 100644 --- a/web/src/library/searchBox.ts +++ b/web/src/library/searchBox.ts @@ -6,7 +6,7 @@ import type { LibraryGame } from '../api/contract' import { h } from '../lib/dom' import { uid } from '../lib/ids' -import { metaLine } from './view' +import { reasonOrMeta } from './view' export interface SearchBoxOptions { /** Every edit of the text (typing, or Escape clearing it). */ @@ -36,7 +36,7 @@ export class SearchBox { 'aria-expanded': 'false', 'aria-controls': this.listId, 'aria-autocomplete': 'list', - placeholder: 'Search your games (typos are fine)…', + placeholder: '🔍', }) this.list = h('ul', { id: this.listId, role: 'listbox', class: 'lib-suggest', hidden: true, 'aria-label': 'Suggestions' }) this.el = h('div', { class: 'lib-search' }, this.input, this.list) @@ -138,7 +138,7 @@ export class SearchBox { }, }, h('span', { class: 'lib-suggest-name' }, g.name), - h('span', { class: 'lib-suggest-meta' }, this.opts.reason(g) ?? metaLine(g)), + reasonOrMeta(this.opts.reason(g), g, 'lib-suggest-meta'), ), ) : []), diff --git a/web/src/library/view.ts b/web/src/library/view.ts index a57153d..bf886e0 100644 --- a/web/src/library/view.ts +++ b/web/src/library/view.ts @@ -2,14 +2,16 @@ // the grid component only wires state to them. import type { LibraryGame } from '../api/contract' +import { h } from '../lib/dom' export type SortKey = 'name' | 'recent' | 'completion' | 'hltb' -export const SORTS: { key: SortKey; label: string }[] = [ - { key: 'name', label: 'Name' }, - { key: 'recent', label: 'Recently played' }, - { key: 'completion', label: 'Completion' }, - { key: 'hltb', label: 'Shortest (HLTB)' }, +/** `label` is spoken only; the sort select paints `icon`. */ +export const SORTS: { key: SortKey; label: string; icon: string }[] = [ + { key: 'name', label: 'Name', icon: '🔤' }, + { key: 'recent', label: 'Recently played', icon: '🕐' }, + { key: 'completion', label: 'Completion', icon: '🏆' }, + { key: 'hltb', label: 'Shortest (HLTB)', icon: '⏱️' }, ] export interface Filters { @@ -58,7 +60,7 @@ export function filterGames( ) } -/** "45% · 12 h HLTB · 3.2 h played", the card's one meta line. */ +/** "45% · 12 h HLTB · 3.2 h played", the card's meta line (spoken only). */ export function metaLine(g: LibraryGame): string { const pct = completion(g) const parts = [pct === null ? 'No achievements' : `${Math.floor(pct)}%`] @@ -67,6 +69,34 @@ export function metaLine(g: LibraryGame): string { return parts.join(' · ') } +/** The painted meta line: "🏆 45% · ⏱️ 12 h · ▶️ 3.2 h" (🏆 — without achievements). */ +export function metaGlyphs(g: LibraryGame): string { + const pct = completion(g) + const parts = [`🏆 ${pct === null ? '—' : `${Math.floor(pct)}%`}`] + if (g.hltb_hours !== null) parts.push(`⏱️ ${hours(g.hltb_hours)}`) + if (g.playtime_minutes > 0) parts.push(`▶️ ${hours(g.playtime_minutes / 60)}`) + return parts.join(' · ') +} + function hours(h: number): string { return h >= 10 ? `${Math.round(h)} h` : `${h.toFixed(1)} h` } + +/** Glyph for a server ineligibility reason; a date in it stays painted. */ +export function reasonGlyph(reason: string): string { + const date = /\d{4}-\d{2}-\d{2}/.exec(reason)?.[0] + if (reason.includes('100%')) return '🏆✅' + if (/no achievements/i.test(reason)) return '🏆🚫' + if (/skip/i.test(reason)) return date ? `⏭️ ${date}` : '⏭️' + return date ? `⛔ ${date}` : '⛔' +} + +/** Glyphs painted, words spoken: `text` shown as `painted` with an sr-only twin. */ +export function spokenGlyphs(painted: string, text: string, className: string): HTMLSpanElement { + return h('span', { class: className }, h('span', { 'aria-hidden': 'true' }, painted), h('span', { class: 'sr-only' }, text)) +} + +/** A suggestion's second line: the reason it cannot be picked, else the meta line. */ +export function reasonOrMeta(reason: string | null, g: LibraryGame, className: string): HTMLSpanElement { + return reason === null ? spokenGlyphs(metaGlyphs(g), metaLine(g), className) : spokenGlyphs(reasonGlyph(reason), reason, className) +} diff --git a/web/src/sections/jobs.test.ts b/web/src/sections/jobs.test.ts index 268c1fe..960affc 100644 --- a/web/src/sections/jobs.test.ts +++ b/web/src/sections/jobs.test.ts @@ -37,10 +37,12 @@ describe('jobs list', () => { expect(await screen.findByRole('table')).toBeInTheDocument() expect(screen.getByRole('heading', { name: 'Jobs', level: 1 })).toBeInTheDocument() expect(screen.getByRole('link', { name: 'Pick manual' })).toHaveAttribute('href', '/jobs/?id=a') - expect(screen.getByText('app_id=5 note=x')).toBeInTheDocument() + // Param values painted, keys and the server's summary spoken only. + expect(screen.getByText('5 x')).toHaveAttribute('aria-hidden', 'true') + expect(screen.getByText('app_id=5 note=x')).toHaveClass('sr-only') expect(screen.getByText('1:05')).toBeInTheDocument() - expect(screen.getByText('Picked 5')).toBeInTheDocument() - expect(screen.getByText('Scanning')).toBeInTheDocument() + expect(screen.getByText('Picked 5')).toHaveClass('sr-only') + expect(screen.getByText('Scanning')).toHaveClass('sr-only') expect(screen.getAllByLabelText('running')).toHaveLength(2) }) @@ -106,7 +108,9 @@ describe('job detail', () => { stubApi({ 'GET /api/jobs/nope': apiError(404, 'not_found', 'No job nope.') }) mount('') expect(await screen.findByRole('heading', { name: 'Job not found', level: 1 })).toBeInTheDocument() - expect(screen.getByText('No job nope.')).toBeInTheDocument() + const notice = document.querySelector('[data-code="not_found"]') + expect(notice?.getAttribute('aria-label')).toMatch(/No job nope\.$/) + expect(notice).toHaveTextContent('nope') expect(screen.getByRole('link', { name: 'See all jobs' })).toHaveAttribute('href', '/jobs/') expect(document.querySelector('job-progress')).toBeNull() expect(FakeEventSource.all).toHaveLength(0) @@ -127,8 +131,9 @@ describe('job detail', () => { at('/jobs/?id=gone') stubApi({ 'GET /api/jobs/gone': apiError(404, 'not_found') }) mount('') - const title = await screen.findByText('Job not found', { selector: '.notice-title' }) - expect(title.parentElement?.querySelectorAll('p')).toHaveLength(2) + await screen.findByRole('heading', { name: 'Job not found', level: 1 }) + const notice = document.querySelector('[data-code="not_found"]') + expect(notice?.getAttribute('aria-label')).toMatch(/keeps the last 50\.$/) }) it('treats a bare as an unknown job', async () => { diff --git a/web/src/sections/jobs.ts b/web/src/sections/jobs.ts index 509b194..77b5bda 100644 --- a/web/src/sections/jobs.ts +++ b/web/src/sections/jobs.ts @@ -6,13 +6,13 @@ import { ApiFailure } from '../api/client' import { explain } from '../api/errors' import type { Job } from '../api/jobContract' import { q } from '../api/queries' -import { commandLabel } from '../commands/catalog' +import { COMMAND_ICON, commandLabel } from '../commands/catalog' import '../jobs/jobProgress' import { stateBadge } from '../jobs/progress' import { define, h, hx } from '../lib/dom' import { LiveElement } from '../lib/element' import { jobHref, pageHref } from '../lib/runner' -import { card, empty, errorNotice, link, loading, notice } from '../ui/build' +import { card, empty, errorNotice, glyph, link, loading, notice } from '../ui/build' import { dateTime, duration } from '../ui/format' /** The `id` query parameter, or null for the list (an empty `?id=` too). */ @@ -27,18 +27,32 @@ function params(j: Job): string { .join(' ') } +/** The command's glyph painted, its name spoken. */ +function commandGlyph(command: Job['command']): HTMLSpanElement { + return glyph(COMMAND_ICON[command], commandLabel(command), 'job-cmd') +} + /** One row, plus its duration cell so ticks can refresh just that. */ function row(j: Job): { tr: HTMLTableRowElement; took: HTMLTableCellElement } { const args = params(j) + // Param values are content (ids, minutes); their keys are spoken only. + const values = Object.values(j.params).map(String).join(' ') const took = h('td', { class: 'num mono' }) + const summary = j.summary ?? j.progress?.label ?? '' const tr = h( 'tr', {}, - h('td', {}, h('a', { href: jobHref(j.id) }, commandLabel(j.command)), args ? h('span', { class: 'muted mono' }, ` ${args}`) : null), + h( + 'td', + {}, + h('a', { href: jobHref(j.id) }, commandGlyph(j.command)), + args ? h('span', { class: 'muted mono' }, h('span', { 'aria-hidden': 'true' }, ` ${values}`), h('span', { class: 'sr-only' }, ` ${args}`)) : null, + // The server's summary sentence is spoken only; the state badge paints the outcome. + summary ? h('span', { class: 'sr-only' }, ` ${summary}`) : null, + ), h('td', {}, stateBadge(j.state)), h('td', { class: 'muted' }, dateTime(j.created_at)), took, - h('td', { class: 'ellipsis' }, j.summary ?? j.progress?.label ?? ''), ) return { tr, took } } @@ -72,18 +86,17 @@ export class JobListElement extends LiveElement { h( 'tr', {}, - h('th', { scope: 'col' }, 'Command'), - h('th', { scope: 'col' }, 'State'), - h('th', { scope: 'col' }, 'Started'), - h('th', { scope: 'col', class: 'num' }, 'Took'), - h('th', { scope: 'col' }, 'Summary'), + h('th', { scope: 'col' }, glyph('⌨️', 'Command')), + h('th', { scope: 'col' }, glyph('🚦', 'State')), + h('th', { scope: 'col' }, glyph('🕐', 'Started')), + h('th', { scope: 'col', class: 'num' }, glyph('⏱️', 'Took')), ), ), this.body, ), ) - const title = h('h1', {}, 'Jobs') - const sub = h('p', { class: 'sub' }, 'The last 50 jobs. They keep running if you close the page.') + const title = h('h1', { class: 'sr-only' }, 'Jobs') + const sub = h('p', { class: 'sr-only' }, 'The last 50 jobs. They keep running if you close the page.') this.replaceChildren(pageHead(title, sub, null), card(null, [this.status, this.table])) this.watch(q.jobs) this.tick(1000) @@ -112,13 +125,16 @@ export class JobListElement extends LiveElement { } function notFound(id: string, error: ApiFailure): HTMLDivElement { - return notice( + // ❓ + the id painted; the explanation and the server's message are spoken. + const el = notice( 'warning', - 'Job not found', - h('p', { class: 'm0' }, 'There is no job ', h('span', { class: 'mono' }, id), '. It may have been pruned: the history keeps the last 50.'), - error.message ? h('p', { class: 'm0 muted' }, error.message) : null, - h('p', { class: 'm0' }, h('a', { href: pageHref('/jobs') }, 'See all jobs')), + null, + h('p', { class: 'm0' }, h('span', { 'aria-hidden': 'true' }, '❓ '), h('span', { class: 'mono' }, id)), + h('p', { class: 'm0' }, link(pageHref('/jobs'), glyph('📋', 'See all jobs'), '')), ) + el.dataset.code = 'not_found' + el.setAttribute('aria-label', `Job not found. There is no job ${id}. It may have been pruned: the history keeps the last 50.${error.message ? ` ${error.message}` : ''}`) + return el } /** `/jobs/?id=…`: one job. `` is mounted once and owns itself. */ @@ -139,7 +155,7 @@ export class JobDetailElement extends LiveElement { this.sub = h('p', { class: 'sub' }) this.status = h('div', { class: 'contents' }) this.mounted = false - this.replaceChildren(pageHead(this.heading, this.sub, link(pageHref('/jobs'), 'All jobs', 'btn btn-ghost')), this.status) + this.replaceChildren(pageHead(this.heading, this.sub, link(pageHref('/jobs'), glyph('📋', 'All jobs'), 'btn btn-ghost')), this.status) // Subscribed by hand, not via watch(): an unknown id stops polling. let live = true const off = q.job(this.jobId).subscribe(() => { @@ -156,8 +172,13 @@ export class JobDetailElement extends LiveElement { const id = this.jobId const { data, error, loading: waiting } = q.job(id).state const missing = !data && error instanceof ApiFailure && error.code === 'not_found' ? error : null - this.heading.textContent = data ? commandLabel(data.command) : missing ? 'Job not found' : 'Job' - this.sub.replaceChildren('Job ', h('span', { class: 'mono' }, id), data ? ` · created ${dateTime(data.created_at)}` : '') + // Heading: the command's glyph (❓ when the id is unknown, ⚙️ while loading), name spoken. + this.heading.replaceChildren(data ? commandGlyph(data.command) : missing ? glyph('❓', 'Job not found') : glyph('⚙️', 'Job')) + this.sub.replaceChildren( + h('span', { class: 'sr-only' }, 'Job '), + h('span', { class: 'mono' }, id), + data ? h('span', {}, h('span', { 'aria-hidden': 'true' }, ' · 🕐 '), h('span', { class: 'sr-only' }, ' · created '), dateTime(data.created_at)) : '', + ) this.status.replaceChildren( ...(missing ? [notFound(id, missing)] : error ? [errorNotice(error)] : waiting ? [loading('job')] : []), ) diff --git a/web/src/sections/library.test.ts b/web/src/sections/library.test.ts index 64bf54c..631575e 100644 --- a/web/src/sections/library.test.ts +++ b/web/src/sections/library.test.ts @@ -108,10 +108,10 @@ describe('Library page', () => { view.remove() at('/library/#view=installed') window.dispatchEvent(new HashChangeEvent('hashchange')) - expect(view.querySelector('[aria-pressed="true"]')).toHaveTextContent('All games') + expect(view.querySelector('[aria-pressed="true"]')).toHaveAttribute('aria-label', 'All games') page.append(view) // re-attached: same controls, view re-read from the hash expect(view.querySelectorAll('.seg')).toHaveLength(1) - expect(view.querySelector('[aria-pressed="true"]')).toHaveTextContent('Installed') + expect(view.querySelector('[aria-pressed="true"]')).toHaveAttribute('aria-label', 'Installed') }) it('says when nothing is installed', async () => { diff --git a/web/src/sections/library.ts b/web/src/sections/library.ts index 63d6c2c..df06952 100644 --- a/web/src/sections/library.ts +++ b/web/src/sections/library.ts @@ -8,14 +8,15 @@ import { define, h, hx } from '../lib/dom' import { LiveElement } from '../lib/element' import '../library/gameBrowser' import { readHash, writeHash } from '../library/hashState' -import { card, empty, errorNotice, loading } from '../ui/build' +import { card, empty, errorNotice, glyph, loading, pill } from '../ui/build' import { bytes } from '../ui/format' type View = 'all' | 'installed' -const VIEWS: [View, string][] = [ - ['all', 'All games'], - ['installed', 'Installed'], +/** View key, spoken label, painted glyph. */ +const VIEWS: [View, string, string][] = [ + ['all', 'All games', '🗂️'], + ['installed', 'Installed', '💾'], ] const viewFromHash = (): View => (readHash().get('view') === 'installed' ? 'installed' : 'all') @@ -65,10 +66,10 @@ export class InstalledTableElement extends LiveElement { h( 'tr', {}, - h('th', { scope: 'col' }, 'Game'), - h('th', { scope: 'col' }, 'App id'), - h('th', { scope: 'col', class: 'num' }, 'Size'), - h('th', { scope: 'col' }, 'Role'), + h('th', { scope: 'col' }, glyph('🎮', 'Game')), + h('th', { scope: 'col' }, glyph('#', 'App id')), + h('th', { scope: 'col', class: 'num' }, glyph('💽', 'Size')), + h('th', { scope: 'col' }, glyph('🏷️', 'Role')), ), ), h( @@ -84,9 +85,9 @@ export class InstalledTableElement extends LiveElement { h( 'td', {}, - g.assigned ? h('span', { class: 'pill pill-accent' }, 'assigned') : null, - g.protected ? h('span', { class: 'pill pill-neutral' }, 'protected') : null, - !g.assigned && !g.protected ? h('span', { class: 'muted' }, 'uninstall candidate') : null, + g.assigned ? pill('accent', 'assigned', '🎯') : null, + g.protected ? pill('neutral', 'protected', '🛡️') : null, + !g.assigned && !g.protected ? glyph('🗑️', 'uninstall candidate', 'muted') : null, ), ), ), @@ -95,7 +96,17 @@ export class InstalledTableElement extends LiveElement { ) : null, ], - { aside: data ? h('span', { class: 'muted' }, `${games.length} games · ${bytes(total)}`) : null }, + { + icon: '💾', + aside: data + ? h( + 'span', + { class: 'muted' }, + h('span', { 'aria-hidden': 'true' }, `🎮 ${games.length} · 💽 ${bytes(total)}`), + h('span', { class: 'sr-only' }, `${games.length} games · ${bytes(total)}`), + ) + : null, + }, ), ) } @@ -120,18 +131,19 @@ export class LibraryViewElement extends HTMLElement { const seg = h( 'div', { class: 'seg', role: 'group', 'aria-label': 'Library view' }, - VIEWS.map(([key, label]) => { + VIEWS.map(([key, label, icon]) => { const btn = h( 'button', { type: 'button', class: 'btn btn-ghost btn-small', + 'aria-label': label, onclick: () => { writeHash({ view: key === 'all' ? null : key }) this.show(key) }, }, - label, + h('span', { 'aria-hidden': 'true' }, icon), ) this.buttons.set(key, btn) return btn diff --git a/web/src/sections/picks.ts b/web/src/sections/picks.ts index 94759fd..32ef01b 100644 --- a/web/src/sections/picks.ts +++ b/web/src/sections/picks.ts @@ -7,6 +7,11 @@ import { define, h } from '../lib/dom' import { LiveElement } from '../lib/element' import { card, empty, errorNotice, loading } from '../ui/build' +/** Glyphs and numbers painted, the sentence spoken. */ +function glyphText(painted: string, spoken: string): HTMLSpanElement { + return h('span', { class: 'muted' }, h('span', { 'aria-hidden': 'true' }, painted), h('span', { class: 'sr-only' }, spoken)) +} + /** Page subtitle: the assigned game, once known. */ export class PicksSubElement extends LiveElement { protected override setup(): void { @@ -41,7 +46,13 @@ export class ManualPicksElement extends LiveElement { h( 'li', { class: 'row' }, - h('span', { class: 'grow' }, h('strong', {}, p.name), ' ', h('span', { class: 'muted' }, `· picked ${p.age_days} d ago · ${p.app_id}`)), + h( + 'span', + { class: 'grow' }, + h('strong', {}, p.name), + ' ', + glyphText(`· 🕐 ${p.age_days} d · ${p.app_id}`, `· picked ${p.age_days} d ago · ${p.app_id}`), + ), abandon(p.app_id), ), ), @@ -50,7 +61,7 @@ export class ManualPicksElement extends LiveElement { h( 'li', { class: 'row' }, - h('span', { class: 'grow' }, h('strong', {}, p.name), ' ', h('span', { class: 'muted' }, `· kept · no lock · ${p.app_id}`)), + h('span', { class: 'grow' }, h('strong', {}, p.name), ' ', glyphText(`· 📌 🔓 · ${p.app_id}`, `· kept · no lock · ${p.app_id}`)), abandon(p.app_id), ), ), @@ -58,7 +69,7 @@ export class ManualPicksElement extends LiveElement { none ? h('div', { class: 'actions' }, commandButton({ name: 'abandon-pick', label: 'Abandon a pick by app id…' })) : null, - ]), + ], { icon: '📌' }), ) } } diff --git a/web/src/sections/store.test.ts b/web/src/sections/store.test.ts index 9cd83b5..9f6efc9 100644 --- a/web/src/sections/store.test.ts +++ b/web/src/sections/store.test.ts @@ -3,23 +3,28 @@ import { describe, expect, it } from 'vitest' import { q } from '../api/queries' import { makeStatus } from '../test/fixtures' import { mount, stubApi } from '../test/harness' +import { visibleWords } from '../test/visibleWords' import './store' describe('store notice', () => { it('says the store is blocked', async () => { stubApi({ 'GET /api/status': makeStatus({ store_blocked: true }) }) - mount('') - expect(await screen.findByText('Store blocked')).toBeInTheDocument() - expect(screen.getByText(/capped at 30 minutes/)).toBeInTheDocument() - expect(screen.getByRole('status')).toHaveClass('notice-info') + const el = mount('') + const notice = await screen.findByRole('status') + expect(notice).toHaveClass('notice-info') + expect(notice).toHaveAttribute('data-blocked', 'true') + expect(screen.getByText(/Store blocked\. .*capped at 30 minutes/)).toHaveClass('sr-only') + expect(visibleWords(el)).toEqual([]) }) it('warns when it is open', async () => { stubApi({ 'GET /api/status': makeStatus({ store_blocked: false }) }) - mount('') - expect(await screen.findByText('Store unblocked')).toBeInTheDocument() - expect(screen.getByText(/re-blocks automatically/)).toBeInTheDocument() - expect(screen.getByRole('status')).toHaveClass('notice-warning') + const el = mount('') + const notice = await screen.findByRole('status') + expect(notice).toHaveClass('notice-warning') + expect(notice).toHaveAttribute('data-blocked', 'false') + expect(screen.getByText(/Store unblocked\. .*re-blocks automatically/)).toHaveClass('sr-only') + expect(visibleWords(el)).toEqual([]) }) it('shows no notice until the status is known', () => { diff --git a/web/src/sections/store.ts b/web/src/sections/store.ts index b9fa818..18f0316 100644 --- a/web/src/sections/store.ts +++ b/web/src/sections/store.ts @@ -2,7 +2,7 @@ // right now. Nothing shows until the status is known. import { q } from '../api/queries' -import { define } from '../lib/dom' +import { define, h } from '../lib/dom' import { LiveElement } from '../lib/element' import { notice } from '../ui/build' @@ -17,11 +17,13 @@ export class StoreNoticeElement extends LiveElement { this.replaceChildren() return } - this.replaceChildren( - data.store_blocked - ? notice('info', 'Store blocked', 'Unblocking takes a typed phrase and is capped at 30 minutes.') - : notice('warning', 'Store unblocked', 'The store is open right now; it re-blocks automatically.'), - ) + // Textgate: 🛒 + lock state painted (tone is the 2nd channel), the sentence spoken. + const [tone, icon, spoken] = data.store_blocked + ? (['info', '🛒🔒', 'Store blocked. Unblocking takes a typed phrase and is capped at 30 minutes.'] as const) + : (['warning', '🛒🔓', 'Store unblocked. The store is open right now; it re-blocks automatically.'] as const) + const el = notice(tone, null, h('span', { 'aria-hidden': 'true' }, icon), h('span', { class: 'sr-only' }, spoken)) + el.dataset.blocked = String(data.store_blocked) + this.replaceChildren(el) } }