All files / app-leaderboard/src/pages chartset.ts

100% Statements 8/8
75% Branches 3/4
100% Functions 1/1
100% Lines 7/7

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                  2x 2x 2x       2x 1x 1x 1x                                            
import { html, renderHTML } from '@be-music/service-web-theme/server';
import { openDatabase } from '../db/client.ts';
import { ChartsetChartsList } from './components/lists.ts';
import { loadChartset, loadChartsetCharts } from './data.ts';
import { Layout, PageHeader } from './layout.ts';
import { meta, notFound, PAGE_CACHE, pageMessages, type PageContext } from './page.ts';
 
/** A chartset: the charts of one work, the original package's and the add-ons, as BMS Search files them. */
export async function chartsetPage(c: PageContext<'/chartsets/:id'>) {
  const messages = pageMessages(c);
  const db = openDatabase(c.env.DB);
  const [found, charts] = await Promise.all([
    loadChartset(db, c.req.param('id')),
    loadChartsetCharts(db, c.req.param('id')),
  ]);
  if (found === undefined) return notFound(c, 'chartset');
  c.header('cache-control', PAGE_CACHE);
  const t = pageMessages(c).chartset;
  return c.html(
    renderHTML(
      Layout({
        meta: meta(c, found.title, t.description(found.title, charts.length), [
          { label: found.title, kind: 'chartset' },
        ]),
        children: html`${PageHeader({
            title: found.title,
            kind: 'chartset',
            children: html`${found.event !== null ? `${found.event} · ` : ''}${t.charts(charts.length)} ·<a
                class="underline-offset-4 hover:underline"
                href=${`https://bmssearch.net/bmses/${encodeURIComponent(found.id)}`}
                rel="noopener"
                target="_blank"
                >BMS Search</a
              >`,
          })}${ChartsetChartsList({ charts: charts }, messages)}
          <p class="text-muted-foreground text-sm">${t.grouping}</p>`,
      }),
    ),
  );
}