| 1 | import Link from "next/link"; |
| 2 | import { notFound } |
| 3 | import { GitCommitHorizontal } |
| 4 | |
| 5 | import { CommitVerificationBadge } |
| 6 | import { CursorPagination } |
| 7 | import { createServerClient } |
| 8 | import { FromNowHoverCard } |
| 9 | |
| 10 | const PAGE_SIZE = 20 |
| 11 | |
| 12 | export default async function |
| 13 | params, |
| 14 | searchParams, |
| 15 | }: PageProps< |
| 16 | const { username, |
| 17 | const { cursor |
| 18 | |
| 19 | const client = |
| 20 | |
| 21 | const revision = |
| 22 | |
| 23 | const commits = |
| 24 | "/api/repositories/{username}/{slug}/commits", |
| 25 | { |
| 26 | params: { |
| 27 | path: { username, |
| 28 | query: { |
| 29 | ref: revision, |
| 30 | limit: PAGE_SIZE, |
| 31 | cursor: typeof cursor |
| 32 | }, |
| 33 | }, |
| 34 | }, |
| 35 | ); |
| 36 | |
| 37 | if (commits.response |
| 38 | if (!commits.data |
| 39 | throw new Error( |
| 40 | } |
| 41 | |
| 42 | const { from, |
| 43 | const base = |
| 44 | |
| 45 | return ( |
| 46 | <> |
| 47 | <div className="overflow-hidden rounded-lg border |
| 48 | <div className="flex items-center gap-2 border-b bg-muted/40 px-4 py-2.5 text-sm |
| 49 | <GitCommitHorizontal className=" |
| 50 | <span className="font-medium |
| 51 | <span className="ml-auto text-xs text-muted-foreground |
| 52 | {total === 0 |
| 53 | </span> |
| 54 | </div> |
| 55 | |
| 56 | {commits.data.commits |
| 57 | <p className="py-16 text-center text-sm text-muted-foreground |
| 58 | Nothing has been pushed to {revision} yet. |
| 59 | </p> |
| 60 | ) : ( |
| 61 | <ul className="divide-y |
| 62 | {commits.data.commits |
| 63 | <li |
| 64 | key={commit.sha |
| 65 | className="flex items-center gap-3 px-4 py-2.5 text-sm hover:bg-muted/40" |
| 66 | > |
| 67 | <div className="min-w-0 flex-1 |
| 68 | <Link |
| 69 | href={`/${username |
| 70 | className="truncate font-medium hover:underline" |
| 71 | > |
| 72 | {commit.subject} |
| 73 | </Link> |
| 74 | <p className="truncate text-xs text-muted-foreground |
| 75 | {commit.authorName} committed |
| 76 | <FromNowHoverCard date={ |
| 77 | </p> |
| 78 | </div> |
| 79 | <CommitVerificationBadge verification={ |
| 80 | <Link |
| 81 | className="hover:underline" |
| 82 | href={`/${username |
| 83 | > |
| 84 | <code className="shrink-0 text-xs text-muted-foreground |
| 85 | {commit.sha.slice |
| 86 | </code> |
| 87 | </Link> |
| 88 | </li> |
| 89 | ))} |
| 90 | </ul> |
| 91 | )} |
| 92 | </div> |
| 93 | |
| 94 | <CursorPagination |
| 95 | pathname={base} |
| 96 | cursor={typeof cursor |
| 97 | nextCursor={nextCursor} |
| 98 | /> |
| 99 | </> |
| 100 | ); |
| 101 | } |