404de06Split into home / problem / about pages; minimal landing with problems listJeremy Magland 1import { useEffect, useState } from "react";
2import { HomePage } from "./pages/HomePage";
3import { AboutPage } from "./pages/AboutPage";
4import { ProblemPage } from "./pages/ProblemPage";
5127df5fastandaccurate: PDE solver benchmarks, laplace-dirichlet-2d with MFS and Nystrom DLP solversJeremy Magland 5
6const REPO_URL = "https://github.com/concept-collection/fastandaccurate";
404de06Split into home / problem / about pages; minimal landing with problems listJeremy Magland 8type Route =
9 | { page: "home" }
10 | { page: "about" }
11 | { page: "problem"; problemId: string };
13function parseRoute(hash: string): Route {
14 const path = hash.replace(/^#/, "");
15 if (path === "/about") return { page: "about" };
16 const m = path.match(/^\/problem\/([a-z0-9-]+)$/);
17 if (m) return { page: "problem", problemId: m[1] };
18 return { page: "home" };
5127df5fastandaccurate: PDE solver benchmarks, laplace-dirichlet-2d with MFS and Nystrom DLP solversJeremy Magland 19}
404de06Split into home / problem / about pages; minimal landing with problems listJeremy Magland 21function useRoute(): Route {
22 const [route, setRoute] = useState<Route>(() => parseRoute(location.hash));
5127df5fastandaccurate: PDE solver benchmarks, laplace-dirichlet-2d with MFS and Nystrom DLP solversJeremy Magland 23 useEffect(() => {
404de06Split into home / problem / about pages; minimal landing with problems listJeremy Magland 24 const onChange = () => {
25 setRoute(parseRoute(location.hash));
26 window.scrollTo(0, 0);
27 };
28 window.addEventListener("hashchange", onChange);
29 return () => window.removeEventListener("hashchange", onChange);
5127df5fastandaccurate: PDE solver benchmarks, laplace-dirichlet-2d with MFS and Nystrom DLP solversJeremy Magland 30 }, []);
404de06Split into home / problem / about pages; minimal landing with problems listJeremy Magland 31 return route;
32}
5127df5fastandaccurate: PDE solver benchmarks, laplace-dirichlet-2d with MFS and Nystrom DLP solversJeremy Magland 33
404de06Split into home / problem / about pages; minimal landing with problems listJeremy Magland 34export function App() {
35 const route = useRoute();
5127df5fastandaccurate: PDE solver benchmarks, laplace-dirichlet-2d with MFS and Nystrom DLP solversJeremy Magland 36
404de06Split into home / problem / about pages; minimal landing with problems listJeremy Magland 37 useEffect(() => {
38 document.title =
39 route.page === "about"
40 ? "About — fastandaccurate"
41 : route.page === "problem"
42 ? `${route.problemId} — fastandaccurate`
43 : "fastandaccurate — PDE solver benchmarks";
44 }, [route]);
5127df5fastandaccurate: PDE solver benchmarks, laplace-dirichlet-2d with MFS and Nystrom DLP solversJeremy Magland 45
46 return (
47 <main>
404de06Split into home / problem / about pages; minimal landing with problems listJeremy Magland 48 {route.page !== "home" && (
49 <nav className="topnav">
50 <a href="#/">fastandaccurate</a>
51 </nav>
5127df5fastandaccurate: PDE solver benchmarks, laplace-dirichlet-2d with MFS and Nystrom DLP solversJeremy Magland 52 )}
404de06Split into home / problem / about pages; minimal landing with problems listJeremy Magland 53 {route.page === "home" && <HomePage />}
54 {route.page === "about" && <AboutPage />}
55 {route.page === "problem" && <ProblemPage problemId={route.problemId} />}
5127df5fastandaccurate: PDE solver benchmarks, laplace-dirichlet-2d with MFS and Nystrom DLP solversJeremy Magland 56 <footer>
404de06Split into home / problem / about pages; minimal landing with problems listJeremy Magland 57 fastandaccurate · <a href="#/about">about</a> ·{" "}
58 <a href={REPO_URL}>source</a> · Apache-2.0 · solvers run via{" "}
59 <a href="https://numbl.org">numbl</a> {__NUMBL_VERSION__}
5127df5fastandaccurate: PDE solver benchmarks, laplace-dirichlet-2d with MFS and Nystrom DLP solversJeremy Magland 60 </footer>
61 </main>
62 );
63}