File
Blob: src/client/server/registry.tsx
| 1 | import type { ReactElement } from "react"; |
| 2 | |
| 3 | import { clientEntrypoints, type ClientEntrypoint } from "@/client/entrypoints"; |
| 4 | import { AccountPage, type AccountPageProps } from "@/client/pages/AccountPage"; |
| 5 | import { AdminPage, type AdminPageProps } from "@/client/pages/AdminPage"; |
| 6 | import { AuthSignInPage, type AuthSignInPageProps } from "@/client/pages/AuthSignInPage"; |
| 7 | import { BlobPage, type BlobPageProps } from "@/client/pages/BlobPage"; |
| 8 | import { CommitPage, type CommitPageProps } from "@/client/pages/CommitPage"; |
| 9 | import { CommitsPage, type CommitsPageProps } from "@/client/pages/CommitsPage"; |
| 10 | import { ErrorPage, type ErrorPageProps } from "@/client/pages/ErrorPage"; |
| 11 | import { HomePage } from "@/client/pages/HomePage"; |
| 12 | import { NotFoundPage } from "@/client/pages/NotFoundPage"; |
| 13 | import { OverviewPage, type OverviewPageProps } from "@/client/pages/OverviewPage"; |
| 14 | import { OwnerPage, type OwnerPageProps } from "@/client/pages/OwnerPage"; |
| 15 | import { TreePage, type TreePageProps } from "@/client/pages/TreePage"; |
| 16 | |
| 17 | type ViewDefinition = { |
| 18 | kind: "document" | "fragment"; |
| 19 | title?: string; |
| 20 | clientEntrypoints?: ClientEntrypoint[]; |
| 21 | render: (data: Record<string, unknown>) => ReactElement; |
| 22 | }; |
| 23 | |
| 24 | function renderWithProps<Props extends object>( |
| 25 | renderPage: (props: Props) => ReactElement |
| 26 | ): (data: Record<string, unknown>) => ReactElement { |
| 27 | return (data) => renderPage(data as Props); |
| 28 | } |
| 29 | |
| 30 | const views: Record<string, ViewDefinition> = { |
| 31 | home: { |
| 32 | kind: "document", |
| 33 | title: "git-on-cloudflare", |
| 34 | clientEntrypoints: [clientEntrypoints.shell], |
| 35 | render: () => <HomePage />, |
| 36 | }, |
| 37 | "404": { |
| 38 | kind: "document", |
| 39 | title: "404 · git-on-cloudflare", |
| 40 | clientEntrypoints: [clientEntrypoints.shell], |
| 41 | render: () => <NotFoundPage />, |
| 42 | }, |
| 43 | error: { |
| 44 | kind: "document", |
| 45 | title: "Error · git-on-cloudflare", |
| 46 | clientEntrypoints: [clientEntrypoints.shell], |
| 47 | render: renderWithProps((props: ErrorPageProps) => <ErrorPage {...props} />), |
| 48 | }, |
| 49 | owner: { |
| 50 | kind: "document", |
| 51 | clientEntrypoints: [clientEntrypoints.shell], |
| 52 | render: renderWithProps((props: OwnerPageProps) => <OwnerPage {...props} />), |
| 53 | }, |
| 54 | overview: { |
| 55 | kind: "document", |
| 56 | clientEntrypoints: [clientEntrypoints.shell], |
| 57 | render: renderWithProps((props: OverviewPageProps) => <OverviewPage {...props} />), |
| 58 | }, |
| 59 | tree: { |
| 60 | kind: "document", |
| 61 | clientEntrypoints: [clientEntrypoints.shell, clientEntrypoints.treePage], |
| 62 | render: renderWithProps((props: TreePageProps) => <TreePage {...props} />), |
| 63 | }, |
| 64 | blob: { |
| 65 | kind: "document", |
| 66 | clientEntrypoints: [clientEntrypoints.shell, clientEntrypoints.blobPage], |
| 67 | render: renderWithProps((props: BlobPageProps) => <BlobPage {...props} />), |
| 68 | }, |
| 69 | commit: { |
| 70 | kind: "document", |
| 71 | clientEntrypoints: [clientEntrypoints.shell, clientEntrypoints.commitPage], |
| 72 | render: renderWithProps((props: CommitPageProps) => <CommitPage {...props} />), |
| 73 | }, |
| 74 | commits: { |
| 75 | kind: "document", |
| 76 | clientEntrypoints: [clientEntrypoints.shell, clientEntrypoints.commitsPage], |
| 77 | render: renderWithProps((props: CommitsPageProps) => <CommitsPage {...props} />), |
| 78 | }, |
| 79 | "auth-signin": { |
| 80 | kind: "document", |
| 81 | title: "Sign in · git-on-cloudflare", |
| 82 | clientEntrypoints: [clientEntrypoints.shell], |
| 83 | render: renderWithProps((props: AuthSignInPageProps) => <AuthSignInPage {...props} />), |
| 84 | }, |
| 85 | account: { |
| 86 | kind: "document", |
| 87 | title: "Account · git-on-cloudflare", |
| 88 | clientEntrypoints: [clientEntrypoints.shell, clientEntrypoints.accountPage], |
| 89 | render: renderWithProps((props: AccountPageProps) => <AccountPage {...props} />), |
| 90 | }, |
| 91 | admin: { |
| 92 | kind: "document", |
| 93 | clientEntrypoints: [clientEntrypoints.shell, clientEntrypoints.adminPage], |
| 94 | render: renderWithProps((props: AdminPageProps) => <AdminPage {...props} />), |
| 95 | }, |
| 96 | }; |
| 97 | |
| 98 | export function getViewDefinition(name: string): ViewDefinition | undefined { |
| 99 | return views[name]; |
| 100 | } |