iterate.com / cloud

git clone https://git.iterate.com/repos/cloud

cloud / internal-packages / installer / src / main.tsxmain at aacbc74

import "./styles.css";
import { StrictMode } from "react";
import { createRoot } from "react-dom/client";
import {
  createRootRoute,
  createRoute,
  createRouter,
  Outlet,
  RouterProvider,
} from "@tanstack/react-router";
import { QueryClientProvider } from "@tanstack/react-query";
import { Connected } from "./ConnectedPage.tsx";
import { Deployments, Entering } from "./Deployments.tsx";
import { Erase } from "./ErasePage.tsx";
import { Wizard } from "./Wizard.tsx";
import { track } from "./analytics.ts";
import { loadConfig, queryClient } from "./api.ts";
import { enterWizard } from "./your-deployments.ts";

const rootRoute = createRootRoute({ component: () => <Outlet /> });
const indexRoute = createRoute({
  getParentRoute: () => rootRoute,
  path: "/",
  // the wizard's own start, then "Your deployments" when the account already holds iterate
  loader: enterWizard,
  component: Wizard,
  pendingComponent: Entering,
});
const deploymentsRoute = createRoute({
  getParentRoute: () => rootRoute,
  path: "/deployments",
  component: Deployments,
});
const eraseRoute = createRoute({
  getParentRoute: () => rootRoute,
  path: "/erase",
  component: Erase,
});
// where `iterate chatgpt connect` sends the browser when it is done (ConnectedPage.tsx)
const connectedRoute = createRoute({
  getParentRoute: () => rootRoute,
  path: "/connected",
  component: Connected,
});
const router = createRouter({
  routeTree: rootRoute.addChildren([indexRoute, deploymentsRoute, eraseRoute, connectedRoute]),
});

declare module "@tanstack/react-router" {
  interface Register {
    router: typeof router;
  }
}

// THE SIDEBAR STARTS AS ITS RAIL ON EVERY PAGE (the mark and the account), and is open only for
// as long as the person who opened it stays on that page. The shell reads this cookie when a page
// mounts, and shadcn's sidebar writes "true" into it when somebody opens it: so it is put back at
// the first load and before each page of the Cloud.
const startAsRail = () => {
  document.cookie = "sidebar_state=false; path=/; max-age=31536000";
};
startAsRail();
router.subscribe("onBeforeNavigate", startAsRail);
// a page view for each page of the Cloud, by its path alone (analytics.ts says what is sent)
router.subscribe("onResolved", ({ toLocation }) =>
  track("cloud page viewed", { path: toLocation.pathname }),
);

await loadConfig();
createRoot(document.getElementById("root")!).render(
  <StrictMode>
    <QueryClientProvider client={queryClient}>
      <RouterProvider router={router} />
    </QueryClientProvider>
  </StrictMode>,
);