SPB Git

spb/autoscholar

Public
2.8 KB · 71 lines tsx
1import { listTemplates } from "@autoscholar/core";2import Link from "next/link";3import { CodeBlock } from "@/components/CodeBlock";4import { MarkdownView } from "@/components/MarkdownView";5import { modeLabel } from "@/lib/format";6import { db } from "@/lib/server/db";78export const dynamic = "force-dynamic";910export default async function TemplatesPage({ searchParams }: { searchParams: Promise<{ t?: string }> }) {11  const { t } = await searchParams;12  const templates = await listTemplates(db());13  const cur = templates.find((x) => x.slug === t) ?? templates[0];14  return (15    <div className="space-y-6">16      <header>17        <p className="eyebrow">Starters</p>18        <h1 className="title-2 mt-1">Research instruction templates</h1>19        <p className="muted mt-1 text-sm">20          Discipline presets synced from research/templates. Preview, then prefill the launch form and edit21          before freezing.22        </p>23      </header>24      {templates.length === 0 ? (25        <div className="surface p-8 text-center muted">26          No templates synced yet (the scheduler syncs research/templates at start).27        </div>28      ) : (29        <div className="grid gap-6 lg:grid-cols-12">30          <ul className="space-y-1 lg:col-span-3">31            {templates.map((x) => (32              <li key={x.slug}>33                <Link34                  href={`/admin/templates?t=${x.slug}`}35                  className={`block rounded-md px-2 py-1.5 text-sm no-underline hover:bg-[var(--bg-muted)] ${cur?.slug === x.slug ? "bg-[var(--bg-muted)]" : ""}`}36                >37                  {x.name}38                  <span className="subtle block text-xs">39                    {modeLabel(x.mode)} · v{x.version}40                  </span>41                </Link>42              </li>43            ))}44          </ul>45          {cur && (46            <div className="space-y-3 lg:col-span-9">47              <div className="flex items-center justify-between">48                <h2 className="title-3">{cur.name}</h2>49                <Link href={`/admin/new?template=${cur.slug}`} className="btn btn-primary btn-sm">50                  Use this template51                </Link>52              </div>53              <p className="muted text-sm">{cur.description}</p>54              <details open className="surface p-4">55                <summary className="cursor-pointer text-sm">Preview</summary>56                <div className="mt-3">57                  <MarkdownView markdown={cur.content} />58                </div>59              </details>60              <details className="surface p-4">61                <summary className="cursor-pointer text-sm">Raw</summary>62                <CodeBlock code={cur.content} lang="md" />63              </details>64            </div>65          )}66        </div>67      )}68    </div>69  );70}71
Files · cbf31e64fd1db62a1819edf166ff2d903b6d3510
Menu

Theme