Press n or j to go to the next uncovered block, b, p or k for the previous block.
| 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 | 6x 6x 6x 6x 6x 5x 5x 5x 5x 5x 5x 6x 6x 6x 6x 6x 10x | import { html, renderHTML } from '@be-music/service-web-theme/server';
import { openDatabase } from '../db/client.ts';
import { loadCourseDetail } from '../courses/detail.ts';
import { countCoursePlayers, loadCourseRanking } from '../courses/ranking.ts';
import { isOn } from '../http/query.ts';
import { CourseRankingList, CourseStagesList } from './components/course-lists.ts';
import { Details, DistributionCard, Stats } from './components/cards.ts';
import { Filters, LocalTime, SectionHeading, Tag, Toggle } from './components/basics.ts';
import { HelpTip } from './components/help-tip.ts';
import { RULESET_LABELS } from './format.ts';
import { Layout, PageHeader } from './layout.ts';
import {
day,
displayRuleset,
meta,
notFound,
PAGE_CACHE,
pageMessages,
RANKING_LIMIT,
withQuery,
type PageContext,
} from './page.ts';
import { loadCourseStats } from './stats.ts';
/** A course's ranking under the display ruleset, its stages with links to their charts, its figures and details. */
export async function coursePage(c: PageContext<'/courses/:courseFingerprint'>) {
const messages = pageMessages(c);
const db = openDatabase(c.env.DB);
const courseFingerprint = c.req.param('courseFingerprint');
const found = await loadCourseDetail(db, courseFingerprint);
if (found === undefined) return notFound(c, 'course');
const ruleset = displayRuleset(c);
const assisted = isOn(c.req.query('assisted'));
const includeAnonymous = isOn(c.req.query('anonymous'));
const filter = { courseFingerprint, ruleset, assisted, includeAnonymous, playedHereOnly: false };
const [ranking, stats, named] = await Promise.all([
loadCourseRanking(db, filter, { offset: 0, limit: RANKING_LIMIT }),
loadCourseStats(db, filter),
// Players with an account: a course none of them ran stays out of search engines, as a chart not listed yet does.
includeAnonymous ? countCoursePlayers(db, { ...filter, includeAnonymous: false }) : undefined,
]);
const namedPlayers = named ?? ranking.players;
c.header('cache-control', PAGE_CACHE);
const t = pageMessages(c);
const rules = t.rules.name(RULESET_LABELS[ruleset] ?? ruleset);
const kind = t.course.kinds[found.kind] ?? found.kind;
return c.html(
renderHTML(
Layout({
meta: {
...meta(c, found.name, t.course.description(found.name, rules, ranking.players), [
{ label: found.name, kind: 'course' },
]),
noindex: namedPlayers === 0,
},
children: html`${PageHeader({
kind: 'course',
title: found.name,
children: html`${kind} · ${t.course.stages(found.stages.length)} · ${t.count.players(ranking.players)}`,
})}${Stats({
items: [
[t.course.stats.players, stats.players],
[t.course.stats.runs, stats.plays],
[t.course.stats.firstRun, day(stats.firstPlayedAt)],
[t.course.stats.lastRun, day(stats.lastPlayedAt)],
],
})}
<section class="space-y-3" aria-labelledby="ranking">
${SectionHeading({
id: 'ranking',
note: t.count.players(ranking.players),
children: html`<span class="inline-flex items-center gap-0.5"
>${t.course.ranking}${HelpTip(
{ topic: 'rows', label: t.course.ranking, children: html`${t.course.rankingHelp}` },
messages,
)}</span
>`,
})}${Filters({
children: html`${Toggle(
{
help: 'filters',
label: t.filters.assisted,
description: t.filters.assistedHelp,
on: assisted,
href: withQuery(c, 'assisted', assisted ? undefined : '1'),
},
messages,
)}${Toggle(
{
help: 'filters',
label: t.filters.anonymous,
description: t.filters.anonymousHelp,
on: includeAnonymous,
href: withQuery(c, 'anonymous', includeAnonymous ? undefined : '1'),
},
messages,
)}`,
})}${CourseRankingList({ entries: ranking.entries, highlight: c.get('viewer')?.handle }, messages)}
</section>
<section class="space-y-3" aria-labelledby="stages">
${SectionHeading({
id: 'stages',
note: t.course.stages(found.stages.length),
children: html`${t.course.stageList}`,
})}
<p class="text-muted-foreground text-sm">${t.course.stageListLead}</p>
${CourseStagesList({ stages: found.stages }, messages)}
</section>
${DistributionCard(
{
title: t.course.clearLamps,
description: t.course.clearLampsLead(rules),
distribution: stats.lamps,
kind: 'lamp',
},
messages,
)}${Details({
title: t.course.details,
rows: [
[t.course.rows.kind, kind],
[
t.course.rows.constraints,
found.constraints.length === 0
? t.course.noConstraints
: html`<span class="inline-flex flex-wrap gap-1"
>${found.constraints.map((constraint) => Tag({ children: html`${constraint}` }))}</span
>`,
],
[t.course.rows.stages, found.stages.length],
[t.course.rows.fingerprint, html`<span class="font-mono text-xs break-all">${courseFingerprint}</span>`],
[t.course.rows.firstRun, LocalTime({ at: found.createdAt })],
],
})}`,
}),
),
);
}
|