/ concept-collection / fastandaccurate
Sign in
concept-collection / fastandaccurate
fastandaccurate / src / app / App.tsx
63 lines · 1.9 KBCodeBlameHistory
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";
6const REPO_URL = "https://github.com/concept-collection/fastandaccurate";
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" };
22 const [route, setRoute] = useState<Route>(() => parseRoute(location.hash));
25 setRoute(parseRoute(location.hash));
26 window.scrollTo(0, 0);
27 };
28 window.addEventListener("hashchange", onChange);
29 return () => window.removeEventListener("hashchange", onChange);
35 const route = useRoute();
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]);
46 return (
47 <main>
49 <nav className="topnav">
50 <a href="#/">fastandaccurate</a>
51 </nav>
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} />}
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__}
61 </main>
62 );
moveopenescclose