flagon-io/g1t

public

Where people and agents ship software together. The open-source git platform for the whole job: issues, agents, checks and deploys to the edge.

g1t/apps/sudo/app/root.tsx

82 lines3,399 bytesCodeBlame
1import { isRouteErrorResponse, Links, Meta, Outlet, useRouteLoaderData } from "react-router";
2
3import type { Route } from "./+types/root";
4import "./app.css";
5import displayFont from "@g1t/theme/fonts/bricolage-grotesque-latin.woff2?url";
6import sansFont from "@g1t/theme/fonts/hanken-grotesk-latin.woff2?url";
7import { MobileBar, Sidebar } from "./components/shell";
8import { ButtonLink } from "./components/ui";
9import type { NavCounts } from "./lib/nav";
10import { identity, statusAdmin } from "./lib/services.server";
11import { settle } from "./lib/settle";
12import { requireStaff, zoneContext } from "./lib/staff";
13
14export const links: Route.LinksFunction = () => [
15 { rel: "icon", type: "image/svg+xml", href: "/favicon.svg" },
16 // The faces are served by sudo itself (@g1t/theme); these two are on every page.
17 { rel: "preload", href: sansFont, as: "font", type: "font/woff2", crossOrigin: "anonymous" },
18 { rel: "preload", href: displayFont, as: "font", type: "font/woff2", crossOrigin: "anonymous" },
19];
20
21export const meta: Route.MetaFunction = () => [
22 { title: "sudo · g1t" },
23 { name: "robots", content: "noindex, nofollow" },
24];
25
26export async function loader({ context }: Route.LoaderArgs) {
27 const { email } = requireStaff(context);
28 // The sidebar's counts: a service that does not answer shows none.
29 const [waitlist, incidents] = await Promise.all([settle(identity.waitlistPending()), settle(statusAdmin.openCount())]);
30 const counts: NavCounts = { waitlist: waitlist.ok ? waitlist.value : 0, incidents: incidents.ok ? incidents.value : 0 };
31 // Every page says times in this zone (components/ui.tsx `When`).
32 const { zone, chosen } = context.get(zoneContext);
33 return { email, counts, zone, zoneChosen: chosen };
34}
35
36export function Layout({ children }: { children: React.ReactNode }) {
37 const root = useRouteLoaderData<typeof loader>("root");
38 return (
39 <html lang="en">
40 <head>
41 <meta charSet="utf-8" />
42 <meta name="viewport" content="width=device-width, initial-scale=1" />
43 <meta name="theme-color" content="#0f0f11" />
44 <Meta />
45 <Links />
46 </head>
47 <body className="min-h-screen">
48 <Sidebar email={root?.email} counts={root?.counts} />
49 <MobileBar email={root?.email} counts={root?.counts} />
50 <div className="lg:pl-60">{children}</div>
51 {/* No <Scripts />: sudo ships no JavaScript, and its policy allows none. */}
52 </body>
53 </html>
54 );
55}
56
57export default function App() {
58 return <Outlet />;
59}
60
61export function ErrorBoundary({ error }: Route.ErrorBoundaryProps) {
62 let title = "Something went wrong";
63 let details = "An unexpected error occurred.";
64 if (isRouteErrorResponse(error)) {
65 title = error.status === 404 ? "Not found" : `Error ${error.status}`;
66 details = typeof error.data === "string" && error.data ? error.data : error.statusText || details;
67 } else if (error instanceof Error) {
68 // Staff only: the real reason helps more than a polite one.
69 details = error.message;
70 }
71 return (
72 <main className="mx-auto max-w-xl px-4 py-24 text-center">
73 <h1 className="text-2xl font-semibold tracking-tight">{title}</h1>
74 <p className="mt-3 break-words text-muted">{details}</p>
75 <div className="mt-8">
76 <ButtonLink to="/" variant="quiet">
77 Back to the overview
78 </ButtonLink>
79 </div>
80 </main>
81 );
82}