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
116
public/js/views/rank.js
Normal file
116
public/js/views/rank.js
Normal file
|
|
@ -0,0 +1,116 @@
|
|||
// Leaderboard: everything ordered by your Elo, with filters and alternative sort orders.
|
||||
|
||||
import { html, local } from '../ui.js';
|
||||
import { shortName, place, netCost, moneyRange, languageFit } from '../metrics.js';
|
||||
import { ranking, PROVISIONAL_GAMES } from '../elo.js';
|
||||
|
||||
const SORTS = {
|
||||
rating: { label: 'My Elo', key: (s, st) => -st.rating },
|
||||
academic: { label: 'AI/robotics research', key: (s) => -(s.research?.aiRobotics?.academic?.score ?? -1) },
|
||||
access: { label: 'Course access', key: (s) => -(s.research?.aiRobotics?.access?.score ?? -1) },
|
||||
net: { label: 'Cheapest', key: (s, st, app) => { const n = netCost(s, app.settings, app.data); return n ? (n.lo + n.hi) / 2 : 1e9; } },
|
||||
nature: { label: 'Nature (avg)', key: (s) => {
|
||||
const n = s.research?.nature;
|
||||
return n ? -(n.climbing.score + n.hiking.score + n.ocean.score) / 3 : 1;
|
||||
} },
|
||||
name: { label: 'Name', key: (s) => shortName(s).toLowerCase() },
|
||||
};
|
||||
|
||||
export function render(root, app) {
|
||||
const prefs = local.get('rank', { q: '', region: '', scope: '', sort: 'rating', dropped: false });
|
||||
const all = ranking(app.state.stats, { includeDropped: true });
|
||||
const position = new Map(ranking(app.state.stats).map((s, i) => [s.code, i + 1]));
|
||||
const q = prefs.q.trim().toLowerCase();
|
||||
const regions = [...new Set(app.data.schools.map((s) => s.region))].sort();
|
||||
|
||||
const rows = all
|
||||
.map((st) => ({ st, s: app.byCode.get(st.code) }))
|
||||
.filter(({ s, st }) => (prefs.dropped ? st.dropped : !st.dropped))
|
||||
.filter(({ s }) => !prefs.region || s.region === prefs.region)
|
||||
.filter(({ s }) => !prefs.scope || s.agreements.some((a) => a.scope === prefs.scope))
|
||||
.filter(({ s }) => !q || `${shortName(s)} ${s.research?.name ?? ''} ${s.catalogName} ${s.research?.city ?? ''} ${s.countryShort} ${s.code}`
|
||||
.toLowerCase().includes(q));
|
||||
const sort = SORTS[prefs.sort] ?? SORTS.rating;
|
||||
rows.sort((x, y) => {
|
||||
const kx = sort.key(x.s, x.st, app);
|
||||
const ky = sort.key(y.s, y.st, app);
|
||||
return kx < ky ? -1 : kx > ky ? 1 : y.st.rating - x.st.rating;
|
||||
});
|
||||
const droppedCount = all.filter((s) => s.dropped).length;
|
||||
|
||||
root.innerHTML = String(html`
|
||||
<section class="rank">
|
||||
<div class="rank-tools">
|
||||
<input type="search" name="q" value="${prefs.q}" placeholder="Search school, city, country" aria-label="Search">
|
||||
<div class="rank-filters">
|
||||
<select name="region" aria-label="Region">
|
||||
<option value="">All regions</option>
|
||||
${regions.map((r) => html`<option value="${r}" ${prefs.region === r ? 'selected' : ''}>${r}</option>`)}
|
||||
</select>
|
||||
<select name="scope" aria-label="Agreement type">
|
||||
<option value="">All types</option>
|
||||
<option value="FEL" ${prefs.scope === 'FEL' ? 'selected' : ''}>FEL agreements</option>
|
||||
<option value="CTU-wide" ${prefs.scope === 'CTU-wide' ? 'selected' : ''}>CTU-wide</option>
|
||||
</select>
|
||||
<select name="sort" aria-label="Sort by">
|
||||
${Object.entries(SORTS).map(([k, v]) => html`<option value="${k}" ${prefs.sort === k ? 'selected' : ''}>${v.label}</option>`)}
|
||||
</select>
|
||||
</div>
|
||||
<label class="check"><input type="checkbox" name="dropped" ${prefs.dropped ? 'checked' : ''}> Show dropped (${droppedCount})</label>
|
||||
</div>
|
||||
<p class="muted small">${rows.length} schools · ${app.state.matches.length} picks so far</p>
|
||||
<ol class="rank-list">
|
||||
${rows.map(({ s, st }) => {
|
||||
const n = netCost(s, app.settings, app.data);
|
||||
const lang = languageFit(s, app.settings.languages);
|
||||
const ai = s.research?.aiRobotics?.academic?.score;
|
||||
return html`
|
||||
<li>
|
||||
<button type="button" class="rank-row ${st.dropped ? 'dropped' : ''}" data-action="open" data-slug="${s.slug}">
|
||||
<span class="pos">${st.dropped ? '–' : position.get(s.code)}</span>
|
||||
<span class="flag" aria-hidden="true">${s.flag}</span>
|
||||
<span class="rmain">
|
||||
<span class="rname">${shortName(s)}</span>
|
||||
<span class="rmeta">${place(s)}${lang.status === 'fail' ? html` · <em class="tone-fail">${lang.text}</em>` : ''}</span>
|
||||
<span class="rchips">
|
||||
${ai != null ? html`<span class="chip">AI ${ai}</span>` : html`<span class="chip warn">pending</span>`}
|
||||
${n ? html`<span class="chip">${moneyRange([n.lo, n.hi], app.settings, app.data, { compact: true })}</span>` : ''}
|
||||
${s.agreements.some((a) => a.scope === 'FEL') ? html`<span class="chip">FEL</span>` : html`<span class="chip">CTU</span>`}
|
||||
</span>
|
||||
</span>
|
||||
<span class="rscore ${st.games < PROVISIONAL_GAMES ? 'provisional' : ''}">
|
||||
${Math.round(st.rating)}<small>${st.wins}–${st.losses}${st.draws ? `–${st.draws}` : ''}</small>
|
||||
</span>
|
||||
</button>
|
||||
${st.dropped ? html`<button type="button" class="link restore" data-action="restore" data-code="${s.code}">Restore</button>` : ''}
|
||||
</li>`;
|
||||
})}
|
||||
</ol>
|
||||
</section>`);
|
||||
|
||||
const save = (patch) => { local.set('rank', { ...prefs, ...patch }); render(root, app); };
|
||||
root.onclick = (e) => {
|
||||
const t = e.target.closest('[data-action]');
|
||||
if (!t) return;
|
||||
if (t.dataset.action === 'open') app.navigate(`#/school/${t.dataset.slug}`);
|
||||
if (t.dataset.action === 'restore') app.restore(t.dataset.code);
|
||||
};
|
||||
root.onchange = (e) => {
|
||||
const el = e.target;
|
||||
if (el.name === 'dropped') save({ dropped: el.checked });
|
||||
else if (['region', 'scope', 'sort'].includes(el.name)) save({ [el.name]: el.value });
|
||||
};
|
||||
let typing;
|
||||
root.oninput = (e) => {
|
||||
if (e.target.name !== 'q') return;
|
||||
clearTimeout(typing);
|
||||
const value = e.target.value;
|
||||
typing = setTimeout(() => {
|
||||
save({ q: value });
|
||||
const input = root.querySelector('input[name="q"]');
|
||||
input.focus();
|
||||
input.setSelectionRange(value.length, value.length);
|
||||
}, 250);
|
||||
};
|
||||
}
|
||||
|
||||
Loading…
Add table
Add a link
Reference in a new issue