| 1 | import Link from "next/link"; |
| 2 | import { formatDistanceToNow } |
| 3 | import { |
| 4 | File, |
| 5 | Folder, |
| 6 | GitCommitHorizontal, |
| 7 | RotateCcwClock, |
| 8 | } from "lucide-react"; |
| 9 | |
| 10 | import { cn } |
| 11 | |
| 12 | import type { components |
| 13 | import { FromNowHoverCard } |
| 14 | |
| 15 | type Contents |
| 16 | type TreeEntry |
| 17 | |
| 18 | function EntryIcon({ type |
| 19 | const Icon = |
| 20 | |
| 21 | return ( |
| 22 | <Icon |
| 23 | className={cn( |
| 24 | "size-4 shrink-0 fill-muted", |
| 25 | type === "blob" |
| 26 | )} |
| 27 | /> |
| 28 | ); |
| 29 | } |
| 30 | |
| 31 | export function RepositoryContents({ |
| 32 | contents, |
| 33 | owner, |
| 34 | slug, |
| 35 | }: { |
| 36 | contents: Contents |
| 37 | owner: string |
| 38 | slug: string |
| 39 | }) { |
| 40 | const branch = |
| 41 | |
| 42 | if (contents.entries |
| 43 | return ( |
| 44 | <div className="flex flex-col items-center gap-3 rounded-lg border border-dashed py-16 text-center |
| 45 | <p className="text-sm font-medium |
| 46 | {contents.path ? |
| 47 | </p> |
| 48 | <p className="max-w-sm text-sm text-muted-foreground |
| 49 | {contents.path |
| 50 | ? `${contents.path |
| 51 | : "Push a commit to see its files here."} |
| 52 | </p> |
| 53 | </div> |
| 54 | ); |
| 55 | } |
| 56 | |
| 57 | return ( |
| 58 | <div className="overflow-hidden rounded-lg border |
| 59 | {contents.commit && |
| 60 | <div className="flex items-center gap-2 border-b bg-muted/40 px-4 py-2.5 text-sm |
| 61 | <GitCommitHorizontal className=" |
| 62 | <span className="min-w-0 truncate font-medium |
| 63 | {contents.commit.subject |
| 64 | </span> |
| 65 | <code className="ml-auto shrink-0 text-xs text-muted-foreground |
| 66 | {contents.commit.sha |
| 67 | </code> |
| 68 | <span className="shrink-0 whitespace-nowrap text-xs text-muted-foreground |
| 69 | {formatDistanceToNow(new Date |
| 70 | addSuffix: true, |
| 71 | })} |
| 72 | </span> |
| 73 | <Link |
| 74 | href={`/${owner |
| 75 | className="flex shrink-0 items-center gap-1.5 whitespace-nowrap text-xs text-muted-foreground hover:text-foreground" |
| 76 | > |
| 77 | <RotateCcwClock className=" |
| 78 | {contents.commitCount} Commits |
| 79 | </Link> |
| 80 | </div> |
| 81 | )} |
| 82 | |
| 83 | <ul className="divide-y |
| 84 | {contents.entries.map |
| 85 | <li |
| 86 | key={entry.oid |
| 87 | className="flex items-center gap-3 justify-between px-4 py-2.5 text-sm hover:bg-muted/40" |
| 88 | > |
| 89 | <div className="flex min-w-0 flex-1 flex-row items-center gap-3 |
| 90 | <EntryIcon type={ |
| 91 | |
| 92 | <Link |
| 93 | href={`/${owner |
| 94 | .split("/") |
| 95 | .map(encodeURIComponent) |
| 96 | .join("/") |
| 97 | className="min-w-0 truncate hover:text-primary hover:underline" |
| 98 | > |
| 99 | {entry.name} |
| 100 | </Link> |
| 101 | </div> |
| 102 | |
| 103 | <div className="flex shrink-0 flex-row items-center gap-3 |
| 104 | <span className="hidden max-w-xs truncate text-xs text-muted-foreground md:block |
| 105 | {entry.lastCommit?.subject |
| 106 | </span> |
| 107 | |
| 108 | <span className="w-28 shrink-0 whitespace-nowrap text-right text-xs text-muted-foreground |
| 109 | {entry.lastCommit && |
| 110 | <FromNowHoverCard date={ |
| 111 | )} |
| 112 | </span> |
| 113 | </div> |
| 114 | </li> |
| 115 | ))} |
| 116 | </ul> |
| 117 | </div> |
| 118 | ); |
| 119 | } |