mirror of
https://github.com/kuhyx/steam-backlog-enforcer.git
synced 2026-11-21 00:12:30 +01:00
Route gaming, backlog and library icons
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01WzxdWYNS1qAMRdgAtbr5Rq
This commit is contained in:
parent
173d296517
commit
b913ff67f5
@ -3,7 +3,9 @@
|
||||
|
||||
import type { EstimateResult } from '../../estimate'
|
||||
import { isoDate } from '../../format'
|
||||
import { iconInline } from '../../icons/render'
|
||||
import type { Filters, WebStateInfo } from '../../types'
|
||||
import { h } from '../dom'
|
||||
|
||||
const W = 820
|
||||
const H = 320
|
||||
@ -83,10 +85,14 @@ export function timelineChart(
|
||||
const box = document.createElement('div')
|
||||
box.className = 'chart'
|
||||
if (pts.length < 2) {
|
||||
const hint = document.createElement('p')
|
||||
hint.className = 'hint empty-state'
|
||||
hint.innerHTML = '<span class="empty-icon" aria-hidden="true">📭</span><span class="sr-only">Not enough games in scope to draw a timeline.</span>'
|
||||
box.append(hint)
|
||||
box.append(
|
||||
h(
|
||||
'p',
|
||||
{ class: 'hint empty-state' },
|
||||
iconInline('state.empty', 'empty-icon'),
|
||||
h('span', { class: 'sr-only' }, 'Not enough games in scope to draw a timeline.'),
|
||||
),
|
||||
)
|
||||
return box
|
||||
}
|
||||
box.append(timelineSvg(pts, now))
|
||||
|
||||
@ -2,14 +2,15 @@
|
||||
// `hash-state` (the Library page only) they live in the URL hash, so a
|
||||
// reload restores them.
|
||||
|
||||
import type { IconId } from '../icons/registry'
|
||||
import { readHash } from './hashState'
|
||||
import { NO_FILTERS, SORTS, type Filters, type SortKey } from './view'
|
||||
|
||||
/** 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', '🎯'],
|
||||
/** Filter key, spoken checkbox label, its token in the hash's `f=` list, painted icon. */
|
||||
export const FILTERS: [keyof Filters, string, string, IconId][] = [
|
||||
['hideCompleted', 'Hide completed', 'completed', 'lib.hide-completed'],
|
||||
['installedOnly', 'Installed only', 'installed', 'dash.installed'],
|
||||
['pickableOnly', 'Pickable only', 'pickable', 'lib.pickable'],
|
||||
]
|
||||
|
||||
export interface BrowserState {
|
||||
|
||||
@ -3,6 +3,8 @@
|
||||
// caret; the browser only writes values into it and hears every edit back.
|
||||
|
||||
import type { LibraryGame } from '../api/contract'
|
||||
import { iconText } from '../icons/iconText'
|
||||
import { iconInline } from '../icons/render'
|
||||
import { h } from '../lib/dom'
|
||||
import { glyph } from '../ui/build'
|
||||
import { FILTERS, type BrowserState } from './browserState'
|
||||
@ -31,7 +33,8 @@ export class BrowserToolbar {
|
||||
opts.onSort(this.sortSelect.value as SortKey)
|
||||
},
|
||||
},
|
||||
SORTS.map((s) => h('option', { value: s.key, 'aria-label': s.label }, s.icon)),
|
||||
// An <option> holds text only: the icon, then the user's word right of it.
|
||||
SORTS.map((s) => h('option', { value: s.key, 'aria-label': s.label }, iconText(s.icon))),
|
||||
)
|
||||
this.checks = new Map(
|
||||
FILTERS.map(([key]) => [
|
||||
@ -48,7 +51,7 @@ export class BrowserToolbar {
|
||||
'div',
|
||||
{ class: 'lib-toolbar' },
|
||||
this.searchBox.el,
|
||||
h('label', { class: 'lib-sort' }, glyph('↕️', 'Sort', 'field-label'), this.sortSelect),
|
||||
h('label', { class: 'lib-sort' }, glyph('lib.sort', 'Sort', 'field-label'), this.sortSelect),
|
||||
h(
|
||||
'fieldset',
|
||||
{ class: 'lib-filters' },
|
||||
@ -79,7 +82,13 @@ export class BrowserToolbar {
|
||||
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',
|
||||
{ 'aria-hidden': 'true' },
|
||||
iconInline('lib.count'),
|
||||
` ${shown}/${total}`,
|
||||
byRelevance ? [' ', iconInline('lib.relevance')] : null,
|
||||
),
|
||||
h('span', { class: 'sr-only' }, spoken),
|
||||
)
|
||||
}
|
||||
|
||||
@ -42,8 +42,8 @@ export function gameCard(game: LibraryGame): HTMLButtonElement {
|
||||
? h(
|
||||
'span',
|
||||
{ class: 'game-badges' },
|
||||
game.assigned ? pill('accent', 'assigned', '🎯') : null,
|
||||
game.installed ? pill('neutral', 'installed', '💾') : null,
|
||||
game.assigned ? pill('accent', 'assigned', 'assigned.game') : null,
|
||||
game.installed ? pill('neutral', 'installed', 'dash.installed') : null,
|
||||
)
|
||||
: null,
|
||||
)
|
||||
|
||||
55
web/src/library/library.icons.test.ts
Normal file
55
web/src/library/library.icons.test.ts
Normal file
@ -0,0 +1,55 @@
|
||||
// Pass-2 icon wiring for the library browser: sort options and placeholders
|
||||
// show the glyph plus the user's word as text, badges and counts draw the
|
||||
// word right of the icon, spoken labels stay.
|
||||
|
||||
import { describe, expect, it, vi } from 'vitest'
|
||||
import { makeLibGame } from '../test/fixtures'
|
||||
import { useIcons } from '../test/iconLedger'
|
||||
import { painted } from '../test/painted'
|
||||
import { BrowserToolbar } from './browserToolbar'
|
||||
import { gameCard } from './gameCard'
|
||||
|
||||
function toolbar(): BrowserToolbar {
|
||||
const bar = new BrowserToolbar({ onInput: vi.fn(), onChoose: vi.fn(), reason: () => null, onSort: vi.fn(), onFilter: vi.fn() })
|
||||
document.body.append(bar.el)
|
||||
return bar
|
||||
}
|
||||
|
||||
describe('library toolbar by id', () => {
|
||||
it('writes the glyph and word into the search placeholder and the sort options', () => {
|
||||
useIcons({ 'lib.search': { word: 'find', glyph: '🔎' }, 'lib.hltb': { word: 'length' } })
|
||||
const bar = toolbar()
|
||||
expect(bar.el.querySelector('input[type=search]')).toHaveAttribute('placeholder', '🔎 Find')
|
||||
const options = [...bar.el.querySelectorAll('option')]
|
||||
expect(options.map((o) => o.textContent)).toEqual(['🔤', '🕐', '🏆', '⏱️ Length'])
|
||||
expect(options[3]).toHaveAttribute('aria-label', 'Shortest (HLTB)')
|
||||
})
|
||||
|
||||
it('draws the sort label, the filters and the count with words, aria unchanged', () => {
|
||||
useIcons({
|
||||
'lib.sort': { word: 'order' },
|
||||
'dash.installed': { word: 'local' },
|
||||
'lib.count': { word: 'games' },
|
||||
'lib.relevance': { glyph: '📊' },
|
||||
})
|
||||
const bar = toolbar()
|
||||
bar.setCount(3, 5, true)
|
||||
expect(painted(bar.el.querySelector('.lib-sort'))).toContain('↕️Order')
|
||||
expect(painted(bar.el.querySelector('.lib-filters label:nth-of-type(2)'))).toBe('💾Local')
|
||||
expect(bar.el.querySelector('.lib-count [aria-hidden]')?.textContent).toBe('🎮Games 3/5 📊')
|
||||
expect(bar.el.querySelector('.lib-count .sr-only')?.textContent).toBe('3 of 5 games · by relevance')
|
||||
expect(bar.el.querySelector('.lib-filters .sr-only')?.textContent).toBe('Filters')
|
||||
})
|
||||
})
|
||||
|
||||
describe('game card badges by id', () => {
|
||||
it('draws the assigned and installed badges with their words, spoken names unchanged', () => {
|
||||
useIcons({ 'assigned.game': { word: 'target' }, 'dash.installed': { glyph: '📥' } })
|
||||
const card = gameCard(makeLibGame({ assigned: true, installed: true }))
|
||||
const [assigned, installed] = [...card.querySelectorAll('.game-badges .pill')]
|
||||
expect(painted(assigned)).toBe('🎯Target')
|
||||
expect(assigned.querySelector('.sr-only')?.textContent).toBe('assigned')
|
||||
expect(painted(installed)).toBe('📥')
|
||||
expect(installed.querySelector('.sr-only')?.textContent).toBe('installed')
|
||||
})
|
||||
})
|
||||
@ -4,6 +4,7 @@
|
||||
// clears. The input is built once; only the list and ARIA state change.
|
||||
|
||||
import type { LibraryGame } from '../api/contract'
|
||||
import { iconText } from '../icons/iconText'
|
||||
import { h } from '../lib/dom'
|
||||
import { uid } from '../lib/ids'
|
||||
import { reasonOrMeta } from './view'
|
||||
@ -36,7 +37,7 @@ export class SearchBox {
|
||||
'aria-expanded': 'false',
|
||||
'aria-controls': this.listId,
|
||||
'aria-autocomplete': 'list',
|
||||
placeholder: '🔍',
|
||||
placeholder: iconText('lib.search'),
|
||||
})
|
||||
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)
|
||||
|
||||
@ -1,5 +1,7 @@
|
||||
import { describe, expect, it } from 'vitest'
|
||||
import { h, type Child } from '../lib/dom'
|
||||
import { makeLibGame } from '../test/fixtures'
|
||||
import { useIcons } from '../test/iconLedger'
|
||||
import { completion, filterGames, isCompleted, metaGlyphs, metaLine, NO_FILTERS, reasonGlyph, reasonOrMeta, sortGames } from './view'
|
||||
|
||||
const g = makeLibGame
|
||||
@ -69,13 +71,23 @@ describe('metaLine', () => {
|
||||
})
|
||||
})
|
||||
|
||||
/** The text the painted nodes show. */
|
||||
const text = (nodes: Child[]) => h('span', {}, ...nodes).textContent
|
||||
|
||||
describe('metaGlyphs', () => {
|
||||
it('paints trophy, clock and play with their values', () => {
|
||||
expect(metaGlyphs(g({ achievements_total: 8, achievements_unlocked: 3, hltb_hours: 12, playtime_minutes: 192 })))
|
||||
expect(text(metaGlyphs(g({ achievements_total: 8, achievements_unlocked: 3, hltb_hours: 12, playtime_minutes: 192 }))))
|
||||
.toBe('🏆 37% · ⏱️ 12 h · ▶️ 3.2 h')
|
||||
})
|
||||
it('paints a dash for no achievements and drops unknown HLTB and zero playtime', () => {
|
||||
expect(metaGlyphs(g({ achievements_total: 0, hltb_hours: null, playtime_minutes: 0 }))).toBe('🏆 —')
|
||||
expect(text(metaGlyphs(g({ achievements_total: 0, hltb_hours: null, playtime_minutes: 0 })))).toBe('🏆 —')
|
||||
})
|
||||
it('draws the user word right of each icon and his alternative glyph', () => {
|
||||
useIcons({ 'lib.hltb': { word: 'length', glyph: '⌛' }, 'lib.completion': { word: 'percent' } })
|
||||
const meta = h('span', {}, ...metaGlyphs(g({ achievements_total: 8, achievements_unlocked: 3, hltb_hours: 12, playtime_minutes: 0 })))
|
||||
expect([...meta.querySelectorAll('.icon-word')].map((w) => w.textContent)).toEqual(['Percent', 'Length'])
|
||||
expect(meta.querySelector('[data-icon="lib.hltb"]')?.textContent).toBe('⌛')
|
||||
expect(meta.querySelector('[data-icon="lib.hltb"]')?.nextElementSibling).toHaveClass('icon-word')
|
||||
})
|
||||
})
|
||||
|
||||
@ -88,7 +100,12 @@ describe('reasonGlyph', () => {
|
||||
['Something else', '⛔'],
|
||||
['Blocked until 2026-10-02', '⛔ 2026-10-02'],
|
||||
])('%s paints %s', (reason, painted) => {
|
||||
expect(reasonGlyph(reason)).toBe(painted)
|
||||
expect(text(reasonGlyph(reason))).toBe(painted)
|
||||
})
|
||||
it('draws the user word beside the reason icon, the date after it', () => {
|
||||
useIcons({ 'lib.why.skipped': { word: 'skipped' } })
|
||||
const el = h('span', {}, ...reasonGlyph('Skipped until 2026-09-01'))
|
||||
expect(el.textContent).toBe('⏭️Skipped 2026-09-01')
|
||||
})
|
||||
})
|
||||
|
||||
@ -97,7 +114,7 @@ describe('reasonOrMeta', () => {
|
||||
const game = g({ achievements_total: 8, achievements_unlocked: 3, hltb_hours: 12, playtime_minutes: 192 })
|
||||
const el = reasonOrMeta(null, game, 'sub')
|
||||
expect(el.className).toBe('sub')
|
||||
expect(el.querySelector('[aria-hidden="true"]')?.textContent).toBe(metaGlyphs(game))
|
||||
expect(el.querySelector('[aria-hidden="true"]')?.textContent).toBe(text(metaGlyphs(game)))
|
||||
expect(el.querySelector('.sr-only')?.textContent).toBe(metaLine(game))
|
||||
})
|
||||
it('paints the reason glyph and speaks the reason when not pickable', () => {
|
||||
|
||||
@ -2,16 +2,18 @@
|
||||
// the grid component only wires state to them.
|
||||
|
||||
import type { LibraryGame } from '../api/contract'
|
||||
import { h } from '../lib/dom'
|
||||
import type { IconId } from '../icons/registry'
|
||||
import { iconInline } from '../icons/render'
|
||||
import { h, type Child } from '../lib/dom'
|
||||
|
||||
export type SortKey = 'name' | 'recent' | 'completion' | '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 const SORTS: { key: SortKey; label: string; icon: IconId }[] = [
|
||||
{ key: 'name', label: 'Name', icon: 'lib.name' },
|
||||
{ key: 'recent', label: 'Recently played', icon: 'lib.recent' },
|
||||
{ key: 'completion', label: 'Completion', icon: 'lib.completion' },
|
||||
{ key: 'hltb', label: 'Shortest (HLTB)', icon: 'lib.hltb' },
|
||||
]
|
||||
|
||||
export interface Filters {
|
||||
@ -69,30 +71,30 @@ 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 {
|
||||
/** The painted meta line: "🏆 45% · ⏱️ 12 h · ▶️ 3.2 h" (🏆 — without achievements), icons by id. */
|
||||
export function metaGlyphs(g: LibraryGame): Child[] {
|
||||
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(' · ')
|
||||
const parts: Child[][] = [[iconInline('lib.completion'), ` ${pct === null ? '—' : `${Math.floor(pct)}%`}`]]
|
||||
if (g.hltb_hours !== null) parts.push([iconInline('lib.hltb'), ` ${hours(g.hltb_hours)}`])
|
||||
if (g.playtime_minutes > 0) parts.push([iconInline('lib.played'), ` ${hours(g.playtime_minutes / 60)}`])
|
||||
return parts.flatMap((part, i) => (i === 0 ? part : [' · ', ...part]))
|
||||
}
|
||||
|
||||
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 {
|
||||
/** Icon for a server ineligibility reason; a date in a skip or block stays painted. */
|
||||
export function reasonGlyph(reason: string): Child[] {
|
||||
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}` : '⛔'
|
||||
if (reason.includes('100%')) return [iconInline('lib.why.complete')]
|
||||
if (/no achievements/i.test(reason)) return [iconInline('lib.why.noach')]
|
||||
const id = /skip/i.test(reason) ? 'lib.why.skipped' : 'lib.why.blocked'
|
||||
return date ? [iconInline(id), ` ${date}`] : [iconInline(id)]
|
||||
}
|
||||
|
||||
/** Glyphs painted, words spoken: `text` shown as `painted` with an sr-only twin. */
|
||||
export function spokenGlyphs(painted: string, text: string, className: string): HTMLSpanElement {
|
||||
export function spokenGlyphs(painted: Child, text: string, className: string): HTMLSpanElement {
|
||||
return h('span', { class: className }, h('span', { 'aria-hidden': 'true' }, painted), h('span', { class: 'sr-only' }, text))
|
||||
}
|
||||
|
||||
|
||||
@ -1,32 +1,34 @@
|
||||
// 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.
|
||||
// Textgate: every label is an icon (registry ids, glyphs.ts) with its words
|
||||
// spoken only; slider values (numbers + units) stay painted.
|
||||
|
||||
import type { IconId } from '../../icons/registry'
|
||||
import { iconInline } from '../../icons/render'
|
||||
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'
|
||||
import { BASIS_ICON, tierText } from './glyphs'
|
||||
|
||||
type Update = (patch: Partial<Filters>) => void
|
||||
interface Seg<T> { id: T; label: string; icon: string }
|
||||
interface Seg<T> { id: T; label: string; icon: IconId }
|
||||
|
||||
const BASES: readonly Seg<EstimateBasis>[] = [
|
||||
{ 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 },
|
||||
{ id: 'rush', label: 'Rush', icon: BASIS_ICON.rush },
|
||||
{ id: 'leisure', label: 'Leisure', icon: BASIS_ICON.leisure },
|
||||
{ id: 'worst', label: 'Worst', icon: BASIS_ICON.worst },
|
||||
{ id: 'pace', label: 'Pace', icon: BASIS_ICON.pace },
|
||||
]
|
||||
const PROTON: readonly Seg<ProtonMode>[] = [
|
||||
{ id: 'playable', label: 'Playable (CLI rule)', icon: '⌨️' },
|
||||
{ id: 'minTier', label: 'Min tier', icon: '🥇≥' },
|
||||
{ id: 'playable', label: 'Playable (CLI rule)', icon: 'backlog.cli' },
|
||||
{ id: 'minTier', label: 'Min tier', icon: 'filter.min-tier' },
|
||||
]
|
||||
const PLAYTIME: readonly Seg<PlaytimeMode>[] = [
|
||||
{ id: 'all', label: 'All', icon: ANY_GLYPH },
|
||||
{ id: 'started', label: 'Started', icon: '▶️' },
|
||||
{ id: 'untouched', label: 'Untouched', icon: '∅' },
|
||||
{ id: 'all', label: 'All', icon: 'backlog.any' },
|
||||
{ id: 'started', label: 'Started', icon: 'filter.started' },
|
||||
{ id: 'untouched', label: 'Untouched', icon: 'filter.untouched' },
|
||||
]
|
||||
|
||||
type NumberKey = 'dailyHours' | 'minCountComp' | 'minComp100' | 'minConfidenceSum' | 'maxHoursPerGame' | 'fallbackHours'
|
||||
@ -35,7 +37,7 @@ interface Slider {
|
||||
key: NumberKey
|
||||
input: HTMLInputElement
|
||||
val: HTMLSpanElement
|
||||
show: (f: Filters) => string
|
||||
show: (f: Filters) => string | HTMLSpanElement
|
||||
}
|
||||
|
||||
const hint = (text: string) => h('p', { class: 'hint sr-only' }, text)
|
||||
@ -45,7 +47,7 @@ export class FilterPanel {
|
||||
private readonly syncs: ((f: Filters) => void)[] = []
|
||||
|
||||
constructor(defaults: WebDefaults, update: Update, onReset: () => void) {
|
||||
const slider = (key: NumberKey, icon: string, label: string, min: number, max: number, step: number, show: Slider['show']) => {
|
||||
const slider = (key: NumberKey, icon: IconId, 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', () => {
|
||||
@ -55,13 +57,13 @@ export class FilterPanel {
|
||||
})
|
||||
this.syncs.push((f) => {
|
||||
input.value = String(f[key])
|
||||
val.textContent = show(f)
|
||||
val.replaceChildren(show(f))
|
||||
})
|
||||
return { label: h('label', {}, glyph(icon, label), ' ', val), input }
|
||||
}
|
||||
const segmented = <T extends string>(items: readonly Seg<T>[], current: (f: Filters) => T, set: (id: T) => void) => {
|
||||
const buttons = items.map((it) =>
|
||||
h('button', { type: 'button', class: 'seg', 'aria-label': it.label, onclick: () => { set(it.id) } }, it.icon),
|
||||
h('button', { type: 'button', class: 'seg', 'aria-label': it.label, onclick: () => { set(it.id) } }, iconInline(it.icon)),
|
||||
)
|
||||
this.syncs.push((f) => {
|
||||
buttons.forEach((b, i) => {
|
||||
@ -72,7 +74,7 @@ export class FilterPanel {
|
||||
})
|
||||
return h('div', { class: 'segmented' }, buttons)
|
||||
}
|
||||
const check = (icon: string, label: string, read: (f: Filters) => boolean, set: (on: boolean) => void) => {
|
||||
const check = (icon: IconId, label: string, read: (f: Filters) => boolean, set: (on: boolean) => void) => {
|
||||
const input = h('input', { type: 'checkbox' })
|
||||
input.addEventListener('change', () => {
|
||||
set(input.checked)
|
||||
@ -88,21 +90,21 @@ export class FilterPanel {
|
||||
})
|
||||
return el
|
||||
}
|
||||
const heading = (icon: string, label: string) => h('label', {}, glyph(icon, label))
|
||||
const heading = (icon: IconId, 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` : '∞',
|
||||
const daily = slider('dailyHours', 'filter.daily', 'Daily play time', 0.5, 16, 0.5, (f) => `${f.dailyHours} h/day`)
|
||||
const minComp = slider('minCountComp', 'planner.completions', 'Min HLTB completions', 0, 100, 1, (f) => String(f.minCountComp))
|
||||
const min100 = slider('minComp100', 'filter.min-polled', 'Min polled completionist times', 0, 50, 1, (f) => String(f.minComp100))
|
||||
const minConf = slider('minConfidenceSum', 'filter.min-confidence', 'Min confidence sum', 0, 150, 1, (f) => String(f.minConfidenceSum))
|
||||
const maxH = slider('maxHoursPerGame', 'filter.max-time', 'Max time per game', 0, 200, 5, (f) =>
|
||||
f.maxHoursPerGame > 0 ? `${f.maxHoursPerGame} h` : iconInline('filter.no-cap'),
|
||||
)
|
||||
const fallback = slider('fallbackHours', '❓', 'Fallback estimate', 1, 100, 1, (f) => `${f.fallbackHours} h`)
|
||||
const fallback = slider('fallbackHours', 'filter.fallback', '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, 'aria-label': t }, TIER_GLYPH[t])),
|
||||
SELECTABLE_TIERS.map((t) => h('option', { value: t, 'aria-label': t }, tierText(t))),
|
||||
)
|
||||
tier.addEventListener('change', () => {
|
||||
update({ protonMinTier: tier.value })
|
||||
@ -119,7 +121,7 @@ export class FilterPanel {
|
||||
date.value = f.targetDate
|
||||
})
|
||||
const clear = shownWhen(
|
||||
h('button', { type: 'button', class: 'ghost', 'aria-label': 'Clear', onclick: () => { update({ targetDate: '' }) } }, '✕'),
|
||||
h('button', { type: 'button', class: 'ghost', 'aria-label': 'Clear', onclick: () => { update({ targetDate: '' }) } }, iconInline('filter.clear-date')),
|
||||
(f) => f.targetDate !== '',
|
||||
)
|
||||
|
||||
@ -129,10 +131,16 @@ export class FilterPanel {
|
||||
h(
|
||||
'div',
|
||||
{ class: 'panel-head' },
|
||||
h('h2', {}, glyph('🎚️', 'Filters')),
|
||||
h('button', { type: 'button', class: 'ghost', 'aria-label': 'Reset to CLI defaults', onclick: () => { onReset() } }, '↺ ⌨️'),
|
||||
h('h2', {}, glyph('backlog.filters', 'Filters')),
|
||||
h(
|
||||
'button',
|
||||
{ type: 'button', class: 'ghost', 'aria-label': 'Reset to CLI defaults', onclick: () => { onReset() } },
|
||||
iconInline('filter.reset'),
|
||||
' ',
|
||||
iconInline('backlog.cli'),
|
||||
),
|
||||
),
|
||||
h('section', { class: 'field' }, heading('📐', 'Estimate basis'), segmented(BASES, (f) => f.basis, (basis) => { update({ basis }) })),
|
||||
h('section', { class: 'field' }, heading('filter.basis', 'Estimate basis'), segmented(BASES, (f) => f.basis, (basis) => { update({ basis }) })),
|
||||
h('section', { class: 'field' }, daily.label, daily.input),
|
||||
h(
|
||||
'section',
|
||||
@ -141,18 +149,18 @@ export class FilterPanel {
|
||||
minComp.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('details', { class: 'field' }, h('summary', {}, glyph('filter.advanced', 'Advanced confidence')), min100.label, min100.input, minConf.label, minConf.input),
|
||||
h(
|
||||
'section',
|
||||
{ class: 'field' },
|
||||
heading('🐧', 'ProtonDB compatibility'),
|
||||
heading('planner.proton', '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('filter.proton-missing', 'Keep games with no ProtonDB data', (f) => f.protonTreatMissingAsPass, (on) => {
|
||||
update({ protonTreatMissingAsPass: on })
|
||||
}),
|
||||
),
|
||||
@ -163,13 +171,13 @@ export class FilterPanel {
|
||||
h(
|
||||
'section',
|
||||
{ class: 'field' },
|
||||
heading('⏱', 'Playtime'),
|
||||
heading('planner.playtime', '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('planner.no-data', '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),
|
||||
@ -177,7 +185,7 @@ export class FilterPanel {
|
||||
h(
|
||||
'section',
|
||||
{ class: 'field' },
|
||||
heading('🏁', 'Target finish date'),
|
||||
heading('filter.target-date', 'Target finish date'),
|
||||
h('div', { class: 'subfield row' }, date, clear),
|
||||
hint('Pick a date to see the hours/day required.'),
|
||||
),
|
||||
|
||||
@ -1,57 +1,69 @@
|
||||
// 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.
|
||||
// Backlog pictograms by registry id (textgate: these are painted, the words
|
||||
// are spoken only). One icon per idea across the stats card, the planner
|
||||
// filters, the summary cards and the table headers, so an icon learned in one
|
||||
// place reads the same everywhere, and the user's word follows it.
|
||||
|
||||
import type { IconId } from '../../icons/registry'
|
||||
import { iconText } from '../../icons/iconText'
|
||||
import { iconInline } from '../../icons/render'
|
||||
import type { EstimateBasis } from '../../types'
|
||||
import { glyph } from '../../ui/build'
|
||||
|
||||
export const BASIS_GLYPH: Record<EstimateBasis, string> = {
|
||||
rush: '🐇',
|
||||
leisure: '🐢',
|
||||
worst: '🐌',
|
||||
pace: '👤',
|
||||
}
|
||||
export const BASIS_ICON = {
|
||||
rush: 'basis.rush',
|
||||
leisure: 'basis.leisure',
|
||||
worst: 'basis.worst',
|
||||
pace: 'basis.pace',
|
||||
} as const satisfies Record<EstimateBasis, IconId>
|
||||
|
||||
/** Player style vs HLTB; the `--<style>` class adds the colour channel. */
|
||||
export const STYLE_GLYPH: Record<string, string> = {
|
||||
faster_than_rush: '⚡',
|
||||
rush_to_leisure: '🐇↔🐢',
|
||||
slower_than_leisure: '🐌',
|
||||
unknown: '❔',
|
||||
const STYLE_ICON: Record<string, IconId> = {
|
||||
faster_than_rush: 'style.fast',
|
||||
rush_to_leisure: 'style.between',
|
||||
slower_than_leisure: 'style.slow',
|
||||
unknown: 'state.unknown',
|
||||
}
|
||||
|
||||
export const STYLE_SPOKEN: Record<string, string> = {
|
||||
const STYLE_SPOKEN: Record<string, string> = {
|
||||
faster_than_rush: 'Faster than HLTB rush',
|
||||
rush_to_leisure: 'Between rush and leisure',
|
||||
slower_than_leisure: 'Slower than HLTB leisure',
|
||||
unknown: 'Not enough finished games yet',
|
||||
}
|
||||
|
||||
/** A player style: its glyph painted (the class adds colour), its sentence spoken. */
|
||||
/** A player style: its icon painted (the class adds colour), its sentence spoken. */
|
||||
export const styleGlyph = (style: string) =>
|
||||
glyph(STYLE_GLYPH[style] ?? '❔', STYLE_SPOKEN[style] ?? style, `player-insight-style player-insight-style--${style}`)
|
||||
glyph(STYLE_ICON[style] ?? 'state.unknown', STYLE_SPOKEN[style] ?? style, `player-insight-style player-insight-style--${style}`)
|
||||
|
||||
/** ProtonDB tiers, best to worst: medals, then a crash and an hourglass. */
|
||||
export const TIER_GLYPH: Record<string, string> = {
|
||||
native: '⭐',
|
||||
platinum: '💎',
|
||||
gold: '🥇',
|
||||
silver: '🥈',
|
||||
bronze: '🥉',
|
||||
borked: '💥',
|
||||
pending: '⏳',
|
||||
const TIER_ICON: Record<string, IconId> = {
|
||||
native: 'tier.native',
|
||||
platinum: 'tier.platinum',
|
||||
gold: 'tier.gold',
|
||||
silver: 'tier.silver',
|
||||
bronze: 'tier.bronze',
|
||||
borked: 'tier.borked',
|
||||
pending: 'tier.pending',
|
||||
}
|
||||
|
||||
const tierGlyph = (tier: string) => TIER_GLYPH[tier] ?? '❔'
|
||||
/** A tierLabel() string (`gold`, `gold / silver`, `—`) as icons; an unknown tier is the unknown mark. */
|
||||
export function tierMarks(label: string): (HTMLSpanElement | string)[] {
|
||||
if (!label || label === '—') return ['—']
|
||||
return label
|
||||
.split(' / ')
|
||||
.flatMap((tier, i) => [...(i ? ['/'] : []), iconInline(TIER_ICON[tier] ?? 'state.unknown')])
|
||||
}
|
||||
|
||||
/** A tierLabel() string (`gold`, `gold / silver`, `—`) as glyphs. */
|
||||
export function tierGlyphs(label: string): string {
|
||||
/** `tierMarks` as plain text (glyph, then word) for an `<option>`, which cannot hold markup. */
|
||||
export function tierText(label: string): string {
|
||||
if (!label || label === '—') return '—'
|
||||
return label.split(' / ').map(tierGlyph).join('/')
|
||||
return label
|
||||
.split(' / ')
|
||||
.map((tier) => iconText(TIER_ICON[tier] ?? 'state.unknown'))
|
||||
.join('/')
|
||||
}
|
||||
|
||||
export const KEEP_GLYPH: Record<string, string> = { kept: '📌', excluded: '🚫' }
|
||||
const KEEP_ICON: Record<string, IconId> = { kept: 'keep.kept', excluded: 'keep.excluded' }
|
||||
|
||||
/** "Any value" in a filter select or segmented control. */
|
||||
export const ANY_GLYPH = '✱'
|
||||
/** The keep filter's value as plain option text. */
|
||||
export const keepText = (value: string) => iconText(KEEP_ICON[value])
|
||||
|
||||
104
web/src/sections/backlog/icons.test.ts
Normal file
104
web/src/sections/backlog/icons.test.ts
Normal file
@ -0,0 +1,104 @@
|
||||
// The backlog page's icons are registry ids: the user's word shows right of
|
||||
// the icon, a chosen alternative glyph replaces it, spoken names stay.
|
||||
|
||||
import { screen } from '@testing-library/dom'
|
||||
import { afterEach, describe, expect, it } from 'vitest'
|
||||
import { applyFilters } from '../../estimate'
|
||||
import { timelineChart } from '../../lib/charts/timeline'
|
||||
import { makeDataset, makeFilters, makeGame, makePaceVsHltb, makeState } from '../../test/factories'
|
||||
import { useIcons } from '../../test/iconLedger'
|
||||
import { GAMES, header, panel, show, table } from '../../test/plannerHelpers'
|
||||
import { painted } from '../../test/painted'
|
||||
import { keepText, styleGlyph, tierMarks, tierText } from './glyphs'
|
||||
import { summaryCards } from './summary'
|
||||
|
||||
afterEach(() => {
|
||||
history.replaceState(null, '', '/')
|
||||
})
|
||||
|
||||
const wordAfter = (mark: Element | null) => mark?.nextElementSibling?.textContent
|
||||
|
||||
describe('backlog icons: filter panel', () => {
|
||||
it('draws the basis word right of the icon and keeps the button name', async () => {
|
||||
useIcons({ 'basis.rush': { word: 'sprint', glyph: '🚀' } })
|
||||
await show()
|
||||
const rush = panel().getByRole('button', { name: 'Rush' })
|
||||
expect(rush.querySelector('[data-icon]')?.textContent).toBe('🚀')
|
||||
expect(wordAfter(rush.querySelector('[data-icon]'))).toBe('Sprint')
|
||||
expect(rush.querySelector('.icon-inline')).toHaveClass('has-word')
|
||||
})
|
||||
|
||||
it('reset button, no-cap value and clear-date mark follow the ledger', async () => {
|
||||
useIcons({ 'filter.reset': { glyph: '🧹' }, 'filter.no-cap': { word: 'endless' }, 'backlog.cli': { word: 'default' } })
|
||||
await show()
|
||||
const reset = panel().getByRole('button', { name: 'Reset to CLI defaults' })
|
||||
expect(painted(reset)).toBe('🧹 ⌨️Default')
|
||||
expect(document.querySelector('.panel .val .icon-word')?.textContent).toBe('Endless')
|
||||
})
|
||||
|
||||
it('tier options and the keep check carry the tier icons and their words', async () => {
|
||||
useIcons({ 'tier.gold': { word: 'great' }, 'filter.proton-missing': { word: 'unrated' } })
|
||||
await show()
|
||||
const gold = [...document.querySelectorAll('.panel select option')].find((o) => o.getAttribute('aria-label') === 'gold')
|
||||
expect(gold?.textContent).toBe('🥇 Great')
|
||||
expect(wordAfter(document.querySelector('.panel .check [data-icon="filter.proton-missing"]'))).toBe('Unrated')
|
||||
})
|
||||
})
|
||||
|
||||
describe('backlog icons: table', () => {
|
||||
it('sort arrow and column icons use their ids', async () => {
|
||||
useIcons({ 'backlog.sort-asc': { glyph: '🔼', word: 'up' }, 'basis.leisure': { word: 'slow' } })
|
||||
await show()
|
||||
const th = header('Leisure')
|
||||
expect(th).toHaveAttribute('aria-label', 'Leisure')
|
||||
expect(th.querySelector('[data-icon="backlog.sort-asc"]')?.textContent).toBe('🔼')
|
||||
expect([...th.querySelectorAll('.icon-word')].map((w) => w.textContent)).toEqual(['Slow', 'Up'])
|
||||
})
|
||||
|
||||
it('tier cells, options and the no-data badge follow the ledger', async () => {
|
||||
useIcons({ 'tier.platinum': { glyph: '💠' }, 'keep.kept': { word: 'pinned' }, 'planner.no-data': { word: 'blank' } })
|
||||
history.replaceState(null, '', '/backlog/#nodata=1')
|
||||
await show([...GAMES, makeGame({ app_id: 9, name: 'No Data', rush_hours: -1, leisure_hours: -1, worst_hours: -1 })])
|
||||
expect(table().querySelector('td.proton [data-icon="tier.platinum"]')?.textContent).toBe('💠')
|
||||
const keep = screen.getByRole('combobox', { name: 'Filter Keep' })
|
||||
expect([...keep.querySelectorAll('option')].map((o) => o.textContent)).toContain('📌 Pinned')
|
||||
expect(wordAfter(table().querySelector('.badge [data-icon="planner.no-data"]'))).toBe('Blank')
|
||||
})
|
||||
|
||||
it('number filter boxes keep their comparator placeholders', async () => {
|
||||
await show()
|
||||
expect(table().querySelector('input[aria-label$=" min"]')).toHaveAttribute('placeholder', '≥')
|
||||
expect(table().querySelector('input[aria-label$=" max"]')).toHaveAttribute('placeholder', '≤')
|
||||
})
|
||||
})
|
||||
|
||||
describe('backlog icons: summary, glyph helpers and chart', () => {
|
||||
it('the banner and parity row paint ledger words and alternatives, spoken text unchanged', () => {
|
||||
useIcons({ 'filter.target-date': { word: 'deadline' }, 'summary.need': { glyph: '➡️' }, 'summary.match': { word: 'same' } })
|
||||
const filters = makeFilters({ targetDate: '2026-01-11' })
|
||||
const result = applyFilters(makeDataset([makeGame({ app_id: 1 })]), filters)
|
||||
const el = summaryCards(
|
||||
{ result, filters, state: makeState(), presets: [2], defaultQualifying: result.remainingGames, paceVsHltb: makePaceVsHltb() },
|
||||
new Date('2026-01-01T00:00:00Z'),
|
||||
)
|
||||
document.body.append(el)
|
||||
expect(painted(el.querySelector('.target-banner'))).toContain('🏁Deadline')
|
||||
expect(painted(el.querySelector('.target-banner'))).toContain('➡️')
|
||||
expect(wordAfter(el.querySelector('.parity [data-icon="summary.match"]'))).toBe('Same')
|
||||
expect(el.querySelector('.target-banner')).toHaveTextContent('by')
|
||||
})
|
||||
|
||||
it('style, tier and keep helpers draw ids, and the empty chart draws the empty id', () => {
|
||||
useIcons({ 'style.fast': { word: 'speedy' }, 'state.empty': { glyph: '📪' }, 'tier.bronze': { word: 'rough' } })
|
||||
const style = styleGlyph('faster_than_rush')
|
||||
expect(style.querySelector('.icon-word')?.textContent).toBe('Speedy')
|
||||
expect(style).toHaveTextContent('Faster than HLTB rush')
|
||||
expect(tierMarks('bronze').map((m) => (typeof m === 'string' ? m : m.textContent)).join('')).toBe('🥉Rough')
|
||||
expect(keepText('kept')).toBe('📌')
|
||||
expect(tierText('bronze / gold')).toBe('🥉 Rough/🥇')
|
||||
const filters = makeFilters()
|
||||
const box = timelineChart(applyFilters(makeDataset([]), filters), filters, makeState())
|
||||
expect(box.querySelector('.empty-icon')?.textContent).toBe('📪')
|
||||
expect(box).toHaveTextContent('Not enough games in scope to draw a timeline.')
|
||||
})
|
||||
})
|
||||
@ -112,12 +112,12 @@ export class Planner {
|
||||
private syncSub(): void {
|
||||
const s = this.data.state
|
||||
this.sub.replaceChildren(
|
||||
...(s.current_game_name ? [glyph('▶️', 'Currently playing '), ' ', h('strong', {}, s.current_game_name), ' · '] : []),
|
||||
glyph('🏆', 'games finished'),
|
||||
...(s.current_game_name ? [glyph('planner.playing', 'Currently playing '), ' ', h('strong', {}, s.current_game_name), ' · '] : []),
|
||||
glyph('dash.finished', 'games finished'),
|
||||
` ${s.games_done_since_start} · `,
|
||||
glyph('📅', 'since'),
|
||||
glyph('planner.since', 'since'),
|
||||
` ${s.enforcement_started_at.slice(0, 10) || '—'} · `,
|
||||
glyph('🎮', 'candidates'),
|
||||
glyph('planner.candidates', 'candidates'),
|
||||
` ${this.data.games.length}`,
|
||||
)
|
||||
}
|
||||
|
||||
@ -2,7 +2,6 @@ import { screen, within } from '@testing-library/dom'
|
||||
import { afterEach, describe, expect, it } from 'vitest'
|
||||
import { makeGame } from '../../test/factories'
|
||||
import { GAMES, hash, header, names, show, table } from '../../test/plannerHelpers'
|
||||
import { ANY_GLYPH } from './glyphs'
|
||||
import { hltbUrl } from './plannerTable'
|
||||
|
||||
afterEach(() => {
|
||||
@ -120,7 +119,7 @@ describe('<game-table> table', () => {
|
||||
await show()
|
||||
const options = [...screen.getByRole('combobox', { name: 'Filter Keep' }).querySelectorAll('option')]
|
||||
expect(options.map((o) => [o.value, o.textContent, o.getAttribute('aria-label')])).toEqual([
|
||||
['', ANY_GLYPH, 'All'],
|
||||
['', '✱', 'All'],
|
||||
['kept', '📌', 'kept'],
|
||||
['excluded', '🚫', 'excluded'],
|
||||
])
|
||||
|
||||
@ -5,11 +5,14 @@
|
||||
|
||||
import type { GameRow } from '../../estimate'
|
||||
import { fmtHoursPrecise, fmtPlaytime } from '../../format'
|
||||
import type { IconId } from '../../icons/registry'
|
||||
import { iconText } from '../../icons/iconText'
|
||||
import { iconInline } from '../../icons/render'
|
||||
import { h } from '../../lib/dom'
|
||||
import { tierLabel } from '../../protondb'
|
||||
import type { WebGame } from '../../types'
|
||||
import { glyph } from '../../ui/build'
|
||||
import { ANY_GLYPH, KEEP_GLYPH, tierGlyphs } from './glyphs'
|
||||
import { BASIS_ICON, keepText, tierMarks, tierText } from './glyphs'
|
||||
import { COLUMNS, optionsFor, type Column, type ColumnKey, type TableState } from './tableState'
|
||||
|
||||
export const DISPLAY_CAP = 300
|
||||
@ -36,27 +39,28 @@ export function hltbUrl(game: WebGame): string {
|
||||
return `https://howlongtobeat.com/?q=${encodeURIComponent(game.name)}`
|
||||
}
|
||||
|
||||
// Textgate: select options paint glyphs; the value (kept/excluded, a
|
||||
// Textgate: select options paint icons; the value (kept/excluded, a
|
||||
// tierLabel string) is what the hash stores and what the option speaks.
|
||||
// Only the keep and proton columns have a select filter; keep's options are
|
||||
// always kept/excluded, so every one has a glyph.
|
||||
const optionLabel = (c: Column, v: string) => (c.key === 'keep' ? KEEP_GLYPH[v] : tierGlyphs(v))
|
||||
// always kept/excluded, so every one has an icon.
|
||||
// An <option> holds text only, so these are glyph-then-word strings.
|
||||
const optionLabel = (c: Column, v: string) => (c.key === 'keep' ? keepText(v) : tierText(v))
|
||||
const option = (c: Column, v: string) =>
|
||||
h('option', { value: v, 'aria-label': v || 'All' }, v ? optionLabel(c, v) : ANY_GLYPH)
|
||||
h('option', { value: v, 'aria-label': v || 'All' }, v ? optionLabel(c, v) : iconText('backlog.any'))
|
||||
|
||||
// Textgate: column headers are pictograms; the column name is the button's
|
||||
// aria-label (spoken only), the sort arrow stays visible.
|
||||
const COLUMN_ICON: Record<ColumnKey, string> = {
|
||||
name: '🎮',
|
||||
completion: '%',
|
||||
playtime: '⏱',
|
||||
rush: '🐇',
|
||||
leisure: '🐢',
|
||||
worst: '🐌',
|
||||
count_comp: '#',
|
||||
proton: '🐧',
|
||||
keep: '📌',
|
||||
}
|
||||
const COLUMN_ICON = {
|
||||
name: 'planner.game',
|
||||
completion: 'planner.completion',
|
||||
playtime: 'planner.playtime',
|
||||
rush: BASIS_ICON.rush,
|
||||
leisure: BASIS_ICON.leisure,
|
||||
worst: BASIS_ICON.worst,
|
||||
count_comp: 'planner.completions',
|
||||
proton: 'planner.proton',
|
||||
keep: 'planner.keep',
|
||||
} as const satisfies Record<ColumnKey, IconId>
|
||||
|
||||
export class PlannerTable {
|
||||
readonly el: HTMLElement
|
||||
@ -109,8 +113,12 @@ export class PlannerTable {
|
||||
return el
|
||||
}
|
||||
if (c.filter === 'range') {
|
||||
// The comparator in the box is a math operator, not an icon: a placeholder is text only.
|
||||
const bound = (side: 'min' | 'max') =>
|
||||
field(`${c.key}.${side}`, h('input', { type: 'number', inputmode: 'decimal', placeholder: side === 'min' ? '≥' : '≤', 'aria-label': `${c.label} ${side}` }))
|
||||
field(
|
||||
`${c.key}.${side}`,
|
||||
h('input', { type: 'number', inputmode: 'decimal', placeholder: side === 'min' ? '≥' : '≤', 'aria-label': `${c.label} ${side}` }),
|
||||
)
|
||||
return h('td', { class: 'range-filter' }, h('div', {}, bound('min'), bound('max')))
|
||||
}
|
||||
if (c.filter === 'select') {
|
||||
@ -121,7 +129,7 @@ export class PlannerTable {
|
||||
return h('td', {}, field(c.key, h('input', { type: 'search', placeholder: '', 'aria-label': `Filter ${c.label}` })))
|
||||
}
|
||||
const headCell = (c: Column): HTMLTableCellElement => {
|
||||
const button = h('button', { type: 'button', class: 'sort-btn', 'aria-label': c.label }, COLUMN_ICON[c.key])
|
||||
const button = h('button', { type: 'button', class: 'sort-btn', 'aria-label': c.label }, iconInline(COLUMN_ICON[c.key]))
|
||||
const th = h('th', { class: c.numeric ? 'num clickable' : 'clickable', scope: 'col', 'aria-label': c.label }, button)
|
||||
th.addEventListener('click', () => {
|
||||
this.opts.onSort(c.key)
|
||||
@ -161,7 +169,7 @@ export class PlannerTable {
|
||||
keep.addEventListener('change', () => { this.opts.onToggle(id) })
|
||||
const link = h('a', { target: '_blank', rel: 'noreferrer' })
|
||||
const name = h('td', { class: 'name' }, link)
|
||||
row = { tr: h('tr', {}, name, cells, h('td', { class: 'num' }, keep)), name, link, badge: glyph('❓', 'no data', 'badge'), cells, keep }
|
||||
row = { tr: h('tr', {}, name, cells, h('td', { class: 'num' }, keep)), name, link, badge: glyph('planner.no-data', 'no data', 'badge'), cells, keep }
|
||||
this.rows.set(id, row)
|
||||
}
|
||||
const g = r.game
|
||||
@ -179,9 +187,9 @@ export class PlannerTable {
|
||||
fmtHoursPrecise(r.leisure),
|
||||
fmtHoursPrecise(r.worst),
|
||||
String(g.count_comp),
|
||||
tierGlyphs(tier),
|
||||
]
|
||||
texts.forEach((text, i) => { row.cells[i].textContent = text })
|
||||
row.cells[6].replaceChildren(...tierMarks(tier))
|
||||
row.cells[6].setAttribute('aria-label', tier)
|
||||
row.keep.checked = !r.excluded
|
||||
row.keep.setAttribute('aria-label', r.excluded ? 'Re-include' : 'Exclude')
|
||||
@ -203,8 +211,8 @@ export class PlannerTable {
|
||||
private syncHeads(table: TableState): void {
|
||||
for (const [c, th, button] of this.heads) {
|
||||
const active = c.key === table.sort
|
||||
const arrow = active ? (table.asc ? ' ▲' : ' ▼') : ''
|
||||
button.textContent = `${COLUMN_ICON[c.key]}${arrow}`
|
||||
const arrow = active ? [' ', iconInline(table.asc ? 'backlog.sort-asc' : 'backlog.sort-desc')] : []
|
||||
button.replaceChildren(iconInline(COLUMN_ICON[c.key]), ...arrow)
|
||||
if (active) th.setAttribute('aria-sort', table.asc ? 'ascending' : 'descending')
|
||||
else th.removeAttribute('aria-sort')
|
||||
}
|
||||
|
||||
@ -1,16 +1,17 @@
|
||||
// <backlog-stats>: the CLI's `stats` estimate for the default filters (was
|
||||
// screens/Backlog.tsx StatsCard). Textgate: labels are glyphs, words spoken only.
|
||||
// screens/Backlog.tsx StatsCard). Textgate: labels are icons, words spoken only.
|
||||
|
||||
import { q } from '../../api/queries'
|
||||
import { fmtHours } from '../../format'
|
||||
import type { IconId } from '../../icons/registry'
|
||||
import { h } from '../../lib/dom'
|
||||
import { LiveElement } from '../../lib/element'
|
||||
import { card, errorNotice, facts, glyph, loading } from '../../ui/build'
|
||||
import { BASIS_GLYPH, styleGlyph } from './glyphs'
|
||||
import { BASIS_ICON, styleGlyph } from './glyphs'
|
||||
|
||||
const ICON = '📊'
|
||||
const ICON: IconId = 'stats.card'
|
||||
const ratio = (r: number) => (r < 0 ? '—' : `${r.toFixed(2)}×`)
|
||||
const stat = (num: string | number, icon: string, label: string) =>
|
||||
const stat = (num: string | number, icon: IconId, label: string) =>
|
||||
h('div', { class: 'stat' }, h('span', { class: 'stat-num' }, num), glyph(icon, label, 'stat-label'))
|
||||
|
||||
export class BacklogStatsElement extends LiveElement {
|
||||
@ -37,17 +38,17 @@ export class BacklogStatsElement extends LiveElement {
|
||||
h(
|
||||
'div',
|
||||
{ class: 'stat-row' },
|
||||
stat(s.qualifying, '🎮', 'qualifying games'),
|
||||
stat(fmtHours(s.rush_total), BASIS_GLYPH.rush, 'rush'),
|
||||
stat(fmtHours(s.leisure_total), BASIS_GLYPH.leisure, 'leisure'),
|
||||
stat(fmtHours(s.worst_total), BASIS_GLYPH.worst, 'worst case'),
|
||||
stat(s.qualifying, 'backlog.in-scope', 'qualifying games'),
|
||||
stat(fmtHours(s.rush_total), BASIS_ICON.rush, 'rush'),
|
||||
stat(fmtHours(s.leisure_total), BASIS_ICON.leisure, 'leisure'),
|
||||
stat(fmtHours(s.worst_total), BASIS_ICON.worst, 'worst case'),
|
||||
),
|
||||
p
|
||||
? facts([
|
||||
[glyph(BASIS_GLYPH.pace, 'Your pace'), styleGlyph(p.player_style)],
|
||||
[glyph(BASIS_GLYPH.rush, 'vs rush'), ratio(p.ratio_vs_rush)],
|
||||
[glyph(BASIS_GLYPH.leisure, 'vs leisure'), ratio(p.ratio_vs_leisure)],
|
||||
[glyph('🏆', 'Calibrated on'), [String(p.calibration_count), h('span', { class: 'sr-only' }, ' finished games')]],
|
||||
[glyph(BASIS_ICON.pace, 'Your pace'), styleGlyph(p.player_style)],
|
||||
[glyph(BASIS_ICON.rush, 'vs rush'), ratio(p.ratio_vs_rush)],
|
||||
[glyph(BASIS_ICON.leisure, 'vs leisure'), ratio(p.ratio_vs_leisure)],
|
||||
[glyph('dash.finished','Calibrated on'), [String(p.calibration_count), h('span', { class: 'sr-only' }, ' finished games')]],
|
||||
])
|
||||
: null,
|
||||
],
|
||||
|
||||
@ -1,13 +1,15 @@
|
||||
// The planner's headline: games in scope, the target-date banner, one card per
|
||||
// estimate basis and the player's pace vs HLTB (was SummaryCards.tsx).
|
||||
// Textgate: labels are glyphs (glyphs.ts), the old wording is spoken only.
|
||||
// Textgate: labels are icons (glyphs.ts), the old wording is spoken only.
|
||||
|
||||
import { basisTotal, etaDays, paceDays, playerEstimatedTotal, type EstimateResult } from '../../estimate'
|
||||
import { fmtEta, fmtHours } from '../../format'
|
||||
import type { IconId } from '../../icons/registry'
|
||||
import { iconInline } from '../../icons/render'
|
||||
import { h } from '../../lib/dom'
|
||||
import type { EstimateBasis, Filters, PaceVsHLTB, WebStateInfo } from '../../types'
|
||||
import { empty, glyph } from '../../ui/build'
|
||||
import { BASIS_GLYPH, styleGlyph } from './glyphs'
|
||||
import { BASIS_ICON, styleGlyph } from './glyphs'
|
||||
|
||||
export interface SummaryProps {
|
||||
result: EstimateResult
|
||||
@ -26,8 +28,8 @@ const CARDS: readonly { basis: EstimateBasis; title: string; blurb: string }[] =
|
||||
]
|
||||
|
||||
const spoken = (text: string) => h('span', { class: 'sr-only' }, text)
|
||||
/** Games per day: the 🎮 stands in for the word "games". */
|
||||
const perDay = (n: number | string) => [`${n} 🎮/d`, spoken(' games per day')]
|
||||
/** Games per day: the games icon stands in for the word "games". */
|
||||
const perDay = (n: number | string) => [`${n} `, iconInline('summary.games-per-day'), '/d', spoken(' games per day')]
|
||||
|
||||
function targetBanner({ result, filters }: SummaryProps, now: Date): HTMLDivElement | null {
|
||||
if (!filters.targetDate) return null
|
||||
@ -39,16 +41,20 @@ function targetBanner({ result, filters }: SummaryProps, now: Date): HTMLDivElem
|
||||
return h(
|
||||
'div',
|
||||
{ class: 'target-banner' },
|
||||
glyph('🎮', 'To finish'),
|
||||
glyph('summary.to-finish', 'To finish'),
|
||||
' ',
|
||||
h('strong', {}, result.remainingGames),
|
||||
spoken(' games'),
|
||||
' 🏁 ',
|
||||
' ',
|
||||
iconInline('filter.target-date'),
|
||||
' ',
|
||||
spoken('by '),
|
||||
h('strong', {}, filters.targetDate),
|
||||
` (${days} d) `,
|
||||
glyph(BASIS_GLYPH[filters.basis], `on the ${filters.basis} model, you need`),
|
||||
' → ',
|
||||
glyph(BASIS_ICON[filters.basis], `on the ${filters.basis} model, you need`),
|
||||
' ',
|
||||
iconInline('summary.need'),
|
||||
' ',
|
||||
h('strong', {}, need),
|
||||
)
|
||||
}
|
||||
@ -60,13 +66,13 @@ const presetRows = (presets: readonly number[], eta: (perDay: number) => number
|
||||
presets.map((p) => h('div', { class: 'preset' }, h('span', {}, `${p} h/day`), h('span', {}, fmtEta(eta(p))))),
|
||||
)
|
||||
|
||||
const pair = (icon: string, label: string, value: Node | string, attrs: Record<string, string> = {}) => [
|
||||
const pair = (icon: IconId, label: string, value: Node | string, attrs: Record<string, string> = {}) => [
|
||||
glyph(icon, label),
|
||||
typeof value === 'string' ? h('span', attrs, value) : value,
|
||||
]
|
||||
|
||||
function playerInsight({ result, paceVsHltb: pace, presets }: SummaryProps): HTMLDivElement {
|
||||
const title = h('div', { class: 'player-insight-title' }, glyph(BASIS_GLYPH.pace, 'Your Play Style vs HLTB'))
|
||||
const title = h('div', { class: 'player-insight-title' }, glyph(BASIS_ICON.pace, 'Your Play Style vs HLTB'))
|
||||
if (!pace || pace.calibration_count === 0) {
|
||||
return h(
|
||||
'div',
|
||||
@ -83,18 +89,18 @@ function playerInsight({ result, paceVsHltb: pace, presets }: SummaryProps): HTM
|
||||
h(
|
||||
'div',
|
||||
{ class: 'player-insight-grid' },
|
||||
pair('🏆', 'Calibration games', String(pace.calibration_count)),
|
||||
pair('dash.finished','Calibration games', String(pace.calibration_count)),
|
||||
pace.ratio_vs_rush !== -1
|
||||
? pair(BASIS_GLYPH.rush, 'vs Rush speed', `${pace.ratio_vs_rush.toFixed(2)}×`, {
|
||||
? pair(BASIS_ICON.rush, 'vs Rush speed', `${pace.ratio_vs_rush.toFixed(2)}×`, {
|
||||
class: pace.ratio_vs_rush <= 1 ? 'player-insight-fast' : 'player-insight-slow',
|
||||
})
|
||||
: null,
|
||||
pace.ratio_vs_leisure !== -1 ? pair(BASIS_GLYPH.leisure, 'vs Leisure speed', `${pace.ratio_vs_leisure.toFixed(2)}×`) : null,
|
||||
pace.ratio_vs_leisure !== -1 ? pair(BASIS_ICON.leisure, 'vs Leisure speed', `${pace.ratio_vs_leisure.toFixed(2)}×`) : null,
|
||||
// `t` is the formula's own symbol: 0 = rush speed, 1 = leisure speed.
|
||||
pace.interpolation_t !== -1
|
||||
? pair('t', 'Interpolation t, 0 = rush speed, 1 = leisure speed', pace.interpolation_t.toFixed(3))
|
||||
? pair('summary.interpolation', 'Interpolation t, 0 = rush speed, 1 = leisure speed', pace.interpolation_t.toFixed(3))
|
||||
: null,
|
||||
pair('🎭', 'Play style', styleGlyph(pace.player_style)),
|
||||
pair('summary.style', 'Play style', styleGlyph(pace.player_style)),
|
||||
),
|
||||
estimated !== null
|
||||
? h(
|
||||
@ -103,7 +109,7 @@ function playerInsight({ result, paceVsHltb: pace, presets }: SummaryProps): HTM
|
||||
h(
|
||||
'div',
|
||||
{ class: 'player-insight-estimate-total' },
|
||||
glyph('Σ', 'Estimated total at your pace: '),
|
||||
glyph('summary.estimated-total', 'Estimated total at your pace: '),
|
||||
' ',
|
||||
h('strong', { class: 'player-insight-estimate-hours' }, fmtHours(estimated)),
|
||||
),
|
||||
@ -122,10 +128,10 @@ function basisCard(props: SummaryProps, c: (typeof CARDS)[number]): HTMLDivEleme
|
||||
return h(
|
||||
'div',
|
||||
{ class: filters.basis === c.basis ? 'card active' : 'card', 'data-basis': c.basis },
|
||||
h('div', { class: 'card-title' }, glyph(BASIS_GLYPH[c.basis], c.title)),
|
||||
h('div', { class: 'card-title' }, glyph(BASIS_ICON[c.basis], c.title)),
|
||||
spoken(c.blurb),
|
||||
h('div', { class: 'card-total' }, isPace ? perDay(pace) : fmtHours(total)),
|
||||
h('div', { class: 'card-eta' }, isPace && !pace ? glyph('∅', 'No start date set') : fmtEta(eta)),
|
||||
h('div', { class: 'card-eta' }, isPace && !pace ? glyph('summary.no-start', 'No start date set') : fmtEta(eta)),
|
||||
isPace ? null : presetRows(presets, (p) => etaDays(total, p)),
|
||||
)
|
||||
}
|
||||
@ -143,15 +149,15 @@ export function summaryCards(props: SummaryProps, now: Date = new Date()): HTMLD
|
||||
'div',
|
||||
{},
|
||||
h('span', { class: 'big' }, result.remainingGames.toLocaleString()),
|
||||
glyph('🎮', 'games in scope', 'big-label'),
|
||||
glyph('backlog.in-scope', 'games in scope', 'big-label'),
|
||||
),
|
||||
h(
|
||||
'div',
|
||||
{ class: 'parity', 'data-match': String(match) },
|
||||
glyph('⌨️', 'CLI default qualifies '),
|
||||
glyph('backlog.cli', 'CLI default qualifies '),
|
||||
' ',
|
||||
h('strong', {}, defaultQualifying),
|
||||
match ? h('span', { class: 'ok' }, ' ✓', spoken(' match')) : null,
|
||||
match ? h('span', { class: 'ok' }, ' ', iconInline('summary.match'), spoken(' match')) : null,
|
||||
),
|
||||
),
|
||||
targetBanner(props, now),
|
||||
|
||||
@ -7,7 +7,7 @@ import { makeGame, makePaceVsHltb, makeState } from '../../test/factories'
|
||||
import { flush, mount, stubApi } from '../../test/harness'
|
||||
import { GAMES, panel, show } from '../../test/plannerHelpers'
|
||||
import { visibleWords } from '../../test/visibleWords'
|
||||
import { ANY_GLYPH, KEEP_GLYPH, styleGlyph, tierGlyphs } from './glyphs'
|
||||
import { keepText, styleGlyph, tierMarks, tierText } from './glyphs'
|
||||
import { painted } from '../../test/painted'
|
||||
|
||||
afterEach(() => {
|
||||
@ -50,11 +50,15 @@ describe('textgate guard: backlog', () => {
|
||||
|
||||
describe('backlog glyphs', () => {
|
||||
it('paints ProtonDB tiers as medals, unknown tiers as ❔', () => {
|
||||
expect(tierGlyphs('gold / silver')).toBe('🥇/🥈')
|
||||
expect(tierGlyphs('—')).toBe('—')
|
||||
expect(tierGlyphs('')).toBe('—')
|
||||
expect(tierGlyphs('weird')).toBe('❔')
|
||||
expect(KEEP_GLYPH.excluded).toBe('🚫')
|
||||
const text = (label: string) => tierMarks(label).map((m) => (typeof m === 'string' ? m : m.textContent)).join('')
|
||||
expect(text('gold / silver')).toBe('🥇/🥈')
|
||||
expect(text('—')).toBe('—')
|
||||
expect(text('')).toBe('—')
|
||||
expect(text('weird')).toBe('❔')
|
||||
expect(keepText('excluded')).toBe('🚫')
|
||||
expect(tierText('gold / silver')).toBe('🥇/🥈')
|
||||
expect(tierText('—')).toBe('—')
|
||||
expect(tierText('weird')).toBe('❔')
|
||||
})
|
||||
|
||||
it('speaks an unknown play style by its key', () => {
|
||||
@ -67,7 +71,7 @@ describe('backlog glyphs', () => {
|
||||
it('offers glyph options in the table filters, values unchanged', async () => {
|
||||
await show()
|
||||
const keep = screen.getByRole('combobox', { name: 'Filter Keep' })
|
||||
expect([...keep.querySelectorAll('option')].map((o) => [o.value, o.textContent])).toContainEqual(['', ANY_GLYPH])
|
||||
expect([...keep.querySelectorAll('option')].map((o) => [o.value, o.textContent])).toContainEqual(['', '✱'])
|
||||
expect([...keep.querySelectorAll('option')].map((o) => [o.value, o.textContent])).toContainEqual(['kept', '📌'])
|
||||
const tier = screen.getByRole('combobox', { name: 'Filter ProtonDB' })
|
||||
expect([...tier.querySelectorAll('option')].map((o) => o.textContent)).toContain('🥇/💎')
|
||||
|
||||
@ -60,7 +60,8 @@ describe('Dashboard', () => {
|
||||
describe('assignment', () => {
|
||||
it('summarises a healthy state', async () => {
|
||||
show()
|
||||
expect(await screen.findByText('Hollow Knight')).toHaveClass('hero-game')
|
||||
// The billing line also names the game, behind its icon: pick the hero by class.
|
||||
expect(await screen.findByText('Hollow Knight', { selector: '.hero-game' })).toHaveClass('hero-game')
|
||||
expect(fact('Installed')).toHaveTextContent('Yes')
|
||||
expect(fact('Games finished')).toHaveTextContent('3')
|
||||
expect(fact('Store')).toHaveTextContent('Blocked')
|
||||
@ -161,7 +162,7 @@ describe('Dashboard', () => {
|
||||
|
||||
it('stays out of the way when nothing is installing', async () => {
|
||||
show({ 'GET /api/daemon': { ...daemon(), fast_installs: undefined } })
|
||||
expect(await screen.findByText('Hollow Knight')).toBeInTheDocument()
|
||||
expect(await screen.findByText('Hollow Knight', { selector: '.hero-game' })).toBeInTheDocument()
|
||||
expect(screen.queryByText(/Fast-installing/)).not.toBeInTheDocument()
|
||||
expect(screen.queryByRole('region', { name: 'Fast install' })).not.toBeInTheDocument()
|
||||
})
|
||||
|
||||
@ -8,6 +8,7 @@ import { commandIcon, commandLabel } from '../commands/catalog'
|
||||
import '../commands/commandButton'
|
||||
import { fmtDuration, fmtRemaining } from '../format'
|
||||
import { progressBar, stateBadge, type BarTone } from '../jobs/progress'
|
||||
import { iconInline } from '../icons/render'
|
||||
import { define, h, hx } from '../lib/dom'
|
||||
import { LiveElement } from '../lib/element'
|
||||
import { jobHref } from '../lib/runner'
|
||||
@ -15,11 +16,11 @@ import { card, empty, errorNotice, facts, glyph, link, loading } from '../ui/bui
|
||||
import { ago } from '../ui/format'
|
||||
import { said } from './spoken'
|
||||
|
||||
/** "5 min ago" painted as 🕓 5 min (the word "ago" spoken only). */
|
||||
/** "5 min ago" painted as a clock icon and 5 min (the word "ago" spoken only). */
|
||||
export function since(iso: string | null): HTMLSpanElement {
|
||||
const spoken = ago(iso)
|
||||
const short = spoken === 'just now' ? '<1 min' : spoken.replace(/ ago$/, '')
|
||||
return said(spoken, '🕓 ', short)
|
||||
return said(spoken, iconInline('dash.ago'), ' ', short)
|
||||
}
|
||||
|
||||
/** Seconds left on the total block: from `until` when known, else the
|
||||
@ -43,23 +44,26 @@ export class BlockCountdownElement extends LiveElement {
|
||||
return
|
||||
}
|
||||
const left = fmtRemaining(blockSecondsLeft(block))
|
||||
this.replaceChildren(h('span', { class: 'text-danger' }, said(`${left} left`, '⏳ ', left)))
|
||||
this.replaceChildren(h('span', { class: 'text-danger' }, said(`${left} left`, iconInline('dash.block-left'), ' ', left)))
|
||||
}
|
||||
}
|
||||
|
||||
function statusFacts(s: StatusPayload): HTMLDListElement {
|
||||
return facts([
|
||||
[
|
||||
glyph('💾', 'Installed'),
|
||||
s.assigned_game_installed ? glyph('✅', 'Yes') : h('span', { class: 'text-warning' }, glyph('⚠️', 'No — install it from Library')),
|
||||
glyph('dash.installed', 'Installed'),
|
||||
s.assigned_game_installed ? glyph('state.yes', 'Yes') : h('span', { class: 'text-warning' }, glyph('state.warn', 'No — install it from Library')),
|
||||
],
|
||||
[glyph('🏆', 'Games finished'), s.finished_count],
|
||||
[glyph('🛒', 'Store'), s.store_blocked ? glyph('🔒', 'Blocked') : h('span', { class: 'text-warning' }, glyph('🔓', 'Unblocked'))],
|
||||
[glyph('🗂️', 'Installed games'), s.installed_count],
|
||||
[glyph('⛔', 'Total block'), s.total_block.active ? hx('block-countdown') : glyph('➖', 'Off')],
|
||||
[glyph('dash.finished', 'Games finished'), s.finished_count],
|
||||
[
|
||||
glyph('📌', 'Manual picks'),
|
||||
s.manual_picks.length ? s.manual_picks.map((p) => `${p.name} (${p.age_days} d)`).join(', ') : glyph('➖', 'None'),
|
||||
glyph('dash.store', 'Store'),
|
||||
s.store_blocked ? glyph('dash.store-blocked', 'Blocked') : h('span', { class: 'text-warning' }, glyph('dash.store-open', 'Unblocked')),
|
||||
],
|
||||
[glyph('dash.games', 'Installed games'), s.installed_count],
|
||||
[glyph('dash.total-block', 'Total block'), s.total_block.active ? hx('block-countdown') : glyph('state.off', 'Off')],
|
||||
[
|
||||
glyph('picks.manual', 'Manual picks'),
|
||||
s.manual_picks.length ? s.manual_picks.map((p) => `${p.name} (${p.age_days} d)`).join(', ') : glyph('state.off', 'None'),
|
||||
],
|
||||
])
|
||||
}
|
||||
@ -71,13 +75,13 @@ export class DashboardStatusElement extends LiveElement {
|
||||
|
||||
protected update(): void {
|
||||
const { data, error } = q.status.state
|
||||
const icon = '🎯'
|
||||
const icon = 'assigned.game'
|
||||
if (error) {
|
||||
this.replaceChildren(card('Assignment', errorNotice(error), { icon }))
|
||||
} else if (!data) {
|
||||
this.replaceChildren(card('Assignment', loading('status'), { icon }))
|
||||
} else {
|
||||
const game = data.current_game_name ?? glyph('📭', 'Nothing assigned')
|
||||
const game = data.current_game_name ?? glyph('state.empty', 'Nothing assigned')
|
||||
this.replaceChildren(
|
||||
card('Assignment', [h('p', { class: 'hero-game' }, game), statusFacts(data)], {
|
||||
icon,
|
||||
@ -95,9 +99,9 @@ function budgetTone(blocked: boolean, used: number): BarTone {
|
||||
}
|
||||
|
||||
function billingLine(blocked: boolean, label: string): HTMLParagraphElement {
|
||||
if (blocked) return h('p', { class: 'field-help' }, glyph('⛔', 'Blocked for today.'))
|
||||
if (!label) return h('p', { class: 'field-help' }, said('Now: nothing billing', '⏸️'))
|
||||
return h('p', { class: 'field-help' }, said(`Now: ${label}`, '▶️ ', label))
|
||||
if (blocked) return h('p', { class: 'field-help' }, glyph('dash.blocked-today', 'Blocked for today.'))
|
||||
if (!label) return h('p', { class: 'field-help' }, said('Now: nothing billing', iconInline('dash.not-billing')))
|
||||
return h('p', { class: 'field-help' }, said(`Now: ${label}`, iconInline('dash.billing'), ' ', label))
|
||||
}
|
||||
|
||||
export class BudgetGlanceElement extends LiveElement {
|
||||
@ -107,7 +111,7 @@ export class BudgetGlanceElement extends LiveElement {
|
||||
|
||||
protected update(): void {
|
||||
const { data, error } = q.budget.state
|
||||
const icon = '⏱️'
|
||||
const icon = 'dash.budget'
|
||||
if (error) {
|
||||
this.replaceChildren(card('Gaming today', errorNotice(error), { icon }))
|
||||
return
|
||||
@ -128,8 +132,8 @@ export class BudgetGlanceElement extends LiveElement {
|
||||
progressBar(t.fraction_used, 'Budget used', budgetTone(t.blocked, t.fraction_used)),
|
||||
billingLine(t.blocked, data.session.billing_label),
|
||||
]
|
||||
: h('p', { class: 'text-danger' }, data.error ?? glyph('⚠️', 'Budget state unavailable.'))
|
||||
this.replaceChildren(card('Gaming today', body, { icon, aside: link('/gaming/', glyph('➡️', 'Details')) }))
|
||||
: h('p', { class: 'text-danger' }, data.error ?? glyph('state.warn', 'Budget state unavailable.'))
|
||||
this.replaceChildren(card('Gaming today', body, { icon, aside: link('/gaming/', glyph('action.open', 'Details')) }))
|
||||
}
|
||||
}
|
||||
|
||||
@ -140,8 +144,8 @@ function fastInstallRow(r: FastInstallRun): HTMLDivElement {
|
||||
return h(
|
||||
'div',
|
||||
{},
|
||||
h('p', { class: 'text-danger' }, said(`Fast install of ${r.name} failed: ${r.error}`, '⛔ ', r.name, ': ', r.error)),
|
||||
h('p', { class: 'field-help' }, glyph('↪️', "Steam's own download took over.")),
|
||||
h('p', { class: 'text-danger' }, said(`Fast install of ${r.name} failed: ${r.error}`, iconInline('dash.fast-failed'), ' ', r.name, ': ', r.error)),
|
||||
h('p', { class: 'field-help' }, glyph('dash.steam-took-over', "Steam's own download took over.")),
|
||||
)
|
||||
}
|
||||
const pct = r.percent === null ? null : Math.floor(r.percent)
|
||||
@ -149,9 +153,9 @@ function fastInstallRow(r: FastInstallRun): HTMLDivElement {
|
||||
return h(
|
||||
'div',
|
||||
{},
|
||||
h('p', {}, said(`Fast-installing ${r.name} — ${where}`, '⚡ ', r.name, pct === null ? '' : ` ${pct}%`)),
|
||||
h('p', {}, said(`Fast-installing ${r.name} — ${where}`, iconInline('dash.fast-install'), ' ', r.name, pct === null ? '' : ` ${pct}%`)),
|
||||
progressBar(pct === null ? null : pct / 100, `${r.name} download`),
|
||||
h('p', { class: 'field-help' }, said(`${fmtDuration(r.elapsed_seconds)} elapsed`, '⏳ ', fmtDuration(r.elapsed_seconds))),
|
||||
h('p', { class: 'field-help' }, said(`${fmtDuration(r.elapsed_seconds)} elapsed`, iconInline('dash.elapsed'), ' ', fmtDuration(r.elapsed_seconds))),
|
||||
)
|
||||
}
|
||||
|
||||
@ -163,7 +167,7 @@ export class FastInstallsElement extends LiveElement {
|
||||
|
||||
protected update(): void {
|
||||
const runs = q.daemon.state.data?.fast_installs ?? []
|
||||
this.replaceChildren(...(runs.length ? [card('Fast install', runs.map(fastInstallRow), { icon: '⚡' })] : []))
|
||||
this.replaceChildren(...(runs.length ? [card('Fast install', runs.map(fastInstallRow), { icon: 'dash.fast-install' })] : []))
|
||||
}
|
||||
}
|
||||
|
||||
@ -201,7 +205,7 @@ export class RecentJobsElement extends LiveElement {
|
||||
),
|
||||
),
|
||||
],
|
||||
{ icon: '⚙️', aside: link('/jobs/', glyph('➡️', 'All jobs')) },
|
||||
{ icon: 'dash.recent-jobs', aside: link('/jobs/', glyph('action.open', 'All jobs')) },
|
||||
),
|
||||
)
|
||||
}
|
||||
|
||||
@ -6,6 +6,8 @@
|
||||
import { OTHER_KEY, UNATTRIBUTED_KEY, seriesClass } from '../../budgetSeries'
|
||||
import { fmtAgo, fmtDuration } from '../../format'
|
||||
import { budgetHistorySvg } from '../../lib/charts/budgetHistory'
|
||||
import { iconInline } from '../../icons/render'
|
||||
import type { IconId } from '../../icons/registry'
|
||||
import { h } from '../../lib/dom'
|
||||
import type { BudgetHistoryDay, BudgetLegendEntry, BudgetRules, BudgetSession, BudgetToday } from '../../types'
|
||||
import { glyph } from '../../ui/build'
|
||||
@ -25,17 +27,17 @@ function meterState(today: BudgetToday): string {
|
||||
|
||||
/** A series name: game names are content; the sentinels and the "(launcher)" tag are glyphs. */
|
||||
export function seriesLabel(key: string, label: string): HTMLElement {
|
||||
if (key === OTHER_KEY) return glyph('➕', label)
|
||||
if (key === UNATTRIBUTED_KEY) return glyph('❔', label)
|
||||
if (key.startsWith('launcher:')) return said(label, '🚀 ', label.replace(/\s*\(launcher\)$/, ''))
|
||||
if (key === OTHER_KEY) return glyph('gaming.series.other', label)
|
||||
if (key === UNATTRIBUTED_KEY) return glyph('gaming.series.unattributed', label)
|
||||
if (key.startsWith('launcher:')) return said(label, iconInline('gaming.launcher'), ' ', label.replace(/\s*\(launcher\)$/, ''))
|
||||
return h('span', {}, label)
|
||||
}
|
||||
|
||||
/** "5m ago" painted as 🕓 5m. */
|
||||
/** "5m ago" painted as the as-of icon and 5m. */
|
||||
function asOf(iso: string): HTMLElement {
|
||||
const ago = fmtAgo(iso)
|
||||
const short = ago === 'unknown' ? '?' : ago === 'just now' ? '<10s' : ago.replace(/ ago$/, '')
|
||||
return said(`as of ${ago}`, '🕓 ', short)
|
||||
return said(`as of ${ago}`, iconInline('dash.ago'), ' ', short)
|
||||
}
|
||||
|
||||
function warningLine(today: BudgetToday, maskedCount: number): HTMLElement {
|
||||
@ -48,14 +50,14 @@ function warningLine(today: BudgetToday, maskedCount: number): HTMLElement {
|
||||
'span',
|
||||
{ class: 'budget-badge budget-badge--blocked' },
|
||||
maskedCount > 0
|
||||
? glyph('⛔🔒', 'Cutoff engaged — launchers are masked')
|
||||
: glyph('⛔🔓', 'Cutoff engaged — launchers are not currently masked'),
|
||||
? glyph('gaming.cutoff.masked', 'Cutoff engaged — launchers are masked')
|
||||
: glyph('gaming.cutoff.unmasked', 'Cutoff engaged — launchers are not currently masked'),
|
||||
)
|
||||
}
|
||||
const next = today.next_warning_seconds
|
||||
return next === null
|
||||
? glyph('🔕', 'No further warnings today.')
|
||||
: said(`Next warning at ${fmtDuration(next)} remaining.`, '🔔 ', fmtDuration(next))
|
||||
? glyph('gaming.warn.none', 'No further warnings today.')
|
||||
: said(`Next warning at ${fmtDuration(next)} remaining.`, iconInline('gaming.warning'), ' ', fmtDuration(next))
|
||||
}
|
||||
|
||||
function usageLine(t: BudgetToday): HTMLElement {
|
||||
@ -63,7 +65,18 @@ function usageLine(t: BudgetToday): HTMLElement {
|
||||
const spoken =
|
||||
`${fmtDuration(t.seconds_used)} of ${fmtDuration(t.budget_seconds)} used · ` +
|
||||
`${Math.round(t.fraction_used * 100)}% · gaming day ${t.gaming_day} (starts ${t.day_starts_at})`
|
||||
return said(spoken, used, ' · 📅 ', t.gaming_day, ' · 🌅 ', t.day_starts_at.replace(/\s*local$/, ''))
|
||||
return said(
|
||||
spoken,
|
||||
used,
|
||||
' · ',
|
||||
iconInline('gaming.day'),
|
||||
' ',
|
||||
t.gaming_day,
|
||||
' · ',
|
||||
iconInline('gaming.day_start'),
|
||||
' ',
|
||||
t.day_starts_at.replace(/\s*local$/, ''),
|
||||
)
|
||||
}
|
||||
|
||||
export function todayCard(today: BudgetToday, legend: readonly BudgetLegendEntry[], maskedCount: number): HTMLElement {
|
||||
@ -76,14 +89,14 @@ export function todayCard(today: BudgetToday, legend: readonly BudgetLegendEntry
|
||||
return h(
|
||||
'section',
|
||||
{ class: 'budget-today' },
|
||||
h('h2', {}, glyph('📅', 'Today')),
|
||||
h('h2', {}, glyph('gaming.today', 'Today')),
|
||||
h('p', { class: 'budget-hero' }, h('strong', {}, fmtDuration(today.seconds_remaining)), h('span', { class: 'sr-only' }, ' left')),
|
||||
h('div', { class: `budget-meter budget-meter--${meterState(today)}` }, fill),
|
||||
h('p', { class: 'hint' }, usageLine(today)),
|
||||
h('p', { class: 'hint' }, warningLine(today, maskedCount)),
|
||||
today.games.length > 0
|
||||
? [
|
||||
h('h3', { class: 'budget-subhead' }, glyph('🎮', 'Today by game')),
|
||||
h('h3', { class: 'budget-subhead' }, glyph('gaming.by_game', 'Today by game')),
|
||||
h(
|
||||
'ul',
|
||||
{ class: 'budget-games' },
|
||||
@ -108,23 +121,23 @@ export function todayUnavailable(error: string | null): HTMLElement {
|
||||
return h(
|
||||
'section',
|
||||
{ class: 'budget-today' },
|
||||
h('h2', {}, glyph('📅', 'Today')),
|
||||
h('h2', {}, glyph('gaming.today', 'Today')),
|
||||
// The server's own error is shown as is; the fallback is a glyph.
|
||||
h('p', { class: 'error' }, error ?? glyph('⚠️', 'Budget state unavailable.')),
|
||||
h('p', { class: 'error' }, error ?? glyph('state.warn', 'Budget state unavailable.')),
|
||||
)
|
||||
}
|
||||
|
||||
const VERDICT = new Map([
|
||||
['engaged', ['▶️', 'Billing — you are playing']],
|
||||
['not_applicable', ['⏸️', 'Not billing — no game running']],
|
||||
const VERDICT = new Map<string, readonly [IconId, string]>([
|
||||
['engaged', ['dash.billing', 'Billing — you are playing']],
|
||||
['not_applicable', ['dash.not-billing', 'Not billing — no game running']],
|
||||
])
|
||||
|
||||
export function liveCard(session: BudgetSession): HTMLElement {
|
||||
const title = h('h2', {}, glyph('📡', 'Right now'))
|
||||
const title = h('h2', {}, glyph('gaming.right_now', 'Right now'))
|
||||
if (!session.available) {
|
||||
return h('section', { class: 'budget-live' }, title, h('p', { class: 'hint' }, glyph('📭', 'No verdict has been logged yet.')))
|
||||
return h('section', { class: 'budget-live' }, title, h('p', { class: 'hint' }, glyph('state.empty', 'No verdict has been logged yet.')))
|
||||
}
|
||||
const [icon, verdict] = VERDICT.get(session.state) ?? ['❔', session.state]
|
||||
const [icon, verdict] = VERDICT.get(session.state) ?? (['state.unknown', session.state] as const)
|
||||
return h(
|
||||
'section',
|
||||
{ class: 'budget-live' },
|
||||
@ -134,8 +147,8 @@ export function liveCard(session: BudgetSession): HTMLElement {
|
||||
? h(
|
||||
'p',
|
||||
{ class: 'hint' },
|
||||
session.game_name ? [said('Assigned game ', '🎯 '), h('strong', {}, session.game_name), ' · '] : null,
|
||||
said(`${session.qualifying_count} qualifying processes`, '⚙️ ', session.qualifying_count),
|
||||
session.game_name ? [said('Assigned game ', iconInline('assigned.game'), ' '), h('strong', {}, session.game_name), ' · '] : null,
|
||||
said(`${session.qualifying_count} qualifying processes`, iconInline('gaming.qualifying'), ' ', session.qualifying_count),
|
||||
)
|
||||
: null,
|
||||
// The assignment above is what the enforcer told you to play; this is
|
||||
@ -146,7 +159,9 @@ export function liveCard(session: BudgetSession): HTMLElement {
|
||||
? h(
|
||||
'p',
|
||||
{ class: 'hint' },
|
||||
session.state === 'engaged' ? said('Billing to ', '💸 ') : said('Last billed to ', '⏮️💸 '),
|
||||
session.state === 'engaged'
|
||||
? said('Billing to ', iconInline('gaming.billing_to'), ' ')
|
||||
: said('Last billed to ', iconInline('gaming.billed_last'), ' '),
|
||||
h('strong', {}, session.billing_label),
|
||||
)
|
||||
: null,
|
||||
@ -157,13 +172,13 @@ export function liveCard(session: BudgetSession): HTMLElement {
|
||||
}
|
||||
|
||||
export function historyCard(days: readonly BudgetHistoryDay[], legend: readonly BudgetLegendEntry[], budgetSeconds: number): HTMLElement {
|
||||
const title = h('h2', {}, glyph('📊', 'Last 14 days'))
|
||||
const title = h('h2', {}, glyph('gaming.history', 'Last 14 days'))
|
||||
if (days.length === 0) {
|
||||
return h(
|
||||
'div',
|
||||
{ class: 'chart' },
|
||||
title,
|
||||
h('p', { class: 'hint' }, glyph('📭', 'No budget history recorded yet — a bar appears for each gaming day from now on.')),
|
||||
h('p', { class: 'hint' }, glyph('state.empty', 'No budget history recorded yet — a bar appears for each gaming day from now on.')),
|
||||
)
|
||||
}
|
||||
// A <template> parses the markup as HTML, which puts <svg> in the SVG namespace.
|
||||
@ -189,24 +204,24 @@ export function historyCard(days: readonly BudgetHistoryDay[], legend: readonly
|
||||
)
|
||||
}
|
||||
|
||||
const onOff = (value: boolean, on: string, off: string) => (value ? glyph('✅', on) : glyph('➖', off))
|
||||
const onOff = (value: boolean, on: string, off: string) => (value ? glyph('state.yes', on) : glyph('state.off', off))
|
||||
|
||||
export function rulesCard(rules: BudgetRules): HTMLElement {
|
||||
const row = (icon: string, term: string, value: Node | string) => [h('dt', {}, glyph(icon, term)), h('dd', {}, value)]
|
||||
const row = (icon: IconId, term: string, value: Node | string) => [h('dt', {}, glyph(icon, term)), h('dd', {}, value)]
|
||||
const warn = rules.warn_at.map((s) => fmtDuration(s)).join(', ')
|
||||
return h(
|
||||
'section',
|
||||
{ class: 'budget-rules' },
|
||||
h('h2', {}, glyph('📏', 'Rules in effect')),
|
||||
h('h2', {}, glyph('gaming.rules', 'Rules in effect')),
|
||||
h(
|
||||
'dl',
|
||||
{ class: 'budget-rules-list' },
|
||||
row('⏱️', 'Daily budget', fmtDuration(rules.budget_seconds)),
|
||||
row('🛡️', 'Enforcement', onOff(rules.enforcement, 'on', 'off')),
|
||||
row('🚀', 'Counts launchers', onOff(rules.counts_launchers, 'yes', 'no')),
|
||||
row('🔔', 'Warnings at', said(`${warn} remaining`, warn)),
|
||||
rules.demo ? row('🧪', 'Mode', glyph('🧪', 'demo (short budget, separate state)')) : null,
|
||||
rules.masked_launchers.length > 0 ? row('🔒', 'Masked now', rules.masked_launchers.join(', ')) : null,
|
||||
row('gaming.budget', 'Daily budget', fmtDuration(rules.budget_seconds)),
|
||||
row('gaming.enforcement', 'Enforcement', onOff(rules.enforcement, 'on', 'off')),
|
||||
row('gaming.launcher', 'Counts launchers', onOff(rules.counts_launchers, 'yes', 'no')),
|
||||
row('gaming.warning', 'Warnings at', said(`${warn} remaining`, warn)),
|
||||
rules.demo ? row('gaming.mode', 'Mode', glyph('gaming.demo', 'demo (short budget, separate state)')) : null,
|
||||
rules.masked_launchers.length > 0 ? row('gaming.masked', 'Masked now', rules.masked_launchers.join(', ')) : null,
|
||||
),
|
||||
)
|
||||
}
|
||||
|
||||
82
web/src/sections/gaming/icons.test.ts
Normal file
82
web/src/sections/gaming/icons.test.ts
Normal file
@ -0,0 +1,82 @@
|
||||
// The gaming page paints every icon through the registry: the user's word
|
||||
// shows right of the icon, a chosen alternative glyph replaces the default,
|
||||
// and the spoken sentence stays as it was.
|
||||
|
||||
import { screen } from '@testing-library/dom'
|
||||
import { afterEach, describe, expect, it } from 'vitest'
|
||||
import { OTHER_KEY } from '../../budgetSeries'
|
||||
import { makeBudgetRules, makeBudgetSession, makeBudgetToday } from '../../test/factories'
|
||||
import { mount } from '../../test/harness'
|
||||
import { useIcons } from '../../test/iconLedger'
|
||||
import { liveCard, rulesCard, seriesLabel, todayCard, todayUnavailable } from './cards'
|
||||
import './panel'
|
||||
|
||||
const show = (el: HTMLElement) => {
|
||||
document.body.replaceChildren(el)
|
||||
}
|
||||
const words = () => [...document.querySelectorAll('.icon-word')].map((w) => w.textContent)
|
||||
|
||||
afterEach(() => {
|
||||
history.replaceState(null, '', '/')
|
||||
})
|
||||
|
||||
describe('gaming page icons', () => {
|
||||
it('rules card: a word right of the row icon, an alternative glyph, spoken names kept', () => {
|
||||
useIcons({ 'gaming.budget': { word: 'allowance' }, 'gaming.enforcement': { glyph: '⚔️' }, 'state.yes': { word: 'on' } })
|
||||
show(rulesCard(makeBudgetRules()))
|
||||
const term = document.querySelector('dt')
|
||||
expect(term?.querySelector('[data-icon]')?.nextElementSibling).toHaveClass('icon-word')
|
||||
expect(term?.querySelector('.icon-word')?.textContent).toBe('Allowance')
|
||||
expect(term?.querySelector('.sr-only')?.textContent).toBe('Daily budget')
|
||||
expect(document.querySelectorAll('dt').item(1).querySelector('[data-icon]')?.textContent).toBe('⚔️')
|
||||
expect(words()).toEqual(['Allowance', 'On', 'On'])
|
||||
})
|
||||
|
||||
it('today card: warning, gaming day and heading icons carry the words', () => {
|
||||
useIcons({ 'gaming.warning': { word: 'bell' }, 'gaming.day': { word: 'date' }, 'gaming.today': { glyph: '🗓️' } })
|
||||
show(todayCard(makeBudgetToday(), [], 0))
|
||||
expect(words()).toEqual(['Date', 'Bell'])
|
||||
expect(screen.getByText(/Next warning at 1h 0m remaining/)).toBeInTheDocument()
|
||||
expect(document.querySelector('h2 [data-icon]')?.textContent).toBe('🗓️')
|
||||
})
|
||||
|
||||
it('unavailable and empty marks reuse the shared state icons', () => {
|
||||
useIcons({ 'state.warn': { word: 'attention' } })
|
||||
show(todayUnavailable(null))
|
||||
expect(words()).toEqual(['Attention'])
|
||||
expect(screen.getByText('Budget state unavailable.')).toBeInTheDocument()
|
||||
})
|
||||
|
||||
it('live card: the verdict icon swaps and the billing icon shows its word', () => {
|
||||
useIcons({ 'dash.billing': { glyph: '⏺️' }, 'gaming.billing_to': { word: 'charging' }, 'assigned.game': { word: 'target' } })
|
||||
show(liveCard(makeBudgetSession()))
|
||||
expect(document.querySelector('.budget-verdict [data-icon]')?.textContent).toBe('⏺️')
|
||||
expect(words()).toEqual(['Target', 'Charging'])
|
||||
expect(screen.getByText('Billing to')).toBeInTheDocument()
|
||||
expect(screen.getByText('Billing — you are playing')).toBeInTheDocument()
|
||||
})
|
||||
|
||||
it('series labels: the other-games sentinel and a launcher carry their icons', () => {
|
||||
useIcons({ 'gaming.series.other': { word: 'rest' }, 'gaming.launcher': { word: 'client' } })
|
||||
show(wrap(seriesLabel(OTHER_KEY, 'Other games')))
|
||||
expect(words()).toEqual(['Rest'])
|
||||
show(wrap(seriesLabel('launcher:epic', 'Epic (launcher)')))
|
||||
expect(words()).toEqual(['Client'])
|
||||
expect(document.body.textContent).toContain('Epic')
|
||||
})
|
||||
|
||||
it('mode link: the demo and production icons take the chosen glyph', () => {
|
||||
useIcons({ 'gaming.demo': { glyph: '🔬' }, 'gaming.production': { glyph: '🏢' } })
|
||||
mount('<budget-mode-link></budget-mode-link>')
|
||||
expect(screen.getByRole('link', { name: 'Show demo budget' }).querySelector('[data-icon]')?.textContent).toBe('🔬')
|
||||
history.replaceState(null, '', '/gaming/?demo=1')
|
||||
mount('<budget-mode-link></budget-mode-link>')
|
||||
expect(screen.getByRole('link', { name: 'Show production budget' }).querySelector('[data-icon]')?.textContent).toBe('🏢')
|
||||
})
|
||||
})
|
||||
|
||||
function wrap(child: HTMLElement): HTMLElement {
|
||||
const el = document.createElement('div')
|
||||
el.append(child)
|
||||
return el
|
||||
}
|
||||
@ -5,6 +5,7 @@
|
||||
|
||||
import { explain } from '../../api/errors'
|
||||
import { q } from '../../api/queries'
|
||||
import { iconInline } from '../../icons/render'
|
||||
import { define, h } from '../../lib/dom'
|
||||
import { LiveElement } from '../../lib/element'
|
||||
import { commandLine, glyph, loading } from '../../ui/build'
|
||||
@ -21,12 +22,12 @@ export function isDemo(search: string = location.search): boolean {
|
||||
export class BudgetModeLinkElement extends LiveElement {
|
||||
protected update(): void {
|
||||
const demo = isDemo()
|
||||
// 🧪 switches to the demo budget, 🏭 back to production; the words are spoken.
|
||||
// The demo icon switches to the demo budget, the production icon back; the words are spoken.
|
||||
this.replaceChildren(
|
||||
h(
|
||||
'a',
|
||||
{ href: demo ? '/gaming/' : '/gaming/?demo=1', class: 'btn btn-ghost' },
|
||||
demo ? glyph('🏭', 'Show production budget') : glyph('🧪', 'Show demo budget'),
|
||||
demo ? glyph('gaming.production', 'Show production budget') : glyph('gaming.demo', 'Show demo budget'),
|
||||
),
|
||||
)
|
||||
}
|
||||
@ -50,7 +51,7 @@ export class BudgetPanelElement extends LiveElement {
|
||||
{ class: 'status' },
|
||||
// The server's own detail is painted; the framing is spoken. The
|
||||
// command is the recovery path, so it stays with a copy button.
|
||||
h('p', { class: 'error' }, said(`Could not read budget state: ${explain(error).detail}`, '⛔ ', explain(error).detail)),
|
||||
h('p', { class: 'error' }, said(`Could not read budget state: ${explain(error).detail}`, iconInline('notice.danger'), ' ', explain(error).detail)),
|
||||
h('p', { class: 'hint' }, h('span', { class: 'sr-only' }, 'Is the backend running? Start it with')),
|
||||
commandLine('./run.sh serve'),
|
||||
),
|
||||
|
||||
@ -4,6 +4,8 @@
|
||||
// browser's search state, so a reload comes back to it.
|
||||
|
||||
import { q } from '../api/queries'
|
||||
import type { IconId } from '../icons/registry'
|
||||
import { iconInline } from '../icons/render'
|
||||
import { define, h, hx } from '../lib/dom'
|
||||
import { LiveElement } from '../lib/element'
|
||||
import '../library/gameBrowser'
|
||||
@ -13,10 +15,10 @@ import { bytes } from '../ui/format'
|
||||
|
||||
type View = 'all' | 'installed'
|
||||
|
||||
/** View key, spoken label, painted glyph. */
|
||||
const VIEWS: [View, string, string][] = [
|
||||
['all', 'All games', '🗂️'],
|
||||
['installed', 'Installed', '💾'],
|
||||
/** View key, spoken label, painted icon. */
|
||||
const VIEWS: [View, string, IconId][] = [
|
||||
['all', 'All games', 'libpage.all'],
|
||||
['installed', 'Installed', 'dash.installed'],
|
||||
]
|
||||
|
||||
const viewFromHash = (): View => (readHash().get('view') === 'installed' ? 'installed' : 'all')
|
||||
@ -66,10 +68,10 @@ export class InstalledTableElement extends LiveElement {
|
||||
h(
|
||||
'tr',
|
||||
{},
|
||||
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('th', { scope: 'col' }, glyph('libpage.game', 'Game')),
|
||||
h('th', { scope: 'col' }, glyph('libpage.app-id', 'App id')),
|
||||
h('th', { scope: 'col', class: 'num' }, glyph('libpage.size', 'Size')),
|
||||
h('th', { scope: 'col' }, glyph('libpage.role', 'Role')),
|
||||
),
|
||||
),
|
||||
h(
|
||||
@ -85,9 +87,9 @@ export class InstalledTableElement extends LiveElement {
|
||||
h(
|
||||
'td',
|
||||
{},
|
||||
g.assigned ? pill('accent', 'assigned', '🎯') : null,
|
||||
g.protected ? pill('neutral', 'protected', '🛡️') : null,
|
||||
!g.assigned && !g.protected ? glyph('🗑️', 'uninstall candidate', 'muted') : null,
|
||||
g.assigned ? pill('accent', 'assigned', 'assigned.game') : null,
|
||||
g.protected ? pill('neutral', 'protected', 'libpage.protected') : null,
|
||||
!g.assigned && !g.protected ? glyph('libpage.candidate', 'uninstall candidate', 'muted') : null,
|
||||
),
|
||||
),
|
||||
),
|
||||
@ -97,12 +99,12 @@ export class InstalledTableElement extends LiveElement {
|
||||
: null,
|
||||
],
|
||||
{
|
||||
icon: '💾',
|
||||
icon: 'dash.installed',
|
||||
aside: data
|
||||
? h(
|
||||
'span',
|
||||
{ class: 'muted' },
|
||||
h('span', { 'aria-hidden': 'true' }, `🎮 ${games.length} · 💽 ${bytes(total)}`),
|
||||
h('span', { 'aria-hidden': 'true' }, iconInline('libpage.game'), ` ${games.length} · `, iconInline('libpage.size'), ` ${bytes(total)}`),
|
||||
h('span', { class: 'sr-only' }, `${games.length} games · ${bytes(total)}`),
|
||||
)
|
||||
: null,
|
||||
@ -143,7 +145,7 @@ export class LibraryViewElement extends HTMLElement {
|
||||
this.show(key)
|
||||
},
|
||||
},
|
||||
h('span', { 'aria-hidden': 'true' }, icon),
|
||||
h('span', { 'aria-hidden': 'true' }, iconInline(icon)),
|
||||
)
|
||||
this.buttons.set(key, btn)
|
||||
return btn
|
||||
|
||||
@ -3,12 +3,13 @@
|
||||
|
||||
import { q } from '../api/queries'
|
||||
import { commandButton } from '../commands/commandButton'
|
||||
import { define, h } from '../lib/dom'
|
||||
import { iconInline } from '../icons/render'
|
||||
import { define, h, type Child } 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 {
|
||||
function glyphText(painted: readonly Child[], spoken: string): HTMLSpanElement {
|
||||
return h('span', { class: 'muted' }, h('span', { 'aria-hidden': 'true' }, painted), h('span', { class: 'sr-only' }, spoken))
|
||||
}
|
||||
|
||||
@ -51,7 +52,7 @@ export class ManualPicksElement extends LiveElement {
|
||||
{ class: 'grow' },
|
||||
h('strong', {}, p.name),
|
||||
' ',
|
||||
glyphText(`· 🕐 ${p.age_days} d · ${p.app_id}`, `· picked ${p.age_days} d ago · ${p.app_id}`),
|
||||
glyphText(['· ', iconInline('picks.age'), ` ${p.age_days} d · ${p.app_id}`], `· picked ${p.age_days} d ago · ${p.app_id}`),
|
||||
),
|
||||
abandon(p.app_id),
|
||||
),
|
||||
@ -61,7 +62,7 @@ export class ManualPicksElement extends LiveElement {
|
||||
h(
|
||||
'li',
|
||||
{ class: 'row' },
|
||||
h('span', { class: 'grow' }, h('strong', {}, p.name), ' ', glyphText(`· 📌 🔓 · ${p.app_id}`, `· kept · no lock · ${p.app_id}`)),
|
||||
h('span', { class: 'grow' }, h('strong', {}, p.name), ' ', glyphText(['· ', iconInline('picks.kept'), ' ', iconInline('state.unlocked'), ` · ${p.app_id}`], `· kept · no lock · ${p.app_id}`)),
|
||||
abandon(p.app_id),
|
||||
),
|
||||
),
|
||||
@ -69,7 +70,7 @@ export class ManualPicksElement extends LiveElement {
|
||||
none
|
||||
? h('div', { class: 'actions' }, commandButton({ name: 'abandon-pick', label: 'Abandon a pick by app id…' }))
|
||||
: null,
|
||||
], { icon: '📌' }),
|
||||
], { icon: 'picks.manual' }),
|
||||
)
|
||||
}
|
||||
}
|
||||
|
||||
@ -2,6 +2,7 @@
|
||||
// right now. Nothing shows until the status is known.
|
||||
|
||||
import { q } from '../api/queries'
|
||||
import { iconInline } from '../icons/render'
|
||||
import { define, h } from '../lib/dom'
|
||||
import { LiveElement } from '../lib/element'
|
||||
import { notice } from '../ui/build'
|
||||
@ -17,11 +18,11 @@ export class StoreNoticeElement extends LiveElement {
|
||||
this.replaceChildren()
|
||||
return
|
||||
}
|
||||
// Textgate: 🛒 + lock state painted (tone is the 2nd channel), the sentence spoken.
|
||||
// Textgate: the store + lock state icon 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))
|
||||
? (['info', 'store.blocked', 'Store blocked. Unblocking takes a typed phrase and is capped at 30 minutes.'] as const)
|
||||
: (['warning', 'store.open', 'Store unblocked. The store is open right now; it re-blocks automatically.'] as const)
|
||||
const el = notice(tone, null, h('span', { 'aria-hidden': 'true' }, iconInline(icon)), h('span', { class: 'sr-only' }, spoken))
|
||||
el.dataset.blocked = String(data.store_blocked)
|
||||
this.replaceChildren(el)
|
||||
}
|
||||
|
||||
Loading…
Reference in New Issue
Block a user