From 9f52d27893b2d7a781954092ad66b81e960b3935 Mon Sep 17 00:00:00 2001 From: Krzysztof kuhy Rudnicki Date: Wed, 11 Nov 2026 11:55:30 +0100 Subject: [PATCH] web: backlog page paints glyphs and numbers Co-Authored-By: Claude Opus 5.5 --- .../commands/runnerDialog.failures.test.ts | 2 +- web/src/sections/backlog/filterPanel.test.ts | 2 +- web/src/sections/backlog/filterPanel.ts | 115 +++++++++--------- web/src/sections/backlog/gameTable.test.ts | 5 +- web/src/sections/backlog/gameTable.ts | 14 +-- web/src/sections/backlog/glyphs.ts | 57 +++++++++ web/src/sections/backlog/painted.testutil.ts | 9 ++ web/src/sections/backlog/planner.test.ts | 13 +- web/src/sections/backlog/planner.ts | 13 +- web/src/sections/backlog/plannerTable.test.ts | 5 +- web/src/sections/backlog/plannerTable.ts | 25 +++- web/src/sections/backlog/stats.test.ts | 6 +- web/src/sections/backlog/stats.ts | 61 +++++----- web/src/sections/backlog/summary.test.ts | 23 ++-- web/src/sections/backlog/summary.ts | 81 ++++++------ web/src/sections/backlog/textgate.test.ts | 81 ++++++++++++ web/src/test/runnerHelpers.ts | 5 +- 17 files changed, 342 insertions(+), 175 deletions(-) create mode 100644 web/src/sections/backlog/glyphs.ts create mode 100644 web/src/sections/backlog/painted.testutil.ts create mode 100644 web/src/sections/backlog/textgate.test.ts diff --git a/web/src/commands/runnerDialog.failures.test.ts b/web/src/commands/runnerDialog.failures.test.ts index 6a99e17..fe38212 100644 --- a/web/src/commands/runnerDialog.failures.test.ts +++ b/web/src/commands/runnerDialog.failures.test.ts @@ -22,7 +22,7 @@ describe(' locked', () => { const lock = must(document.querySelector('.notice-warning')) expect(lock).toHaveAttribute('aria-label', 'Locked: Manual pick active') expect(lock).toHaveTextContent('๐Ÿ”’') - expect(field(/N$/)).toBeDisabled() + expect(field('N')).toBeDisabled() expect(document.querySelector('.phrase')).toBeNull() expect(run).toBeDisabled() submit(run) diff --git a/web/src/sections/backlog/filterPanel.test.ts b/web/src/sections/backlog/filterPanel.test.ts index fc99e23..35cd364 100644 --- a/web/src/sections/backlog/filterPanel.test.ts +++ b/web/src/sections/backlog/filterPanel.test.ts @@ -121,7 +121,7 @@ describe('FilterPanel', () => { it('shows each slider value, the hours cap as off or N h', () => { const { el, panel } = setup() expect(getByText(el, '4 h/day')).toBeInTheDocument() - expect(getByText(el, 'off')).toBeInTheDocument() + expect(getByText(el, 'โˆž')).toBeInTheDocument() panel.sync(makeFilters({ maxHoursPerGame: 50 })) expect(getByText(el, '50 h')).toBeInTheDocument() }) diff --git a/web/src/sections/backlog/filterPanel.ts b/web/src/sections/backlog/filterPanel.ts index ce8ae4c..6e10023 100644 --- a/web/src/sections/backlog/filterPanel.ts +++ b/web/src/sections/backlog/filterPanel.ts @@ -1,27 +1,32 @@ // The planner's estimate filters (was FilterPanel.tsx). Built once; `sync()` // writes values, active segments and conditional rows in place, so a slider // being dragged or a date being typed never loses focus. +// Textgate: every label is a glyph (glyphs.ts) with its words spoken only; +// slider values (numbers + units) stay painted. import { h } from '../../lib/dom' import { SELECTABLE_TIERS } from '../../protondb' import type { EstimateBasis, Filters, PlaytimeMode, ProtonMode, WebDefaults } from '../../types' +import { glyph } from '../../ui/build' +import { ANY_GLYPH, BASIS_GLYPH, TIER_GLYPH } from './glyphs' type Update = (patch: Partial) => void +interface Seg { id: T; label: string; icon: string } -const BASES: readonly { id: EstimateBasis; label: string }[] = [ - { id: 'rush', label: 'Rush' }, - { id: 'leisure', label: 'Leisure' }, - { id: 'worst', label: 'Worst' }, - { id: 'pace', label: 'Pace' }, +const BASES: readonly Seg[] = [ + { id: 'rush', label: 'Rush', icon: BASIS_GLYPH.rush }, + { id: 'leisure', label: 'Leisure', icon: BASIS_GLYPH.leisure }, + { id: 'worst', label: 'Worst', icon: BASIS_GLYPH.worst }, + { id: 'pace', label: 'Pace', icon: BASIS_GLYPH.pace }, ] -const PROTON: readonly { id: ProtonMode; label: string }[] = [ - { id: 'playable', label: 'Playable (CLI rule)' }, - { id: 'minTier', label: 'Min tier' }, +const PROTON: readonly Seg[] = [ + { id: 'playable', label: 'Playable (CLI rule)', icon: 'โŒจ๏ธ' }, + { id: 'minTier', label: 'Min tier', icon: '๐Ÿฅ‡โ‰ฅ' }, ] -const PLAYTIME: readonly { id: PlaytimeMode; label: string }[] = [ - { id: 'all', label: 'All' }, - { id: 'started', label: 'Started' }, - { id: 'untouched', label: 'Untouched' }, +const PLAYTIME: readonly Seg[] = [ + { id: 'all', label: 'All', icon: ANY_GLYPH }, + { id: 'started', label: 'Started', icon: 'โ–ถ๏ธ' }, + { id: 'untouched', label: 'Untouched', icon: 'โˆ…' }, ] type NumberKey = 'dailyHours' | 'minCountComp' | 'minComp100' | 'minConfidenceSum' | 'maxHoursPerGame' | 'fallbackHours' @@ -33,12 +38,14 @@ interface Slider { show: (f: Filters) => string } +const hint = (text: string) => h('p', { class: 'hint sr-only' }, text) + export class FilterPanel { readonly el: HTMLElement private readonly syncs: ((f: Filters) => void)[] = [] constructor(defaults: WebDefaults, update: Update, onReset: () => void) { - const slider = (key: NumberKey, label: string, min: number, max: number, step: number, show: Slider['show']) => { + const slider = (key: NumberKey, icon: string, label: string, min: number, max: number, step: number, show: Slider['show']) => { const val = h('span', { class: 'val' }) const input = h('input', { type: 'range', min, max, step, 'aria-label': label }) input.addEventListener('input', () => { @@ -50,18 +57,22 @@ export class FilterPanel { input.value = String(f[key]) val.textContent = show(f) }) - return { label: h('label', {}, `${label} `, val), input } + return { label: h('label', {}, glyph(icon, label), ' ', val), input } } - const segmented = (items: readonly { id: T; label: string }[], current: (f: Filters) => T, set: (id: T) => void) => { + const segmented = (items: readonly Seg[], current: (f: Filters) => T, set: (id: T) => void) => { const buttons = items.map((it) => - h('button', { type: 'button', class: 'seg', onclick: () => { set(it.id) } }, it.label), + h('button', { type: 'button', class: 'seg', 'aria-label': it.label, onclick: () => { set(it.id) } }, it.icon), ) this.syncs.push((f) => { - buttons.forEach((b, i) => b.classList.toggle('active', items[i]?.id === current(f))) + buttons.forEach((b, i) => { + const on = items[i]?.id === current(f) + b.classList.toggle('active', on) + b.setAttribute('aria-pressed', String(on)) + }) }) return h('div', { class: 'segmented' }, buttons) } - const check = (label: string, read: (f: Filters) => boolean, set: (on: boolean) => void) => { + const check = (icon: string, label: string, read: (f: Filters) => boolean, set: (on: boolean) => void) => { const input = h('input', { type: 'checkbox' }) input.addEventListener('change', () => { set(input.checked) @@ -69,7 +80,7 @@ export class FilterPanel { this.syncs.push((f) => { input.checked = read(f) }) - return h('label', { class: 'check' }, input, label) + return h('label', { class: 'check' }, input, glyph(icon, label)) } const shownWhen = (el: E, when: (f: Filters) => boolean): E => { this.syncs.push((f) => { @@ -77,17 +88,22 @@ export class FilterPanel { }) return el } + const heading = (icon: string, label: string) => h('label', {}, glyph(icon, label)) - const daily = slider('dailyHours', 'Daily play time', 0.5, 16, 0.5, (f) => `${f.dailyHours} h/day`) - const minComp = slider('minCountComp', 'Min HLTB completions', 0, 100, 1, (f) => String(f.minCountComp)) - const min100 = slider('minComp100', 'Min polled completionist times', 0, 50, 1, (f) => String(f.minComp100)) - const minConf = slider('minConfidenceSum', 'Min confidence sum', 0, 150, 1, (f) => String(f.minConfidenceSum)) - const maxH = slider('maxHoursPerGame', 'Max time per game', 0, 200, 5, (f) => - f.maxHoursPerGame > 0 ? `${f.maxHoursPerGame} h` : 'off', + const daily = slider('dailyHours', 'โฐ', 'Daily play time', 0.5, 16, 0.5, (f) => `${f.dailyHours} h/day`) + const minComp = slider('minCountComp', '#', 'Min HLTB completions', 0, 100, 1, (f) => String(f.minCountComp)) + const min100 = slider('minComp100', '๐Ÿ’ฏ', 'Min polled completionist times', 0, 50, 1, (f) => String(f.minComp100)) + const minConf = slider('minConfidenceSum', 'ฮฃ', 'Min confidence sum', 0, 150, 1, (f) => String(f.minConfidenceSum)) + const maxH = slider('maxHoursPerGame', 'โณ', 'Max time per game', 0, 200, 5, (f) => + f.maxHoursPerGame > 0 ? `${f.maxHoursPerGame} h` : 'โˆž', ) - const fallback = slider('fallbackHours', 'Fallback estimate', 1, 100, 1, (f) => `${f.fallbackHours} h`) + const fallback = slider('fallbackHours', 'โ“', 'Fallback estimate', 1, 100, 1, (f) => `${f.fallbackHours} h`) - const tier = h('select', { 'aria-label': 'Minimum ProtonDB tier' }, SELECTABLE_TIERS.map((t) => h('option', { value: t }, t))) + const tier = h( + 'select', + { 'aria-label': 'Minimum ProtonDB tier' }, + SELECTABLE_TIERS.map((t) => h('option', { value: t, 'aria-label': t }, TIER_GLYPH[t])), + ) tier.addEventListener('change', () => { update({ protonMinTier: tier.value }) }) @@ -103,7 +119,7 @@ export class FilterPanel { date.value = f.targetDate }) const clear = shownWhen( - h('button', { type: 'button', class: 'ghost', onclick: () => { update({ targetDate: '' }) } }, 'Clear'), + h('button', { type: 'button', class: 'ghost', 'aria-label': 'Clear', onclick: () => { update({ targetDate: '' }) } }, 'โœ•'), (f) => f.targetDate !== '', ) @@ -113,66 +129,47 @@ export class FilterPanel { h( 'div', { class: 'panel-head' }, - h('h2', {}, 'Filters'), - h('button', { type: 'button', class: 'ghost', onclick: () => { onReset() } }, 'Reset to CLI defaults'), - ), - h( - 'section', - { class: 'field' }, - h('label', {}, 'Estimate basis'), - segmented(BASES, (f) => f.basis, (basis) => { update({ basis }) }), + h('h2', {}, glyph('๐ŸŽš๏ธ', 'Filters')), + h('button', { type: 'button', class: 'ghost', 'aria-label': 'Reset to CLI defaults', onclick: () => { onReset() } }, 'โ†บ โŒจ๏ธ'), ), + h('section', { class: 'field' }, heading('๐Ÿ“', 'Estimate basis'), segmented(BASES, (f) => f.basis, (basis) => { update({ basis }) })), h('section', { class: 'field' }, daily.label, daily.input), h( 'section', { class: 'field' }, minComp.label, minComp.input, - h('p', { class: 'hint' }, `Higher = more reliable HLTB times (CLI default ${defaults.min_count_comp}).`), - ), - h( - 'details', - { class: 'field' }, - h('summary', {}, 'Advanced confidence'), - min100.label, - min100.input, - minConf.label, - minConf.input, + hint(`Higher = more reliable HLTB times (CLI default ${defaults.min_count_comp}).`), ), + h('details', { class: 'field' }, h('summary', {}, glyph('๐Ÿ”ฌ', 'Advanced confidence')), min100.label, min100.input, minConf.label, minConf.input), h( 'section', { class: 'field' }, - h('label', {}, 'ProtonDB compatibility'), + heading('๐Ÿง', 'ProtonDB compatibility'), segmented(PROTON, (f) => f.protonMode, (protonMode) => { update({ protonMode }) }), shownWhen( h( 'div', { class: 'subfield' }, tier, - check('Keep games with no ProtonDB data', (f) => f.protonTreatMissingAsPass, (on) => { + check('โ“', 'Keep games with no ProtonDB data', (f) => f.protonTreatMissingAsPass, (on) => { update({ protonTreatMissingAsPass: on }) }), ), (f) => f.protonMode === 'minTier', ), ), + h('section', { class: 'field' }, maxH.label, maxH.input, hint('Hide games longer than this (0 = no cap).')), h( 'section', { class: 'field' }, - maxH.label, - maxH.input, - h('p', { class: 'hint' }, 'Hide games longer than this (0 = no cap).'), - ), - h( - 'section', - { class: 'field' }, - h('label', {}, 'Playtime'), + heading('โฑ', 'Playtime'), segmented(PLAYTIME, (f) => f.playtimeMode, (playtimeMode) => { update({ playtimeMode }) }), ), h( 'section', { class: 'field' }, - check('Include games with no HLTB data', (f) => f.includeNoData, (on) => { + check('โ“', 'Include games with no HLTB data', (f) => f.includeNoData, (on) => { update({ includeNoData: on }) }), shownWhen(h('div', { class: 'subfield' }, fallback.label, fallback.input), (f) => f.includeNoData), @@ -180,9 +177,9 @@ export class FilterPanel { h( 'section', { class: 'field' }, - h('label', {}, 'Target finish date'), + heading('๐Ÿ', 'Target finish date'), h('div', { class: 'subfield row' }, date, clear), - h('p', { class: 'hint' }, 'Pick a date to see the hours/day required.'), + hint('Pick a date to see the hours/day required.'), ), ) } diff --git a/web/src/sections/backlog/gameTable.test.ts b/web/src/sections/backlog/gameTable.test.ts index 10bf3ce..3960f22 100644 --- a/web/src/sections/backlog/gameTable.test.ts +++ b/web/src/sections/backlog/gameTable.test.ts @@ -11,7 +11,8 @@ describe(' loading', () => { it('shows loading until the dataset arrives', () => { stubApi({ 'GET /api/dataset': () => new Promise(() => undefined) }) mount('') - expect(screen.getByText(/Loading your backlog/i)).toBeInTheDocument() + expect(screen.getByRole('status')).toHaveTextContent('Loading backlog') + expect(document.querySelector('game-table .spinner')).not.toBeNull() }) it('renders the planner once data loads', async () => { @@ -24,7 +25,7 @@ describe(' loading', () => { stubApi({ 'GET /api/dataset': apiError(500, 'boom') }) mount('') await flush() - expect(screen.getByText('Could not load data: API returned 500 Error')).toBeInTheDocument() + expect(screen.getByRole('alert')).toHaveAttribute('data-code') expect(screen.getByText('./run.sh serve')).toBeInTheDocument() }) diff --git a/web/src/sections/backlog/gameTable.ts b/web/src/sections/backlog/gameTable.ts index 5cf418a..2936972 100644 --- a/web/src/sections/backlog/gameTable.ts +++ b/web/src/sections/backlog/gameTable.ts @@ -6,10 +6,9 @@ import { q } from '../../api/queries' import { h } from '../../lib/dom' import { LiveElement } from '../../lib/element' +import { commandLine, errorNotice, loading } from '../../ui/build' import { Planner } from './planner' -const message = (e: unknown) => (e instanceof Error ? e.message : String(e)) - export class GameTableElement extends LiveElement { private planner: Planner | null = null @@ -24,15 +23,10 @@ export class GameTableElement extends LiveElement { const { data, error } = q.dataset.state if (!data) { this.planner = null + // Textgate: โ›” + the server's own message + the recovery command; the + // explanation is spoken only (errorNotice). this.replaceChildren( - error - ? h( - 'div', - { class: 'status' }, - h('p', { class: 'error' }, `Could not load data: ${message(error)}`), - h('p', { class: 'hint' }, 'Is the backend running? Start it with ', h('code', {}, './run.sh serve'), '.'), - ) - : h('div', { class: 'status' }, h('p', { class: 'hint' }, 'Loading your backlogโ€ฆ')), + h('div', { class: 'status' }, error ? errorNotice(error, commandLine('./run.sh serve')) : loading('backlog')), ) return } diff --git a/web/src/sections/backlog/glyphs.ts b/web/src/sections/backlog/glyphs.ts new file mode 100644 index 0000000..486fc94 --- /dev/null +++ b/web/src/sections/backlog/glyphs.ts @@ -0,0 +1,57 @@ +// Backlog pictograms (textgate: these are painted, the words are spoken only). +// One glyph per idea across the stats card, the planner filters, the summary +// cards and the table headers, so a glyph learned in one place reads the same +// everywhere. + +import type { EstimateBasis } from '../../types' +import { glyph } from '../../ui/build' + +export const BASIS_GLYPH: Record = { + rush: '๐Ÿ‡', + leisure: '๐Ÿข', + worst: '๐ŸŒ', + pace: '๐Ÿ‘ค', +} + +/** Player style vs HLTB; the `--