Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
40 changes: 13 additions & 27 deletions src/app/(authed)/(project-doc)/[...slug]/layout.tsx
Original file line number Diff line number Diff line change
@@ -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: () => <SecondaryHeaderPlaceholder />,
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 (
<Stack sx={{ height: "100%" }}>
{!project &&
<>
<SecondarySplitHeader>
<TrailingToolbarItem/>
</SecondarySplitHeader>
<main style={{ flexGrow: "1", overflowY: "auto" }}>
<NotFound />
</main>
</>
}
{project &&
<>
<>
{project &&
<SecondarySplitHeader mobileToolbar={<MobileToolbar/>}>
<TrailingToolbarItem/>
</SecondarySplitHeader>
<Box sx={{ height: "0.5px", background: theme.palette.divider }} />
<main style={{ flexGrow: "1", overflowY: "auto" }}>
{children}
</main>
</>
}
}
{!project && cached && <SecondaryHeaderPlaceholder/>}
<Box sx={{ height: "0.5px", background: theme.palette.divider }} />
<main style={{ flexGrow: "1", overflowY: "auto" }}>
{children}
</main>
</>
</Stack>
)
}
10 changes: 7 additions & 3 deletions src/app/(authed)/(project-doc)/[...slug]/page.tsx
Original file line number Diff line number Diff line change
@@ -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(() => {
Expand All @@ -28,12 +31,13 @@ export default function Page() {
{project && version && specification &&
<Documentation url={specification.url} />
}
{project && !version &&
{project && !version && !cached &&
<ErrorMessage text="The selected branch or tag was not found."/>
}
{project && !specification &&
{project && !specification && !cached &&
<ErrorMessage text="The selected specification was not found."/>
}
{!project && !cached && <NotFound/>}
</>
)
}
2 changes: 2 additions & 0 deletions src/common/context/ProjectsContext.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,11 +6,13 @@ import { Project } from "@/features/projects/domain"
export const SidebarTogglableContext = createContext<boolean>(true)

type ProjectsContextValue = {
cached: boolean,
projects: Project[],
setProjects: (projects: Project[]) => void
}

export const ProjectsContext = createContext<ProjectsContextValue>({
cached: true,
projects: [],
setProjects: () => {}
})
11 changes: 10 additions & 1 deletion src/features/projects/view/ProjectsContextProvider.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -11,9 +11,18 @@ const ProjectsContextProvider = ({
initialProjects?: Project[],
children?: React.ReactNode
}) => {
const [cached, setCached] = useState<boolean>(true)
const [projects, setProjects] = useState<Project[]>(initialProjects || [])
const setProjectsAndCached = (projects: Project[]) => {
setProjects(projects)
setCached(false)
}
return (
<ProjectsContext.Provider value={{ projects, setProjects }}>
<ProjectsContext.Provider value={{
cached,
projects,
setProjects: setProjectsAndCached
}}>
{children}
</ProjectsContext.Provider>
)
Expand Down