77 lines · 3.6 KBRaw
| 1 | import { LayerCard } from "@refs/design-system"; |
| 2 | import { WarningIcon } from "@refs/design-system/icons"; |
| 3 | import { Avatar, formatDate } from "@refs/design-system"; |
| 4 | import { narrative, parseDecisions } from "@refs/protocol"; |
| 5 | import type { Route } from "./+types/repo-commit"; |
| 6 | import { DecisionView } from "../components/decision-view"; |
| 7 | import { DiffView } from "../components/diff-view"; |
| 8 | import { found, refs, fullName } from "../lib/session"; |
| 9 | |
| 10 | export const meta: Route.MetaFunction = ({ loaderData, params }) => [{ title: loaderData ? `${loaderData.commit.message.split("\n")[0]} · ${fullName(params)} · refs` : `Commit · ${fullName(params)} · refs` }]; |
| 11 | |
| 12 | export async function loader({ params, context }: Route.LoaderArgs) { |
| 13 | const repo = await found(refs(context).repo(fullName(params))); |
| 14 | const commit = await found(repo.commit(params.hash)); |
| 15 | return { repo: repo.summary.name, commit }; |
| 16 | } |
| 17 | |
| 18 | export default function RepoCommit({ loaderData }: Route.ComponentProps) { |
| 19 | const { repo, commit } = loaderData; |
| 20 | const title = commit.message.split("\n")[0]; |
| 21 | const story = narrative(commit.message); |
| 22 | const { decisions, problems } = parseDecisions(commit.message, commit.hash); |
| 23 | const parentLink = (hash: string) => ( |
| 24 | <a key={hash} href={`/${repo}/commit/${hash}`} className="rounded-chip bg-sunken px-1.5 py-0.5 shadow-[inset_0_0_0_1px_var(--hairline)] font-mono text-xs text-ink hover:text-accent-text"> |
| 25 | {hash.slice(0, 7)} |
| 26 | </a> |
| 27 | ); |
| 28 | |
| 29 | return ( |
| 30 | <div className="flex flex-col gap-6"> |
| 31 | <header className="flex flex-col gap-3"> |
| 32 | <h1 className="m-0 max-w-[60ch] text-heading leading-tight font-semibold">{title}</h1> |
| 33 | <div className="flex flex-wrap items-center gap-x-2 gap-y-2 text-compact text-muted"> |
| 34 | <Avatar name={commit.author.name} /> |
| 35 | <span className="font-medium text-ink">{commit.author.name}</span> |
| 36 | <span>committed {formatDate(commit.committedAt)}</span> |
| 37 | <span aria-hidden="true">·</span> |
| 38 | <span className="rounded-chip bg-sunken px-1.5 py-0.5 shadow-[inset_0_0_0_1px_var(--hairline)] font-mono text-xs text-ink">{commit.hash.slice(0, 7)}</span> |
| 39 | <span aria-hidden="true">·</span> |
| 40 | {commit.parents.length ? ( |
| 41 | <span className="flex items-center gap-1.5"> |
| 42 | {commit.parents.length === 1 ? "parent" : "parents"} {commit.parents.map(parentLink)} |
| 43 | </span> |
| 44 | ) : ( |
| 45 | <span>root commit</span> |
| 46 | )} |
| 47 | </div> |
| 48 | {story && <p className="m-0 mt-2 max-w-[72ch] text-base leading-relaxed whitespace-pre-line text-ink">{story}</p>} |
| 49 | </header> |
| 50 | |
| 51 | {(decisions.length > 0 || problems.length > 0) && ( |
| 52 | <section className="flex flex-col gap-3"> |
| 53 | {decisions.length > 0 && ( |
| 54 | <h2 className="m-0 text-callout font-semibold"> |
| 55 | {decisions.length} {decisions.length === 1 ? "decision" : "decisions"} |
| 56 | </h2> |
| 57 | )} |
| 58 | {problems.map((problem, index) => ( |
| 59 | <p key={index} className="m-0 flex items-start gap-1.5 text-compact text-caution"> |
| 60 | <WarningIcon className="mt-0.5 shrink-0" aria-hidden="true" /> |
| 61 | <span>A decision record here could not be read. {problem.message}</span> |
| 62 | </p> |
| 63 | ))} |
| 64 | {decisions.map((record, index) => ( |
| 65 | <LayerCard key={`${record.decisionId}-${index}`}> |
| 66 | <LayerCard.Primary className="p-4"> |
| 67 | <DecisionView record={record} /> |
| 68 | </LayerCard.Primary> |
| 69 | </LayerCard> |
| 70 | ))} |
| 71 | </section> |
| 72 | )} |
| 73 | |
| 74 | <DiffView changes={commit.changes} /> |
| 75 | </div> |
| 76 | ); |
| 77 | } |