| 1 | import { Users } from "lucide-react"; |
| 2 | import Link from "next/link |
| 3 | import { notFound } |
| 4 | |
| 5 | import { FromNowHoverCard } |
| 6 | import { Avatar, AvatarFallback |
| 7 | import { |
| 8 | Tooltip, |
| 9 | TooltipContent, |
| 10 | TooltipProvider, |
| 11 | TooltipTrigger, |
| 12 | } from "@/components/ui/tooltip"; |
| 13 | import { createServerClient } |
| 14 | |
| 15 | export default async function |
| 16 | params, |
| 17 | }: PageProps< |
| 18 | const { username, |
| 19 | |
| 20 | const client = |
| 21 | const { data |
| 22 | "/api/repositories/{username}/{slug}/contributors", |
| 23 | { params: { path: |
| 24 | ); |
| 25 | |
| 26 | if (!data) |
| 27 | |
| 28 | const top = |
| 29 | |
| 30 | return ( |
| 31 | <div className="flex flex-col gap-4 |
| 32 | <h1 className="flex items-center gap-2 text-lg font-semibold |
| 33 | <Users className=" |
| 34 | Contributors |
| 35 | <span className="text-sm font-normal text-muted-foreground tabular-nums |
| 36 | {data.totalContributors} · |
| 37 | </span> |
| 38 | </h1> |
| 39 | |
| 40 | {data.contributors.length |
| 41 | <p className="rounded-lg border border-dashed py-16 text-center text-sm text-muted-foreground |
| 42 | No commits on this repository yet. |
| 43 | </p> |
| 44 | ) : ( |
| 45 | <TooltipProvider> |
| 46 | <ul className="divide-y rounded-lg border |
| 47 | {data.contributors.map |
| 48 | <li |
| 49 | key={`${contributor |
| 50 | className="flex items-center gap-3 px-4 py-3" |
| 51 | > |
| 52 | <Avatar className=" |
| 53 | <AvatarImage src={ |
| 54 | <AvatarFallback> |
| 55 | {contributor.name.slice |
| 56 | </AvatarFallback> |
| 57 | </Avatar> |
| 58 | |
| 59 | <div className="flex min-w-0 flex-col |
| 60 | {contributor.username ? |
| 61 | <> |
| 62 | <Link |
| 63 | href={`/${contributor |
| 64 | className="truncate text-sm font-medium hover:underline" |
| 65 | > |
| 66 | {contributor.name} |
| 67 | </Link> |
| 68 | <span className="truncate text-xs text-muted-foreground |
| 69 | {contributor.username} |
| 70 | </span> |
| 71 | </> |
| 72 | ) : ( |
| 73 | <> |
| 74 | <span className="truncate text-sm font-medium |
| 75 | {contributor.name} |
| 76 | </span> |
| 77 | <span className="truncate text-xs text-muted-foreground |
| 78 | no Ghost account |
| 79 | </span> |
| 80 | </> |
| 81 | )} |
| 82 | </div> |
| 83 | |
| 84 | <div className="ml-auto flex shrink-0 items-center gap-3 |
| 85 | <Tooltip> |
| 86 | <TooltipTrigger asChild> |
| 87 | <div |
| 88 | className="h-2 w-24 overflow-hidden rounded-full bg-muted" |
| 89 | role="img" |
| 90 | aria-label={`${contributor |
| 91 | > |
| 92 | <div |
| 93 | className="h-full rounded-full bg-emerald-500" |
| 94 | style={{ |
| 95 | width: `${top |
| 96 | }} |
| 97 | /> |
| 98 | </div> |
| 99 | </TooltipTrigger> |
| 100 | <TooltipContent> |
| 101 | {contributor.commits} commits ( |
| 102 | {contributor.percent.toFixed |
| 103 | </TooltipContent> |
| 104 | </Tooltip> |
| 105 | |
| 106 | <span className="w-20 text-right text-xs text-muted-foreground tabular-nums |
| 107 | {contributor.commits}{" |
| 108 | {contributor.commits === |
| 109 | </span> |
| 110 | |
| 111 | <span className="hidden w-28 text-right text-xs text-muted-foreground sm:inline |
| 112 | <FromNowHoverCard date={ |
| 113 | </span> |
| 114 | </div> |
| 115 | </li> |
| 116 | ))} |
| 117 | </ul> |
| 118 | </TooltipProvider> |
| 119 | )} |
| 120 | </div> |
| 121 | ); |
| 122 | } |