App.tsx

  1import { createRootRoute, createRoute, createRouter, RouterProvider } from "@tanstack/react-router";
  2
  3import { Shell } from "@/components/layout/Shell";
  4import { RepoShell } from "@/lib/repo";
  5import { BugDetailPage } from "@/pages/BugDetailPage";
  6import { BugListPage } from "@/pages/BugListPage";
  7import { CodePage } from "@/pages/CodePage";
  8import { CommitPage } from "@/pages/CommitPage";
  9import { ErrorPage } from "@/pages/ErrorPage";
 10import { IdentitySelectPage } from "@/pages/IdentitySelectPage";
 11import { NewBugPage } from "@/pages/NewBugPage";
 12import { RepoPickerPage } from "@/pages/RepoPickerPage";
 13import { UserProfilePage } from "@/pages/UserProfilePage";
 14
 15// ── Route tree ───────────────────────────────────────────────────────────────
 16
 17const rootRoute = createRootRoute({
 18  component: Shell,
 19  errorComponent: ErrorPage,
 20});
 21
 22const indexRoute = createRoute({
 23  getParentRoute: () => rootRoute,
 24  path: "/",
 25  component: RepoPickerPage,
 26});
 27
 28const authSelectIdentityRoute = createRoute({
 29  getParentRoute: () => rootRoute,
 30  path: "/auth/select-identity",
 31  component: IdentitySelectPage,
 32});
 33
 34const repoRoute = createRoute({
 35  getParentRoute: () => rootRoute,
 36  path: "/$repo",
 37  component: RepoShell,
 38});
 39
 40export type CodePageSearch = {
 41  ref: string;
 42  path: string;
 43  type: "tree" | "blob" | "commits";
 44};
 45
 46const repoIndexRoute = createRoute({
 47  getParentRoute: () => repoRoute,
 48  path: "/",
 49  component: CodePage,
 50  validateSearch: (search: Record<string, unknown>): CodePageSearch => ({
 51    ref: (search.ref as string) ?? "",
 52    path: (search.path as string) ?? "",
 53    type: ["tree", "blob", "commits"].includes(search.type as string)
 54      ? (search.type as CodePageSearch["type"])
 55      : "tree",
 56  }),
 57});
 58
 59const bugListRoute = createRoute({
 60  getParentRoute: () => repoRoute,
 61  path: "/issues",
 62  component: BugListPage,
 63});
 64
 65const newBugRoute = createRoute({
 66  getParentRoute: () => repoRoute,
 67  path: "/issues/new",
 68  component: NewBugPage,
 69});
 70
 71const bugDetailRoute = createRoute({
 72  getParentRoute: () => repoRoute,
 73  path: "/issues/$id",
 74  component: BugDetailPage,
 75});
 76
 77const userProfileRoute = createRoute({
 78  getParentRoute: () => repoRoute,
 79  path: "/user/$id",
 80  component: UserProfilePage,
 81});
 82
 83const commitRoute = createRoute({
 84  getParentRoute: () => repoRoute,
 85  path: "/commit/$hash",
 86  component: CommitPage,
 87});
 88
 89const routeTree = rootRoute.addChildren([
 90  indexRoute,
 91  authSelectIdentityRoute,
 92  repoRoute.addChildren([
 93    repoIndexRoute,
 94    bugListRoute,
 95    newBugRoute,
 96    bugDetailRoute,
 97    userProfileRoute,
 98    commitRoute,
 99  ]),
100]);
101
102// ── Router instance ──────────────────────────────────────────────────────────
103
104const router = createRouter({ routeTree });
105
106declare module "@tanstack/react-router" {
107  interface Register {
108    router: typeof router;
109  }
110}
111
112export function App() {
113  return <RouterProvider router={router} />;
114}