| 1 | import { Suspense } from "react"; |
| 2 | import { RepositoryContents } |
| 3 | import { RepositoryEmptyState } |
| 4 | import { |
| 5 | RepositoryReadme, |
| 6 | RepositoryReadmeSkeleton, |
| 7 | } from "@/components/repositories/repository-readme"; |
| 8 | import { createServerClient } |
| 9 | import { API_URL, sshCloneUrlFor |
| 10 | |
| 11 | export default async function |
| 12 | params, |
| 13 | }: PageProps< |
| 14 | const { username, |
| 15 | |
| 16 | const client = |
| 17 | const contents = |
| 18 | "/api/repositories/{username}/{slug}/contents", |
| 19 | { params: { path: |
| 20 | ); |
| 21 | |
| 22 | if (!contents.data |
| 23 | return ( |
| 24 | <div className="flex flex-col items-center gap-3 rounded-lg border border-dashed py-16 text-center |
| 25 | <p className="text-sm font-medium |
| 26 | <p className="max-w-sm text-sm text-muted-foreground |
| 27 | Try refreshing the page. |
| 28 | </p> |
| 29 | </div> |
| 30 | ); |
| 31 | } |
| 32 | |
| 33 | // nothing pushed yet: no tip commit, so there is no tree to list either |
| 34 | if (contents.data |
| 35 | return ( |
| 36 | <RepositoryEmptyState |
| 37 | cloneUrl={`${API_URL |
| 38 | sshCloneUrl={sshCloneUrlFor(username |
| 39 | defaultBranch={ |
| 40 | contents.data.ref |
| 41 | } |
| 42 | /> |
| 43 | ); |
| 44 | } |
| 45 | |
| 46 | return ( |
| 47 | <> |
| 48 | <RepositoryContents |
| 49 | contents={contents.data |
| 50 | owner={username} |
| 51 | slug={repo} |
| 52 | /> |
| 53 | <Suspense fallback={ |
| 54 | <Readme username={ |
| 55 | </Suspense> |
| 56 | </> |
| 57 | ); |
| 58 | } |
| 59 | |
| 60 | async function Readme( |
| 61 | const client = |
| 62 | const { data |
| 63 | "/api/repositories/{username}/{slug}/readme", |
| 64 | { params: { path: |
| 65 | ); |
| 66 | |
| 67 | return data ? |
| 68 | <RepositoryReadme readme={ |
| 69 | ) : null; |
| 70 | } |