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
210 lines
12 KiB
JavaScript
210 lines
12 KiB
JavaScript
// Everything known about one school: catalog agreements, all research sections with sources,
|
||
// money breakdown for your stay, your notes, and your pick history for it.
|
||
|
||
import { html, bar, extLink, ICONS } from '../ui.js';
|
||
import {
|
||
shortName, fullName, place, languageFit, subjectFit, monthlyGrant, netCost, money, moneyRange, LANG_NAMES,
|
||
} from '../metrics.js';
|
||
|
||
const CONF_LABEL = { high: 'high confidence', medium: 'medium confidence', low: 'low confidence' };
|
||
const conf = (c) => (c ? html`<span class="conf conf-${c}">${CONF_LABEL[c]}</span>` : '');
|
||
const para = (t) => (t ? html`<p>${t}</p>` : '');
|
||
const list = (items, cls = '') => (items?.length ? html`<ul class="${cls}">${items.map((i) => html`<li>${i}</li>`)}</ul>` : '');
|
||
|
||
function scored(label, node, tone = '') {
|
||
if (!node) return '';
|
||
return html`<div class="scored"><div class="scored-head"><span>${label}</span>${bar(node.score, tone)}</div>${para(node.text)}</div>`;
|
||
}
|
||
|
||
function section(title, body, confidence) {
|
||
return html`<section class="dsec"><h2>${title} ${conf(confidence)}</h2>${body}</section>`;
|
||
}
|
||
|
||
function agreementsBlock(s, app) {
|
||
return html`
|
||
<ul class="agreements">
|
||
${s.agreements.map((a) => html`
|
||
<li>
|
||
<div><span class="chip">${a.scope === 'FEL' ? 'FEL agreement' : 'CTU-wide'}</span>
|
||
<b>${a.places == null ? '?' : a.places >= 99 ? 'open' : a.places}</b> place${a.places === 1 ? '' : 's'} ·
|
||
levels ${a.levels.join(' ')}</div>
|
||
<div class="muted small">${a.isced.length ? a.iscedLabels.map((l, i) => `${a.isced[i]} ${l}`).join(' · ') : 'Any subject area'}</div>
|
||
<div class="small">${a.languages.length
|
||
? a.languages.map((l) => html`<span class="lang">${LANG_NAMES[l.lang] ?? l.lang} ${l.level}</span> `)
|
||
: html`<span class="muted">No language listed</span>`}</div>
|
||
${a.factsheet ? html`<div class="small">${extLink(a.factsheet, 'CTU factsheet (CTU login)')}</div>` : ''}
|
||
</li>`)}
|
||
</ul>
|
||
<p class="small">Subject fit: <b class="tone-${subjectFit(s).level}">${subjectFit(s).text}</b> ·
|
||
Language: <b class="tone-${languageFit(s, app.settings.languages).status}">${languageFit(s, app.settings.languages).text}</b></p>`;
|
||
}
|
||
|
||
function moneyBlock(s, app) {
|
||
const r = s.research;
|
||
const g = monthlyGrant(s, app.settings, app.data);
|
||
const n = netCost(s, app.settings, app.data);
|
||
const m = app.settings.stayMonths;
|
||
const country = app.data.countries?.[s.country];
|
||
const range = (x) => moneyRange(x, app.settings, app.data);
|
||
const liv = r?.living;
|
||
return html`
|
||
<dl class="kv">
|
||
<dt>Money from CTU</dt><dd><b>${money(g.eur, app.settings, app.data)}</b>/month · ${s.funding?.label}
|
||
<div class="muted small">${s.funding?.note}</div></dd>
|
||
${r?.fees?.hostFunding?.monthlyEUR ? html`<dt>Host scholarship</dt><dd>${money(r.fees.hostFunding.monthlyEUR, app.settings, app.data)}/month (not guaranteed)
|
||
<div class="muted small">${r.fees.hostFunding.text}</div></dd>` : ''}
|
||
${liv ? html`
|
||
<dt>Living /month</dt><dd><b>${range(liv.totalEUR)}</b>
|
||
<div class="muted small">rent ${range(liv.rentEUR)} · food ${range(liv.foodEUR)} · transport ${range(liv.transportEUR)} · other ${range(liv.otherEUR)}</div></dd>
|
||
<dt>Housing</dt><dd>${liv.housing}</dd>` : ''}
|
||
${r?.fees ? html`<dt>Mandatory fees</dt><dd>${r.fees.mandatoryEUR != null ? money(r.fees.mandatoryEUR, app.settings, app.data) : '?'} per semester
|
||
<div class="muted small">${r.fees.text}</div></dd>` : ''}
|
||
${r?.travel ? html`<dt>Getting there</dt><dd>${r.travel.duration} · <b>${range(r.travel.roundTripEUR)}</b> round trip
|
||
<div class="muted small">${r.travel.text}</div></dd>` : ''}
|
||
${country?.visa ? html`<dt>Visa</dt><dd>${country.visa.required ? `${country.visa.type || 'Required'} · ${country.visa.costEUR != null ? money(country.visa.costEUR, app.settings, app.data) : 'cost unknown'}` : 'Not needed'}
|
||
<div class="muted small">${country.visa.text}</div></dd>` : ''}
|
||
${n ? html`<dt>Out of pocket (${m} months)</dt><dd><b>${range([n.lo, n.hi])}</b>
|
||
<div class="muted small">living ${range(n.parts.living)} + travel ${range(n.parts.travel)} + visa ${money(n.parts.visa, app.settings, app.data)}
|
||
+ fees ${money(n.parts.fees, app.settings, app.data)} − money received ${money(n.parts.grant, app.settings, app.data)}</div></dd>` : ''}
|
||
</dl>
|
||
${liv ? para(liv.text) : ''}`;
|
||
}
|
||
|
||
function safetyBlock(s, app) {
|
||
const r = s.research;
|
||
const c = app.data.countries?.[s.country];
|
||
return html`
|
||
${r ? scored('City safety', { score: r.safety.score, text: r.safety.text }) : ''}
|
||
${r ? html`<p class="small"><b>Hazards:</b> ${r.safety.hazards}</p>` : ''}
|
||
${c ? html`
|
||
${scored('Country stability', { score: c.stabilityScore, text: c.text })}
|
||
<p class="small">World Bank political stability: ${c.wgiPoliticalStability?.percentile ?? '?'}th percentile (${c.wgiPoliticalStability?.year}) ·
|
||
Global Peace Index #${c.gpi?.rank ?? '?'} (${c.gpi?.year})</p>
|
||
<p class="small"><b>Czech MFA:</b> <span class="advisory adv-${c.mfaAdvisory?.level}">${c.mfaAdvisory?.level}</span> ${c.mfaAdvisory?.text}</p>
|
||
<p class="small"><b>Health insurance:</b> ${c.health?.text}</p>` : ''}`;
|
||
}
|
||
|
||
export function render(root, app, slug) {
|
||
const s = app.bySlug.get(slug);
|
||
if (!s) {
|
||
root.innerHTML = String(html`<section class="empty"><h2>Unknown school</h2><a class="btn" href="#/rank">Back to the ranking</a></section>`);
|
||
return;
|
||
}
|
||
const r = s.research;
|
||
const st = app.state.stats.get(s.code);
|
||
const rank = app.rankOf(s.code);
|
||
const note = app.notes[s.code]?.text ?? '';
|
||
const history = [...st.history].reverse().slice(0, 30);
|
||
|
||
root.innerHTML = String(html`
|
||
<article class="detail">
|
||
<button type="button" class="back" data-action="back">${ICONS.back} Back</button>
|
||
<header class="dhead">
|
||
<div class="dflag" aria-hidden="true">${s.flag}</div>
|
||
<h1>${fullName(s)}</h1>
|
||
<p class="muted">${shortName(s) !== fullName(s) ? `${shortName(s)} · ` : ''}${place(s)} · ${s.code}</p>
|
||
<p class="dstats">
|
||
<b>${Math.round(st.rating)}</b> Elo ${rank && st.games ? `· #${rank}` : ''} · ${st.games} games (${st.wins}W ${st.losses}L ${st.draws}D)
|
||
${st.dropped ? html`<span class="chip warn">dropped</span>` : ''}
|
||
</p>
|
||
<div class="dactions">
|
||
${st.dropped
|
||
? html`<button type="button" class="btn" data-action="restore">Restore to the race</button>`
|
||
: html`<button type="button" class="btn" data-action="duel">Compare it now</button>
|
||
<button type="button" class="btn ghost" data-action="drop">Drop</button>`}
|
||
${s.web ? extLink(s.web, 'Website') : ''} ${s.qs ? extLink(s.qs, 'QS') : ''}
|
||
${extLink(`https://www.openstreetmap.org/?mlat=${s.lat}&mlon=${s.lon}#map=12/${s.lat}/${s.lon}`, 'Map')}
|
||
</div>
|
||
</header>
|
||
|
||
${r ? html`
|
||
<p class="dsummary">${r.summary}</p>
|
||
<div class="hlwo">${list(r.highlights, 'hl-list')}${list(r.watchouts, 'wo-list')}</div>` : html`
|
||
<p class="notice">Research for this school is still pending. You can still compare it using the catalog data.</p>`}
|
||
|
||
${section('Agreements', agreementsBlock(s, app))}
|
||
|
||
${r ? html`
|
||
${section('AI & robotics', html`
|
||
${scored('Research', r.aiRobotics.academic)}
|
||
${scored('Hands-on', r.aiRobotics.practical)}
|
||
${scored('Course access for you', r.aiRobotics.access)}
|
||
<p class="small">${Object.entries(r.aiRobotics.rankings).filter(([, v]) => v).map(([k, v]) => html`<span class="chip">${({ qsWorld: 'QS', qsCS: 'QS CS', csrankings: 'CSRankings', other: '' })[k]} ${v}</span> `)}</p>
|
||
${r.aiRobotics.labs.length ? html`<h3>Labs & groups</h3>${list(r.aiRobotics.labs)}` : ''}
|
||
${r.aiRobotics.courses.length ? html`<h3>Relevant English courses</h3>${list(r.aiRobotics.courses)}` : ''}
|
||
${r.aiRobotics.teams.length ? html`<h3>Student teams</h3>${list(r.aiRobotics.teams)}` : ''}`, r.confidence.aiRobotics)}
|
||
|
||
${section('Money', moneyBlock(s, app), r.confidence.living)}
|
||
|
||
${section('Language', html`
|
||
<dl class="kv">
|
||
<dt>Teaching</dt><dd>${r.language.teaching}</dd>
|
||
<dt>Proof needed</dt><dd>${r.language.proof}</dd>
|
||
<dt>Local language in daily life</dt><dd>${bar(r.language.localNeed)} <span class="muted small">(10 = essential)</span></dd>
|
||
</dl>${para(r.language.text)}`, r.confidence.language)}
|
||
|
||
${section('Social life & solitude', html`
|
||
${scored('Social', r.social)}
|
||
<p class="small">${r.social.esn ? html`<b>ESN/buddy:</b> ${r.social.esn}` : ''}${r.social.internationals ? html` · <b>Internationals:</b> ${r.social.internationals}` : ''}</p>
|
||
${scored('Calm & solitude', r.solitude)}`, r.confidence.social)}
|
||
|
||
${section('Nature', html`
|
||
${scored('Climbing', r.nature.climbing)}
|
||
${scored('Hiking', r.nature.hiking)}
|
||
${scored('Ocean', r.nature.ocean)}
|
||
${scored('Skiing', r.nature.skiing)}
|
||
<p class="small"><b>Climate (Sep–Feb):</b> ${r.nature.climate}</p>`, r.confidence.nature)}
|
||
` : ''}
|
||
|
||
${section('Safety & stability', safetyBlock(s, app), r?.confidence?.safety)}
|
||
|
||
${r ? html`
|
||
${section('Calendar & application', html`
|
||
<dl class="kv">
|
||
<dt>Term</dt><dd>${r.calendar.term}</dd>
|
||
<dt>Fit with CTU winter</dt><dd><b class="tone-${r.calendar.fit}">${r.calendar.fit}</b> · full year: ${r.calendar.fullYear}</dd>
|
||
<dt>Host deadline</dt><dd>${r.application.nominationDeadline ?? 'unknown'}</dd>
|
||
</dl>${para(r.calendar.text)}${para(r.application.text)}`, r.confidence.calendar)}
|
||
|
||
${section('Sources', html`
|
||
<ol class="sources">${r.sources.map((src) => html`<li>${extLink(src.url, src.label)}</li>`)}</ol>
|
||
<p class="muted small">Researched ${r.researchedAt} · overall ${CONF_LABEL[r.confidence.overall]}. Check money and language rules officially before applying.</p>`)}
|
||
` : ''}
|
||
|
||
${section('My notes', html`
|
||
<textarea name="note" rows="4" maxlength="5000" placeholder="Your thoughts, questions to ask, people to contact…">${note}</textarea>
|
||
<p class="muted small" data-note-status>${note ? 'Saved' : 'Saved automatically'}</p>`)}
|
||
|
||
${history.length ? section('My picks', html`
|
||
<ul class="history">${history.map((m) => {
|
||
const meA = m.a === s.code;
|
||
const other = app.byCode.get(meA ? m.b : m.a);
|
||
const delta = meA ? m.da : m.db;
|
||
const outcome = m.r === 'draw' ? 'tied with' : (m.r === 'a') === meA ? 'beat' : 'lost to';
|
||
return html`<li><span class="${delta >= 0 ? 'up' : 'down'}">${delta >= 0 ? '+' : ''}${Math.round(delta)}</span> ${outcome} ${shortName(other)}</li>`;
|
||
})}</ul>`) : ''}
|
||
</article>`);
|
||
|
||
root.onclick = (e) => {
|
||
const t = e.target.closest('[data-action]');
|
||
if (!t) return;
|
||
const action = t.dataset.action;
|
||
if (action === 'back') app.back();
|
||
else if (action === 'drop') app.drop(s.code);
|
||
else if (action === 'restore') app.restore(s.code);
|
||
else if (action === 'duel') app.duelWith(s.code);
|
||
};
|
||
const textarea = root.querySelector('textarea[name="note"]');
|
||
const status = root.querySelector('[data-note-status]');
|
||
let timer;
|
||
const save = () => {
|
||
clearTimeout(timer);
|
||
if (textarea.value === (app.notes[s.code]?.text ?? '')) return;
|
||
status.textContent = 'Saving…';
|
||
app.saveNote(s.code, textarea.value)
|
||
.then(() => { status.textContent = 'Saved'; })
|
||
.catch(() => { status.textContent = 'Not saved: offline? It will retry when you leave the field.'; });
|
||
};
|
||
textarea.addEventListener('input', () => { status.textContent = 'Editing…'; clearTimeout(timer); timer = setTimeout(save, 1200); });
|
||
textarea.addEventListener('blur', save);
|
||
}
|