| 1 | import { notFound } from "next/navigation"; |
| 2 | |
| 3 | import { UserLink } |
| 4 | import { CommentBox } |
| 5 | import { EditableField } |
| 6 | import { Timeline } |
| 7 | import { Markdown } |
| 8 | import { |
| 9 | createServerClient, |
| 10 | getServerSession, |
| 11 | getViewerRole, |
| 12 | } from "@/lib/api/server"; |
| 13 | import { atLeast } |
| 14 | |
| 15 | import { AssigneeEditor, LabelEditor |
| 16 | |
| 17 | export default async function |
| 18 | params, |
| 19 | }: PageProps< |
| 20 | const { username, |
| 21 | |
| 22 | const [session, |
| 23 | getServerSession(), |
| 24 | createServerClient(), |
| 25 | getViewerRole(username, repo |
| 26 | ]); |
| 27 | |
| 28 | const path = |
| 29 | const [issue, |
| 30 | client.GET("/api/repositories/{username}/{repo}/issues/{number} |
| 31 | params: { path |
| 32 | }), |
| 33 | client.GET("/api/repositories/{username}/{repo}/issues/{number}/timeline |
| 34 | params: { path |
| 35 | }), |
| 36 | client.GET("/api/repositories/{username}/{repo}/labels |
| 37 | params: { path: { |
| 38 | }), |
| 39 | ]); |
| 40 | |
| 41 | if (issue.response |
| 42 | if (!issue.data |
| 43 | if (timeline.response |
| 44 | |
| 45 | const viewer = |
| 46 | // Server-computed: the author, or whoever can write to the repository. |
| 47 | const canEdit = |
| 48 | // Triage closes, labels and assigns other people's issues without being able to edit them. |
| 49 | const canTriage = |
| 50 | |
| 51 | return ( |
| 52 | <div className="grid gap-4 lg:grid-cols-[minmax(0,1fr)_260px] |
| 53 | <div className="flex min-w-0 flex-col gap-4 |
| 54 | <EditableField |
| 55 | username={username} |
| 56 | repo={repo} |
| 57 | number={Number(number |
| 58 | noun="issue" |
| 59 | field="body" |
| 60 | value={issue.data |
| 61 | canEdit={canEdit} |
| 62 | header={<UserLink |
| 63 | > |
| 64 | {issue.data.body |
| 65 | <Markdown repository={ |
| 66 | {issue.data.body |
| 67 | </Markdown> |
| 68 | ) : ( |
| 69 | <p className="text-muted-foreground |
| 70 | )} |
| 71 | </EditableField> |
| 72 | |
| 73 | <Timeline |
| 74 | username={username} |
| 75 | repo={repo} |
| 76 | number={Number(number |
| 77 | viewer={viewer} |
| 78 | canModerate={atLeast(role |
| 79 | items={timeline.data |
| 80 | noun="issue" |
| 81 | /> |
| 82 | |
| 83 | <CommentBox |
| 84 | username={username} |
| 85 | repo={repo} |
| 86 | number={Number(number |
| 87 | signedIn={Boolean(viewer |
| 88 | state={issue.data |
| 89 | canChangeState={canTriage} |
| 90 | /> |
| 91 | </div> |
| 92 | |
| 93 | <aside className="flex flex-col gap-4 lg:pt-0 |
| 94 | <LabelEditor |
| 95 | username={username} |
| 96 | repo={repo} |
| 97 | number={Number(number |
| 98 | attached={issue.data |
| 99 | available={labels.data |
| 100 | canEdit={canTriage} |
| 101 | canManage={atLeast(role |
| 102 | /> |
| 103 | <AssigneeEditor |
| 104 | username={username} |
| 105 | repo={repo} |
| 106 | number={Number(number |
| 107 | assignees={issue.data |
| 108 | canEdit={canTriage} |
| 109 | /> |
| 110 | </aside> |
| 111 | </div> |
| 112 | ); |
| 113 | } |