| 1 | import { CircleCheck, CircleDot } from "lucide-react"; |
| 2 | import type { Metadata |
| 3 | import { Suspense } |
| 4 | import { notFound, redirect |
| 5 | |
| 6 | import { UserLink } |
| 7 | import { FromNowHoverCard } |
| 8 | import { EditableField } |
| 9 | import { Badge } |
| 10 | import { |
| 11 | ThreadSubscription, |
| 12 | ThreadSubscriptionSkeleton, |
| 13 | } from "@/components/notifications/thread-subscription"; |
| 14 | import { createServerClient } |
| 15 | import { cn } |
| 16 | |
| 17 | export async function generateMetadata |
| 18 | params, |
| 19 | }: LayoutProps< |
| 20 | const { username, |
| 21 | const client = |
| 22 | const { data |
| 23 | "/api/repositories/{username}/{repo}/issues/{number}", |
| 24 | { params: { path: |
| 25 | ); |
| 26 | |
| 27 | const title = |
| 28 | ? `${data.title |
| 29 | : `Issue #${number} |
| 30 | |
| 31 | return { title, |
| 32 | } |
| 33 | |
| 34 | export default async function |
| 35 | params, |
| 36 | children, |
| 37 | }: LayoutProps< |
| 38 | const { username, |
| 39 | |
| 40 | const client = |
| 41 | const issue = |
| 42 | "/api/repositories/{username}/{repo}/issues/{number}", |
| 43 | { params: { path: |
| 44 | ); |
| 45 | |
| 46 | if (issue.response |
| 47 | if (!issue.data |
| 48 | throw new Error( |
| 49 | } |
| 50 | // `#N` always links to `/issues/N`, whichever kind N turns out to be. |
| 51 | if (issue.data |
| 52 | redirect(`/${username |
| 53 | |
| 54 | // Server-computed: the author, or whoever can write to the repository. |
| 55 | const canEdit = |
| 56 | const Icon = |
| 57 | |
| 58 | return ( |
| 59 | <div className="flex flex-col gap-4 |
| 60 | <div className="flex flex-col gap-2 |
| 61 | <EditableField |
| 62 | username={username} |
| 63 | repo={repo} |
| 64 | number={issue.data |
| 65 | noun="issue" |
| 66 | field="title" |
| 67 | value={issue.data |
| 68 | canEdit={canEdit} |
| 69 | > |
| 70 | <h1 className="text-xl font-semibold |
| 71 | {issue.data.title |
| 72 | <span className="font-normal text-muted-foreground |
| 73 | #{issue.data.number |
| 74 | </span> |
| 75 | </h1> |
| 76 | </EditableField> |
| 77 | |
| 78 | <div className="flex flex-wrap items-center gap-2 text-sm text-muted-foreground |
| 79 | <Badge |
| 80 | className={cn( |
| 81 | "gap-1.5 rounded-full capitalize", |
| 82 | issue.data.state |
| 83 | issue.data.state |
| 84 | )} |
| 85 | > |
| 86 | <Icon className=" |
| 87 | {issue.data.state |
| 88 | </Badge> |
| 89 | |
| 90 | <span> |
| 91 | <UserLink username={ |
| 92 | <FromNowHoverCard date={ |
| 93 | </span> |
| 94 | |
| 95 | {issue.data.state |
| 96 | <span> |
| 97 | · closed by {issue.data.closedByUsername |
| 98 | {issue.data.closedAt |
| 99 | <FromNowHoverCard date={ |
| 100 | )} |
| 101 | </span> |
| 102 | )} |
| 103 | |
| 104 | <div className="ml-auto |
| 105 | <Suspense fallback={ |
| 106 | <ThreadSubscription |
| 107 | username={username} |
| 108 | repo={repo} |
| 109 | number={Number(number |
| 110 | /> |
| 111 | </Suspense> |
| 112 | </div> |
| 113 | </div> |
| 114 | </div> |
| 115 | |
| 116 | {children} |
| 117 | </div> |
| 118 | ); |
| 119 | } |