| 1 | import type { Metadata } from "next"; |
| 2 | import { notFound, redirect |
| 3 | import { Suspense } |
| 4 | |
| 5 | import { |
| 6 | LatestRelease, |
| 7 | LatestReleaseSkeleton, |
| 8 | } from "@/components/releases/latest-release"; |
| 9 | import { RepositoryAbout } |
| 10 | import { RepositoryFrame } |
| 11 | import { |
| 12 | RepositoryLanguages, |
| 13 | RepositoryLanguagesSkeleton, |
| 14 | } from "@/components/repositories/repository-languages"; |
| 15 | import { createServerClient, getServerSession |
| 16 | |
| 17 | export async function generateMetadata |
| 18 | params, |
| 19 | }: LayoutProps< |
| 20 | const { username, |
| 21 | const client = |
| 22 | const { data |
| 23 | params: { path: { |
| 24 | }); |
| 25 | |
| 26 | const title = |
| 27 | const description = |
| 28 | |
| 29 | return { |
| 30 | title, |
| 31 | description, |
| 32 | openGraph: { title, |
| 33 | }; |
| 34 | } |
| 35 | |
| 36 | export default async function |
| 37 | params, |
| 38 | children, |
| 39 | }: LayoutProps< |
| 40 | const { username, |
| 41 | |
| 42 | const [session, |
| 43 | getServerSession(), |
| 44 | createServerClient(), |
| 45 | ]); |
| 46 | |
| 47 | const repository = |
| 48 | params: { path: { |
| 49 | }); |
| 50 | |
| 51 | if (repository.response |
| 52 | if (repository.error |
| 53 | throw new Error( |
| 54 | } |
| 55 | // ponytail: an old name after a rename or transfer redirects to the repository root, since a layout does not know the rest of the path; a proxy could keep it. |
| 56 | if (repository.data |
| 57 | redirect(`/${repository |
| 58 | } |
| 59 | |
| 60 | const [branches, |
| 61 | client.GET("/api/repositories/{username}/{slug}/branches |
| 62 | params: { path: { |
| 63 | }), |
| 64 | client.GET("/api/repositories/{username}/{repo}/pulls |
| 65 | params: { path: { |
| 66 | }), |
| 67 | client.GET("/api/repositories/{username}/{repo}/issues |
| 68 | params: { path: { |
| 69 | }), |
| 70 | session |
| 71 | ? client.GET( |
| 72 | params: { path: { |
| 73 | }) |
| 74 | : null, |
| 75 | ]); |
| 76 | |
| 77 | return ( |
| 78 | <RepositoryFrame |
| 79 | viewer={session?.user |
| 80 | viewerRole={repository.data |
| 81 | username={username} |
| 82 | slug={repository.data |
| 83 | name={repository.data |
| 84 | description={repository.data |
| 85 | visibility={repository.data |
| 86 | defaultBranch={branches.data |
| 87 | branches={branches.data |
| 88 | starCount={repository.data |
| 89 | viewerHasStarred={repository.data |
| 90 | watchLevel={watch?.data |
| 91 | forkCount={repository.data |
| 92 | openPullRequestCount={pulls.data |
| 93 | openIssueCount={issues.data |
| 94 | parent={repository.data |
| 95 | sidebar={ |
| 96 | <> |
| 97 | <RepositoryAbout |
| 98 | username={username} |
| 99 | slug={repository.data |
| 100 | description={repository.data |
| 101 | starCount={repository.data |
| 102 | forkCount={repository.data |
| 103 | /> |
| 104 | |
| 105 | <Suspense fallback={ |
| 106 | <LatestRelease username={ |
| 107 | </Suspense> |
| 108 | |
| 109 | {/* its own fetch: a first-ever language count of a big repository |
| 110 | must not hold up the file listing */} |
| 111 | <Suspense fallback={ |
| 112 | <Languages username={ |
| 113 | </Suspense> |
| 114 | </> |
| 115 | } |
| 116 | > |
| 117 | {children} |
| 118 | </RepositoryFrame> |
| 119 | ); |
| 120 | } |
| 121 | |
| 122 | async function Languages( |
| 123 | username, |
| 124 | repo, |
| 125 | }: { |
| 126 | username: string |
| 127 | repo: string |
| 128 | }) { |
| 129 | const client = |
| 130 | const { data |
| 131 | "/api/repositories/{username}/{slug}/languages", |
| 132 | { params: { path: |
| 133 | ); |
| 134 | |
| 135 | return data ? |
| 136 | } |