Skip to content
File

Blob: src/client/server/registry.tsx

typescript101 lines
1import type { ReactElement } from "react";
2 
3import { clientEntrypoints, type ClientEntrypoint } from "@/client/entrypoints";
4import { AccountPage, type AccountPageProps } from "@/client/pages/AccountPage";
5import { AdminPage, type AdminPageProps } from "@/client/pages/AdminPage";
6import { AuthSignInPage, type AuthSignInPageProps } from "@/client/pages/AuthSignInPage";
7import { BlobPage, type BlobPageProps } from "@/client/pages/BlobPage";
8import { CommitPage, type CommitPageProps } from "@/client/pages/CommitPage";
9import { CommitsPage, type CommitsPageProps } from "@/client/pages/CommitsPage";
10import { ErrorPage, type ErrorPageProps } from "@/client/pages/ErrorPage";
11import { HomePage } from "@/client/pages/HomePage";
12import { NotFoundPage } from "@/client/pages/NotFoundPage";
13import { OverviewPage, type OverviewPageProps } from "@/client/pages/OverviewPage";
14import { OwnerPage, type OwnerPageProps } from "@/client/pages/OwnerPage";
15import { TreePage, type TreePageProps } from "@/client/pages/TreePage";
16 
17type ViewDefinition = {
18 kind: "document" | "fragment";
19 title?: string;
20 clientEntrypoints?: ClientEntrypoint[];
21 render: (data: Record<string, unknown>) => ReactElement;
22};
23 
24function renderWithProps<Props extends object>(
25 renderPage: (props: Props) => ReactElement
26): (data: Record<string, unknown>) => ReactElement {
27 return (data) => renderPage(data as Props);
28}
29 
30const 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 
98export function getViewDefinition(name: string): ViewDefinition | undefined {
99 return views[name];
100}