diff --git a/src/app/(authed)/(project-doc)/[...slug]/layout.tsx b/src/app/(authed)/(project-doc)/[...slug]/layout.tsx index 62f1ab7e..3d0122bc 100644 --- a/src/app/(authed)/(project-doc)/[...slug]/layout.tsx +++ b/src/app/(authed)/(project-doc)/[...slug]/layout.tsx @@ -1,47 +1,33 @@ "use client" +import { useContext } from "react" import { Box, Stack } from "@mui/material" import { useTheme } from "@mui/material/styles" import TrailingToolbarItem from "@/features/projects/view/toolbar/TrailingToolbarItem" import MobileToolbar from "@/features/projects/view/toolbar/MobileToolbar" import { useProjectSelection } from "@/features/projects/data" -import NotFound from "@/features/projects/view/NotFound" -import dynamic from "next/dynamic" +import { ProjectsContext } from "@/common" import SecondaryHeaderPlaceholder from "@/features/sidebar/view/SecondarySplitHeaderPlaceholder" - -const SecondarySplitHeader = dynamic(() => import("@/features/sidebar/view/SecondarySplitHeader"), - { - loading: () => , - ssr: false, - } -) +import SecondarySplitHeader from "@/features/sidebar/view/SecondarySplitHeader" export default function Page({ children }: { children: React.ReactNode }) { + const { cached } = useContext(ProjectsContext) const { project } = useProjectSelection() const theme = useTheme() return ( - {!project && - <> - - - -
- -
- - } - {project && - <> + <> + {project && }> - -
- {children} -
- - } + } + {!project && cached && } + +
+ {children} +
+
) } \ No newline at end of file diff --git a/src/app/(authed)/(project-doc)/[...slug]/page.tsx b/src/app/(authed)/(project-doc)/[...slug]/page.tsx index 7e2635e4..bb50392c 100644 --- a/src/app/(authed)/(project-doc)/[...slug]/page.tsx +++ b/src/app/(authed)/(project-doc)/[...slug]/page.tsx @@ -1,12 +1,15 @@ "use client" -import { useEffect } from "react" +import { useEffect, useContext } from "react" import ErrorMessage from "@/common/ui/ErrorMessage" import { updateWindowTitle } from "@/features/projects/domain" import { useProjectSelection } from "@/features/projects/data" import Documentation from "@/features/projects/view/Documentation" +import NotFound from "@/features/projects/view/NotFound" +import { ProjectsContext } from "@/common" export default function Page() { + const { cached } = useContext(ProjectsContext) const { project, version, specification, navigateToSelectionIfNeeded } = useProjectSelection() // Ensure the URL reflects the current selection of project, version, and specification. useEffect(() => { @@ -28,12 +31,13 @@ export default function Page() { {project && version && specification && } - {project && !version && + {project && !version && !cached && } - {project && !specification && + {project && !specification && !cached && } + {!project && !cached && } ) } diff --git a/src/common/context/ProjectsContext.ts b/src/common/context/ProjectsContext.ts index c5484722..ccd71812 100644 --- a/src/common/context/ProjectsContext.ts +++ b/src/common/context/ProjectsContext.ts @@ -6,11 +6,13 @@ import { Project } from "@/features/projects/domain" export const SidebarTogglableContext = createContext(true) type ProjectsContextValue = { + cached: boolean, projects: Project[], setProjects: (projects: Project[]) => void } export const ProjectsContext = createContext({ + cached: true, projects: [], setProjects: () => {} }) diff --git a/src/features/projects/view/ProjectsContextProvider.tsx b/src/features/projects/view/ProjectsContextProvider.tsx index cd3725e9..7eab84ae 100644 --- a/src/features/projects/view/ProjectsContextProvider.tsx +++ b/src/features/projects/view/ProjectsContextProvider.tsx @@ -11,9 +11,18 @@ const ProjectsContextProvider = ({ initialProjects?: Project[], children?: React.ReactNode }) => { + const [cached, setCached] = useState(true) const [projects, setProjects] = useState(initialProjects || []) + const setProjectsAndCached = (projects: Project[]) => { + setProjects(projects) + setCached(false) + } return ( - + {children} )