import { UNSAFE_PortalProvider } from "@react-aria/overlays"; import { useQueries } from "@tanstack/react-query"; import { NoMatch } from "@thorium/components/NotFound"; import Stars from "@thorium/components/Station/Stars"; import AppContext, { clientId, liveQueryClient, q } from "@thorium/context/AppContext"; import Button from "@thorium/ui/Button"; import { Icon } from "@thorium/ui/Icon"; import "./styles/tailwind.css"; import "@fontsource-variable/outfit"; import { useEffect, useRef } from "react"; import { isRouteErrorResponse, Links, Meta, Outlet, Scripts, ScrollRestoration, type MetaFunction, } from "react-router"; import type { Route } from "./+types/root"; import icon from "./images/logo.svg?url"; export const meta: MetaFunction = () => { return [{ title: "Thorium Nova" }, {}]; }; export const links: Route.LinksFunction = () => { return [{ rel: "icon", href: icon }]; }; export function Layout({ children }: { children: React.ReactNode }) { const container = useRef(null); return ( container.current}>
{children}
); } function Preload() { const preloadOptions = { refetchOnMount: false, refetchOnReconnect: false, refetchOnWindowFocus: false, staleTime: Number.POSITIVE_INFINITY, queryFn: ({ signal, queryKey: [pathKey, input] }: { signal: any; queryKey: any }) => { const path = pathKey.join("."); return liveQueryClient.netRequest({ path, ...input, signal }); }, }; useQueries({ queries: [ { queryKey: q.ship.players.getQueryKey(), ...preloadOptions, }, { queryKey: q.ship.player.getQueryKey({ clientId }), ...preloadOptions }, { queryKey: q.ship.get.getQueryKey({ clientId }), ...preloadOptions }, { queryKey: q.station.get.getQueryKey({ clientId }), ...preloadOptions }, { queryKey: q.client.get.getQueryKey({ clientId }), ...preloadOptions }, { queryKey: q.flight.active.getQueryKey(), ...preloadOptions }, ], }); return null; } export default function Root() { useHttpRedirect(); return ( ); } export function HydrateFallback() { return (

Loading Thorium Nova..

); } export function ErrorBoundary({ error }: { error: Error }) { let message = "Oops!"; let details = "An unexpected error occurred."; let stack: string | undefined; if (isRouteErrorResponse(error)) { if (error.status === 404) { return ; } message = "Error"; details = error.statusText || details; } else if (import.meta.env.DEV && error && error instanceof Error) { details = error.message; stack = error.stack; } return (

{message}

{details}

{stack && (
					{stack}
				
)}
); } function Snapshot() { if (process.env.NODE_ENV === "production") return null; return ( ); } function useHttpRedirect() { useEffect(() => { if (window.location.protocol === "http:") { const url = new URL(window.location.href); const oldPathname = url.pathname; url.protocol = "https:"; url.pathname = "/https"; fetch(url) .then(async (res) => { if (res.ok) { const port = await res.text(); url.pathname = oldPathname; if (port !== "443") { url.port = port; } window.location.assign(url); } }) .catch(() => {}); } }, []); }