diff --git a/apps/cyberstorm-remix/app/root.tsx b/apps/cyberstorm-remix/app/root.tsx index 25c818271..98b6a6879 100644 --- a/apps/cyberstorm-remix/app/root.tsx +++ b/apps/cyberstorm-remix/app/root.tsx @@ -1,7 +1,6 @@ import "./styles/index.css"; import "@thunderstore/cyberstorm-theme"; import { - Await, Links, Meta, MetaFunction, @@ -9,7 +8,6 @@ import { Scripts, ScrollRestoration, ShouldRevalidateFunctionArgs, - UIMatch, isRouteErrorResponse, useLoaderData, useLocation, @@ -18,26 +16,12 @@ import { useRouteLoaderData, } from "react-router"; // import { LinksFunction } from "@remix-run/react/dist/routeModules"; -import { Provider as RadixTooltip } from "@radix-ui/react-tooltip"; -import { LinkLibrary } from "cyberstorm/utils/LinkLibrary"; -import { - AdContainer, - isRecord, - LinkingProvider, - NewBreadCrumbs, - NewBreadCrumbsLink, -} from "@thunderstore/cyberstorm"; import { DapperTs } from "@thunderstore/dapper-ts"; import { CurrentUser } from "@thunderstore/dapper/types"; import { captureRemixErrorBoundaryError, withSentry } from "@sentry/remix"; -import { memo, ReactNode, Suspense, useEffect, useRef } from "react"; -import { useHydrated } from "remix-utils/use-hydrated"; -import Toast from "@thunderstore/cyberstorm/src/newComponents/Toast"; -import { Footer } from "./commonComponents/Footer/Footer"; import { RequestConfig } from "@thunderstore/thunderstore-api"; -import { NavigationWrapper } from "./commonComponents/Navigation/NavigationWrapper"; import { NamespacedStorageManager } from "@thunderstore/ts-api-react"; import { getSessionContext, @@ -51,10 +35,20 @@ import { } from "cyberstorm/security/publicEnvVariables"; import { StorageManager } from "@thunderstore/ts-api-react/src/storage"; import { Route } from "./+types/root"; +import { LinkingProvider } from "@thunderstore/cyberstorm"; +import { LinkLibrary } from "cyberstorm/utils/LinkLibrary"; +import Toast from "@thunderstore/cyberstorm/src/newComponents/Toast"; +import { TooltipProvider } from "./rootRoute/tooltipProvider"; +import { NavigationWrapper } from "./commonComponents/Navigation/NavigationWrapper"; +import { BetaButtonInit } from "./rootRoute/betaButton"; +import { Ads, AdsInit } from "./rootRoute/nitroAds"; +import { Footer } from "./commonComponents/Footer/Footer"; +import { NimbusBreadcrumbs } from "./rootRoute/breadcrumbs"; // REMIX TODO: https://remix.run/docs/en/main/route/links // export const links: LinksFunction = () => [{ rel: "stylesheet", href: styles }]; +/* Declaring window types that are present, because of certain parts of the application */ declare global { interface Window { NIMBUS_PUBLIC_ENV: publicEnvVariablesType; @@ -82,6 +76,7 @@ declare global { } } +/* React router outlet context shape. This shape should be present on all pages. Pages might define additional context for their children */ export type OutletContextShape = { currentUser: CurrentUser | undefined; requestConfig: () => RequestConfig; @@ -99,6 +94,7 @@ export const meta: MetaFunction = () => { ]; }; +/* Loaders start */ export async function loader() { const publicEnvVariables = getPublicEnvVariables([ "VITE_SITE_URL", @@ -174,6 +170,9 @@ export async function clientLoader({ request }: Route.ClientLoaderArgs) { } export type RootLoadersType = typeof loader | typeof clientLoader; +// Force hydration of client loader on the initial page load +clientLoader.hydrate = true; +/* Loaders end */ // We want to force revalidation when session is stale // TODO: Currently when logging in, the revalidation wont be run on the redirect back to the page @@ -202,10 +201,7 @@ export function shouldRevalidate({ return sessionIsStale || defaultShouldRevalidate; } -clientLoader.hydrate = true; - -const adContainerIds = ["right-column-1", "right-column-2", "right-column-3"]; - +// Layout component to provide common UI around all pages export function Layout({ children }: { children: React.ReactNode }) { const data = useLoaderData(); let envVars = undefined; @@ -243,49 +239,6 @@ export function Layout({ children }: { children: React.ReactNode }) { // splitPath.length > 5 && splitPath[1] === "c" && splitPath[3] === "p"; const matches = useMatches(); - const userSettingsPage = matches.find( - (m) => m.id === "settings/user/Settings" - ); - const userSettingsAccountPage = matches.find( - (m) => m.id === "settings/user/Account/Account" - ); - const teamsPage = matches.find((m) => m.id === "settings/teams/Teams"); - const teamSettingsPage = matches.find( - (m) => m.id === "settings/teams/team/teamSettings" - ); - const teamSettingsProfilePage = matches.find( - (m) => m.id === "settings/teams/team/tabs/Profile/Profile" - ); - const teamSettingsMembersPage = matches.find( - (m) => m.id === "settings/teams/team/tabs/Members/Members" - ); - const teamSettingsServiceAccountsPage = matches.find( - (m) => m.id === "settings/teams/team/tabs/ServiceAccounts/ServiceAccounts" - ); - const teamSettingsSettingsPage = matches.find( - (m) => m.id === "settings/teams/team/tabs/Settings/Settings" - ); - const communitiesPage = matches.find( - (m) => m.id === "communities/communities" - ); - const uploadPage = matches.find((m) => m.id === "upload/upload"); - const communityPage = matches.find((m) => m.id === "c/community"); - const packageListingPage = matches.find((m) => m.id === "p/packageListing"); - const packageEditPage = matches.find((m) => m.id === "p/packageEdit"); - const packageDependantsPage = matches.find( - (m) => m.id === "p/dependants/Dependants" - ); - const packageTeamPage = matches.find((m) => m.id === "p/team/Team"); - const packageFormatDocsPage = matches.find( - (m) => m.id === "tools/package-format-docs/packageFormatDocs" - ); - const manifestValidatorPage = matches.find( - (m) => m.id === "tools/manifest-validator/manifestValidator" - ); - const markdownPreviewPage = matches.find( - (m) => m.id === "tools/markdown-preview/markdownPreview" - ); - const shouldShowAds = location.pathname.startsWith("/teams") ? false : location.pathname.startsWith("/settings") @@ -346,161 +299,11 @@ export function Layout({ children }: { children: React.ReactNode }) {
- {/* Breadcrumbs are build progressively */} - - {/* User Settings */} - {userSettingsPage ? ( - userSettingsAccountPage ? ( - - Settings - - ) : ( - - Settings - - ) - ) : null} - {/* User Settings account */} - {userSettingsAccountPage ? ( - - Account - - ) : null} - {/* Teams */} - {teamsPage || teamSettingsPage ? ( - - Teams - - ) : null} - {/* Team settings */} - {teamSettingsPage ? ( - - {teamSettingsPage.params.namespaceId} - - ) : null} - {/* Team Settings Profile */} - {teamSettingsProfilePage ? ( - - Profile - - ) : null} - {/* Team Settings Members */} - {teamSettingsMembersPage ? ( - - Members - - ) : null} - {/* Team Settings Service Accounts */} - {teamSettingsServiceAccountsPage ? ( - - Service Accounts - - ) : null} - {/* Team Settings Settings */} - {teamSettingsSettingsPage ? ( - - Settings - - ) : null} - {/* Upload */} - {uploadPage ? ( - - Upload - - ) : null} - {/* Communities page */} - {communitiesPage || - communityPage || - packageDependantsPage || - packageTeamPage ? ( - communityPage || - packageDependantsPage || - packageTeamPage ? ( - - Communities - - ) : ( - - Communities - - ) - ) : null} - {/* Community page */} - {getCommunityBreadcrumb( - communityPage || - packageListingPage || - packageDependantsPage || - packageTeamPage, - Boolean(packageListingPage) || - Boolean(packageDependantsPage) || - Boolean(packageTeamPage) - )} - {/* Package listing page */} - {getPackageListingBreadcrumb( - packageListingPage, - packageEditPage, - packageDependantsPage - )} - {packageEditPage ? ( - - Edit package - - ) : null} - {packageDependantsPage ? ( - - Dependants - - ) : null} - {packageTeamPage ? ( - - {packageTeamPage.params.namespaceId} - - ) : null} - {packageFormatDocsPage ? ( - - Package Format Docs - - ) : null} - {manifestValidatorPage ? ( - - Manifest Validator - - ) : null} - {markdownPreviewPage ? ( - - Markdown Preview - - ) : null} - + {children}
- {shouldShowAds ? ( -
-
- {adContainerIds.map((cid, k_i) => ( - - ))} -
-
- ) : null} +