Add mobile-first web UI
Compare (duel with row-by-row comparison and thumb-reach pick bar), Ranking, Triage (keep/drop pass, problem schools first), school detail with sources and notes, Settings. Picks go to a localStorage outbox first and sync in the background, so nothing is lost on a flaky connection. Light/dark themes, installable to the home screen. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01HA82gXkMmmRRKLSnY6vQN3
This commit is contained in:
parent
67f9b199ec
commit
0951f34a9d
15 changed files with 1531 additions and 0 deletions
125
public/js/views/duel.js
Normal file
125
public/js/views/duel.js
Normal file
|
|
@ -0,0 +1,125 @@
|
|||
// The main screen: two schools side by side, a comparison table, and pick buttons in thumb reach.
|
||||
|
||||
import { html, bar } from '../ui.js';
|
||||
import { COMPARE_ROWS, rowWinner, shortName, place } from '../metrics.js';
|
||||
import { PROVISIONAL_GAMES } from '../elo.js';
|
||||
|
||||
function head(app, s, side) {
|
||||
const st = app.state.stats.get(s.code);
|
||||
const rank = app.rankOf(s.code);
|
||||
const provisional = st.games < PROVISIONAL_GAMES;
|
||||
return html`
|
||||
<button type="button" class="school-head side-${side}" data-action="open" data-slug="${s.slug}"
|
||||
aria-label="Details for ${shortName(s)}">
|
||||
<span class="side-tag">${side.toUpperCase()}</span>
|
||||
<span class="flag" aria-hidden="true">${s.flag}</span>
|
||||
<span class="sname">${shortName(s)}</span>
|
||||
<span class="splace">${place(s)}</span>
|
||||
<span class="srating ${provisional ? 'provisional' : ''}">
|
||||
${provisional ? '~' : ''}${Math.round(st.rating)}
|
||||
<small>${rank && st.games ? `#${rank} · ` : ''}${st.games} ${st.games === 1 ? 'game' : 'games'}</small>
|
||||
</span>
|
||||
${s.research ? '' : html`<span class="chip warn">research pending</span>`}
|
||||
</button>`;
|
||||
}
|
||||
|
||||
function table(app, a, b) {
|
||||
let section = '';
|
||||
const rows = [];
|
||||
for (const row of COMPARE_ROWS) {
|
||||
if (row.section !== section) {
|
||||
section = row.section;
|
||||
rows.push(html`<div class="cmp-section">${section}</div>`);
|
||||
}
|
||||
const va = row.get(a, app.ctx);
|
||||
const vb = row.get(b, app.ctx);
|
||||
if (!va && !vb) continue;
|
||||
const win = rowWinner(row, va, vb);
|
||||
const cell = (v, side) => {
|
||||
if (!v) return html`<div class="cmp-val muted">–</div>`;
|
||||
const content = v.bar != null ? bar(v.bar) : html`<span class="txt ${v.tone ? `tone-${v.tone}` : ''}">${v.text}</span>`;
|
||||
return html`<div class="cmp-val ${win === side ? `win win-${side}` : ''}">${content}</div>`;
|
||||
};
|
||||
rows.push(html`
|
||||
<div class="cmp-row" ${row.hint ? html`title="${row.hint}"` : ''}>
|
||||
<div class="cmp-label">${row.label}</div>${cell(va, 'a')}${cell(vb, 'b')}
|
||||
</div>`);
|
||||
}
|
||||
return html`<div class="cmp">${rows}</div>`;
|
||||
}
|
||||
|
||||
function flagsBlock(s, side) {
|
||||
const r = s.research;
|
||||
if (!r) return '';
|
||||
const items = [
|
||||
...r.highlights.slice(0, 3).map((t) => html`<li class="hl">${t}</li>`),
|
||||
...r.watchouts.slice(0, 3).map((t) => html`<li class="wo">${t}</li>`),
|
||||
];
|
||||
return html`
|
||||
<div class="flags side-${side}">
|
||||
<h3><span class="side-tag">${side.toUpperCase()}</span> ${shortName(s)}</h3>
|
||||
<p class="summary">${r.summary}</p>
|
||||
<ul>${items}</ul>
|
||||
</div>`;
|
||||
}
|
||||
|
||||
export function render(root, app) {
|
||||
const pair = app.currentPair();
|
||||
if (!pair) {
|
||||
root.innerHTML = String(html`
|
||||
<section class="empty">
|
||||
<h2>Not enough schools left</h2>
|
||||
<p>You need at least two schools that aren't dropped. Restore some in the ranking.</p>
|
||||
<a class="btn" href="#/rank">Open the ranking</a>
|
||||
</section>`);
|
||||
return;
|
||||
}
|
||||
const [a, b] = pair.map((c) => app.byCode.get(c));
|
||||
const undoable = app.state.lastUndoable;
|
||||
root.innerHTML = String(html`
|
||||
<section class="duel" aria-label="Which school do you prefer?">
|
||||
<p class="prompt">Which would you rather go to?</p>
|
||||
<div class="duel-heads">${head(app, a, 'a')}<span class="vs" aria-hidden="true">vs</span>${head(app, b, 'b')}</div>
|
||||
${table(app, a, b)}
|
||||
<div class="duel-flags">${flagsBlock(a, 'a')}${flagsBlock(b, 'b')}</div>
|
||||
<div class="duel-drop">
|
||||
<button type="button" class="link" data-action="drop" data-code="${a.code}">Drop A from the race</button>
|
||||
<button type="button" class="link" data-action="drop" data-code="${b.code}">Drop B from the race</button>
|
||||
</div>
|
||||
</section>
|
||||
<div class="actionbar" role="group" aria-label="Pick">
|
||||
<div class="actionbar-sub">
|
||||
<button type="button" class="ghost" data-action="undo" ${undoable ? '' : 'disabled'}>Undo</button>
|
||||
<span class="muted small">${app.state.matches.length} picks</span>
|
||||
<button type="button" class="ghost" data-action="skip">Skip</button>
|
||||
</div>
|
||||
<div class="actionbar-main">
|
||||
<button type="button" class="pick pick-a" data-action="pick" data-r="a"><span>A</span> ${shortName(a)}</button>
|
||||
<button type="button" class="pick pick-draw" data-action="pick" data-r="draw" aria-label="Too close to call">=</button>
|
||||
<button type="button" class="pick pick-b" data-action="pick" data-r="b">${shortName(b)} <span>B</span></button>
|
||||
</div>
|
||||
</div>`);
|
||||
|
||||
root.onclick = (e) => {
|
||||
const t = e.target.closest('[data-action]');
|
||||
if (!t || t.disabled) return;
|
||||
const action = t.dataset.action;
|
||||
if (action === 'pick') app.pick(a.code, b.code, t.dataset.r);
|
||||
else if (action === 'skip') app.skip();
|
||||
else if (action === 'undo') app.undo();
|
||||
else if (action === 'drop') app.drop(t.dataset.code);
|
||||
else if (action === 'open') app.navigate(`#/school/${t.dataset.slug}`);
|
||||
};
|
||||
}
|
||||
|
||||
/** Desktop shortcuts: ←/→ pick, ↓ or = draw, space skip, z/backspace undo. */
|
||||
export function onKey(e, app) {
|
||||
if (e.target.closest('input, textarea, select')) return false;
|
||||
const pair = app.currentPair();
|
||||
if (!pair) return false;
|
||||
const map = { ArrowLeft: 'a', ArrowRight: 'b', ArrowDown: 'draw', '=': 'draw' };
|
||||
if (map[e.key]) { app.pick(pair[0], pair[1], map[e.key]); return true; }
|
||||
if (e.key === ' ') { app.skip(); return true; }
|
||||
if (e.key === 'z' || e.key === 'Backspace') { app.undo(); return true; }
|
||||
return false;
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue