diff --git a/apps/forge/src/config/appLinks.ts b/apps/forge/src/config/appLinks.ts index 77ef9ed9..f7357fc5 100644 --- a/apps/forge/src/config/appLinks.ts +++ b/apps/forge/src/config/appLinks.ts @@ -1,10 +1,11 @@ // appLinks.ts import { Apps } from "@/types/app.ts"; +import { appRoutes } from "@/types/common"; export type AppLink = { app: Apps; // Identifier for the app displayName: string; // User-facing name - path?: string; // Path for the link + path?: appRoutes; // Path for the link children?: AppLink[]; // Nested links, specific to the same app index?: number; // Index of the link in the navbar (PER LEVEL) id: string; // Unique identifier for the link @@ -23,7 +24,6 @@ export const appLinks: AppLink[] = [ { app: "Sign In", displayName: "Actions", - path: "/signin/actions", index: 2, id: "signin_actions_root", children: [ diff --git a/apps/forge/src/config/nav.ts b/apps/forge/src/config/nav.ts deleted file mode 100644 index 35ef1c23..00000000 --- a/apps/forge/src/config/nav.ts +++ /dev/null @@ -1,15 +0,0 @@ -import { Apps } from "@/types/app.ts"; - -interface AppNavMapping { - [routeSegment: string]: Apps; -} - -export const appNavMapping: AppNavMapping = { - auth: "Auth", - training: "Training", - "": "Main", - users: "User", - printing: "Printing", - signin: "Sign In", - admin: "Admin", -}; diff --git a/apps/forge/src/hooks/useCurrentApp.ts b/apps/forge/src/hooks/useCurrentApp.ts index 67bfa9f2..76e8bcd8 100644 --- a/apps/forge/src/hooks/useCurrentApp.ts +++ b/apps/forge/src/hooks/useCurrentApp.ts @@ -1,29 +1,16 @@ -import { useState, useEffect } from "react"; -import { useMatchRoute, useRouterState } from "@tanstack/react-router"; import { Apps } from "@/types/app.ts"; -import { appRoutes } from "@/types/common.ts"; -import { appNavMapping } from "@/config/nav.ts"; +import { useMatches } from "@tanstack/react-router"; const useCurrentApp = (): Apps | undefined => { - const [currentApp, setCurrentApp] = useState(undefined); - const matchRoute = useMatchRoute(); + const matchWithTitle = useMatches() + .reverse() + .find((d) => d.staticData.title); - const routerChanged = useRouterState().resolvedLocation.pathname; - - // biome-ignore lint/correctness/useExhaustiveDependencies: Needed to include router state or else this doesn't update quick enough (side effect is it updates too much)> - useEffect(() => { - for (const [routeSegment, app] of Object.entries(appNavMapping)) { - const route = routeSegment as appRoutes; - const match = matchRoute({ to: `/${route}`, fuzzy: true }); - if (match) { - console.log("updating"); - setCurrentApp(app); - return; // Stop the loop once a match is found - } - } - }, [matchRoute, routerChanged]); - - return currentApp; + const title = matchWithTitle?.staticData.title; + if (!title) { + throw new Error("Page has no title. This should have been set in the root directory in a file with the app's name"); + } + return title; }; export default useCurrentApp; diff --git a/apps/forge/src/main.tsx b/apps/forge/src/main.tsx index 96cd0da7..089670ef 100644 --- a/apps/forge/src/main.tsx +++ b/apps/forge/src/main.tsx @@ -15,6 +15,7 @@ import { routeTree } from "@/routeTree.gen.ts"; import { Toaster } from "@ui/components/ui/sonner.tsx"; import posthog from "posthog-js"; import { PersistGate } from "redux-persist/integration/react"; +import { Apps } from "./types/app"; // Begin Router const queryClient = new QueryClient(); @@ -35,6 +36,9 @@ declare module "@tanstack/react-router" { interface Register { router: typeof router; } + interface StaticDataRouteOption { + title?: Apps; + } } function InnerApp() { diff --git a/apps/forge/src/routes/admin.tsx b/apps/forge/src/routes/admin.tsx new file mode 100644 index 00000000..5b4d9472 --- /dev/null +++ b/apps/forge/src/routes/admin.tsx @@ -0,0 +1,5 @@ +import { createFileRoute } from "@tanstack/react-router"; + +export const Route = createFileRoute("/admin")({ + staticData: { title: "Admin" }, +}); diff --git a/apps/forge/src/routes/auth.tsx b/apps/forge/src/routes/auth.tsx new file mode 100644 index 00000000..abe40486 --- /dev/null +++ b/apps/forge/src/routes/auth.tsx @@ -0,0 +1,5 @@ +import { createFileRoute } from "@tanstack/react-router"; + +export const Route = createFileRoute("/auth")({ + staticData: { title: "Auth" }, +}); diff --git a/apps/forge/src/routes/index.tsx b/apps/forge/src/routes/index.tsx index 6466ce14..6fe6d68a 100644 --- a/apps/forge/src/routes/index.tsx +++ b/apps/forge/src/routes/index.tsx @@ -25,4 +25,4 @@ const IndexComponent = () => { ); }; -export const Route = createFileRoute("/")({ component: IndexComponent }); +export const Route = createFileRoute("/")({ component: IndexComponent, staticData: { title: "Main" } }); diff --git a/apps/forge/src/routes/printing.tsx b/apps/forge/src/routes/printing.tsx new file mode 100644 index 00000000..df42a829 --- /dev/null +++ b/apps/forge/src/routes/printing.tsx @@ -0,0 +1,5 @@ +import { createFileRoute } from "@tanstack/react-router"; + +export const Route = createFileRoute("/printing")({ + staticData: { title: "Printing" }, +}); diff --git a/apps/forge/src/routes/signin.tsx b/apps/forge/src/routes/signin.tsx new file mode 100644 index 00000000..3b2cdc7e --- /dev/null +++ b/apps/forge/src/routes/signin.tsx @@ -0,0 +1,5 @@ +import { createFileRoute } from "@tanstack/react-router"; + +export const Route = createFileRoute("/signin")({ + staticData: { title: "Sign In" }, +}); diff --git a/apps/forge/src/routes/socials.tsx b/apps/forge/src/routes/socials.tsx new file mode 100644 index 00000000..4476e9ed --- /dev/null +++ b/apps/forge/src/routes/socials.tsx @@ -0,0 +1,3 @@ +import { createFileRoute } from "@tanstack/react-router"; + +export const Route = createFileRoute("/socials")({ staticData: { title: "Socials" } }); diff --git a/apps/forge/src/routes/training.tsx b/apps/forge/src/routes/training.tsx new file mode 100644 index 00000000..d4d00bcf --- /dev/null +++ b/apps/forge/src/routes/training.tsx @@ -0,0 +1,5 @@ +import { createFileRoute } from "@tanstack/react-router"; + +export const Route = createFileRoute("/training")({ + staticData: { title: "Training" }, +}); diff --git a/apps/forge/src/routes/user.tsx b/apps/forge/src/routes/user.tsx new file mode 100644 index 00000000..8aabdd43 --- /dev/null +++ b/apps/forge/src/routes/user.tsx @@ -0,0 +1,5 @@ +import { createFileRoute } from "@tanstack/react-router"; + +export const Route = createFileRoute("/user")({ + component: () => ({ title: "User" }), +}); diff --git a/apps/forge/src/types/app.ts b/apps/forge/src/types/app.ts index 62c34621..0fc3d648 100644 --- a/apps/forge/src/types/app.ts +++ b/apps/forge/src/types/app.ts @@ -1 +1 @@ -export type Apps = "Main" | "Sign In" | "Printing" | "User" | "Admin" | "Training" | "Auth"; +export type Apps = "Main" | "Sign In" | "Printing" | "User" | "Admin" | "Training" | "Auth" | "Socials";