| 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 | import { ImportBanner } |
| 18 | |
| 19 | export async function generateMetadata |
| 20 | params, |
| 21 | }: LayoutProps< |
| 22 | const { username, |
| 23 | const client = |
| 24 | const { data |
| 25 | params: { path: { |
| 26 | }); |
| 27 | |
| 28 | const title = |
| 29 | const description = |
| 30 | |
| 31 | return { |
| 32 | title, |
| 33 | description, |
| 34 | openGraph: { title, |
| 35 | }; |
| 36 | } |
| 37 | |
| 38 | export default async function |
| 39 | params, |
| 40 | children, |
| 41 | }: LayoutProps< |
| 42 | const { username, |
| 43 | |
| 44 | const [session, |
| 45 | getServerSession(), |
| 46 | createServerClient(), |
| 47 | ]); |
| 48 | |
| 49 | const repository = |
| 50 | params: { path: { |
| 51 | }); |
| 52 | |
| 53 | if (repository.response |
| 54 | if (repository.error |
| 55 | throw new Error( |
| 56 | } |
| 57 | // 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. |
| 58 | if (repository.data |
| 59 | redirect(`/${repository |
| 60 | } |
| 61 | |
| 62 | const [branches, |
| 63 | client.GET("/api/repositories/{username}/{slug}/branches |
| 64 | params: { path: { |
| 65 | }), |
| 66 | client.GET("/api/repositories/{username}/{repo}/pulls |
| 67 | params: { path: { |
| 68 | }), |
| 69 | client.GET("/api/repositories/{username}/{repo}/issues |
| 70 | params: { path: { |
| 71 | }), |
| 72 | session |
| 73 | ? client.GET( |
| 74 | params: { path: { |
| 75 | }) |
| 76 | : null, |
| 77 | client.GET("/api/repositories/{username}/{repo}/import |
| 78 | params: { path: { |
| 79 | }), |
| 80 | ]); |
| 81 | |
| 82 | return ( |
| 83 | <RepositoryFrame |
| 84 | viewer={session?.user |
| 85 | viewerRole={repository.data |
| 86 | username={username} |
| 87 | slug={repository.data |
| 88 | name={repository.data |
| 89 | description={repository.data |
| 90 | visibility={repository.data |
| 91 | defaultBranch={branches.data |
| 92 | branches={branches.data |
| 93 | starCount={repository.data |
| 94 | viewerHasStarred={repository.data |
| 95 | watchLevel={watch?.data |
| 96 | forkCount={repository.data |
| 97 | openPullRequestCount={pulls.data |
| 98 | openIssueCount={issues.data |
| 99 | parent={repository.data |
| 100 | sidebar={ |
| 101 | <> |
| 102 | <RepositoryAbout |
| 103 | username={username} |
| 104 | slug={repository.data |
| 105 | description={repository.data |
| 106 | starCount={repository.data |
| 107 | forkCount={repository.data |
| 108 | /> |
| 109 | |
| 110 | <Suspense fallback={ |
| 111 | <LatestRelease username={ |
| 112 | </Suspense> |
| 113 | |
| 114 | {/* its own fetch: a first-ever language count of a big repository |
| 115 | must not hold up the file listing */} |
| 116 | <Suspense fallback={ |
| 117 | <Languages username={ |
| 118 | </Suspense> |
| 119 | </> |
| 120 | } |
| 121 | > |
| 122 | {imported.data && |
| 123 | <ImportBanner |
| 124 | username={username} |
| 125 | repo={repository.data |
| 126 | viewerRole={repository.data |
| 127 | initial={imported.data |
| 128 | /> |
| 129 | )} |
| 130 | {children} |
| 131 | </RepositoryFrame> |
| 132 | ); |
| 133 | } |
| 134 | |
| 135 | async function Languages( |
| 136 | username, |
| 137 | repo, |
| 138 | }: { |
| 139 | username: string |
| 140 | repo: string |
| 141 | }) { |
| 142 | const client = |
| 143 | const { data |
| 144 | "/api/repositories/{username}/{slug}/languages", |
| 145 | { params: { path: |
| 146 | ); |
| 147 | |
| 148 | return data ? |
| 149 | } |