Skip to content

Commit

Permalink
Convert most TSX pages to Typescript
Browse files Browse the repository at this point in the history
  • Loading branch information
davenquinn committed Jan 21, 2024
1 parent a38ad7a commit 19af62d
Show file tree
Hide file tree
Showing 9 changed files with 33 additions and 69 deletions.
13 changes: 13 additions & 0 deletions src/pages/+Page.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
import h from "@macrostrat/hyper";
import { Link } from "~/renderer/Link";

export function Page() {
return h([
h("h1", "Macrostrat dev"),
h("ul", [
h("li", h(Link, { href: "map" }, "Map")),
h("li", h(Link, { href: "maps" }, "Map index")),
h("li", h(Link, { href: "dev" }, "Dev layers")),
]),
]);
}
20 changes: 0 additions & 20 deletions src/pages/+Page.tsx

This file was deleted.

14 changes: 14 additions & 0 deletions src/pages/_error/+Page.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
export { Page };

import h from "@macrostrat/hyper";

function Page({ is404 }: { is404: boolean }) {
if (is404) {
return h([
h("h1", "404 Page Not Found"),
h("p", "This page could not be found."),
]);
} else {
return h([h("h1", "500 Internal Error"), h("p", "Something went wrong.")]);
}
}
19 changes: 0 additions & 19 deletions src/pages/_error/+Page.tsx

This file was deleted.

14 changes: 0 additions & 14 deletions src/pages/about/+Page.tsx

This file was deleted.

6 changes: 0 additions & 6 deletions src/pages/about/code.css

This file was deleted.

Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
export { render as onRenderClient };

import { FocusStyleManager } from "@blueprintjs/core";
import h from "@macrostrat/hyper";
import { hydrateRoot } from "react-dom/client";
import { PageShell } from "./page-shell";
import type { PageContextClient } from "./types";
Expand All @@ -18,12 +19,7 @@ async function render(pageContext: PageContextClient) {
console.log("Rendering on client");
const root = document.getElementById("app-container");
if (!root) throw new Error("DOM element #react-root not found");
hydrateRoot(
root,
<PageShell pageContext={pageContext}>
<Page {...pageProps} />
</PageShell>
);
hydrateRoot(root, h(PageShell, { pageContext }, h(Page, pageProps)));
}

/* To enable Client-side Routing:
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
export { render as onRenderHtml };
// See https://vike.dev/data-fetching

import h from "@macrostrat/hyper";
import ReactDOMServer from "react-dom/server";
import { dangerouslySkipEscape, escapeInject } from "vike/server";
import { PageShell } from "./page-shell";
Expand All @@ -12,9 +13,7 @@ async function render(pageContext: PageContextServer) {
if (!Page)
throw new Error("render() hook expects pageContext.Page to be defined");
const pageHtml = ReactDOMServer.renderToString(
<PageShell pageContext={pageContext}>
<Page {...pageProps} />
</PageShell>
h(PageShell, { pageContext }, h(Page, pageProps))
);

// See https://vike.dev/head
Expand Down
3 changes: 2 additions & 1 deletion src/renderer/Link.tsx → src/renderer/Link.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import h from "@macrostrat/hyper";
import { usePageContext } from "./page-context";

export function Link(props: {
Expand All @@ -12,5 +13,5 @@ export function Link(props: {
]
.filter(Boolean)
.join(" ");
return <a {...props} className={className} />;
return h("a", { ...props, className });
}

0 comments on commit 19af62d

Please sign in to comment.