// Commit detail page (/:repo/commit/:hash). Shows commit metadata, full // message, parent links, and changed files with lazy diffs. import { gql } from "@apollo/client"; import { useQuery } from "@apollo/client/react"; import { format } from "date-fns"; import { ArrowLeft, GitCommit } from "lucide-react"; import { Link, useParams, useNavigate } from "react-router"; import { FileDiffView } from "@/components/code/FileDiffView"; import { Skeleton } from "@/components/ui/skeleton"; import { useRepo } from "@/lib/repo"; const COMMIT_QUERY = gql` query CommitPageDetail($repo: String, $hash: String!) { repository(ref: $repo) { commit(hash: $hash) { hash shortHash message fullMessage authorName authorEmail date parents files { nodes { path oldPath status } } } } } `; export function CommitPage() { const { hash } = useParams<{ hash: string }>(); const navigate = useNavigate(); const repo = useRepo(); const { data, loading, error } = useQuery(COMMIT_QUERY, { variables: { repo, hash }, skip: !hash, }); if (loading) return ; if (error) { return (
Failed to load commit: {error.message}
); } const commit = data?.repository?.commit; if (!commit) return null; const date = new Date(commit.date); const files = commit.files?.nodes ?? []; return (

{commit.message}

{commit.fullMessage.includes("\n") && (
            {commit.fullMessage.split("\n").slice(1).join("\n").trim()}
          
)}
{commit.authorName} {commit.authorEmail && <{commit.authorEmail}>} {format(date, "PPP")}
commit {commit.hash} {commit.parents.map((p: string) => ( parent{" "} {p.slice(0, 7)} ))}

{files.length} file{files.length !== 1 ? "s" : ""} changed

{files.length === 0 && (

No file changes.

)} {files.map((file: { path: string; oldPath?: string | null; status: string }) => ( ))}
); } function CommitPageSkeleton() { return (
{Array.from({ length: 5 }).map((_, i) => (
))}
); }