Skip to content

Commit 720794e

Browse files
committed
Delays error messages until data is refreshed
1 parent e58049b commit 720794e

File tree

4 files changed

+32
-31
lines changed

4 files changed

+32
-31
lines changed
Lines changed: 13 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -1,47 +1,33 @@
11
"use client"
22

3+
import { useContext } from "react"
34
import { Box, Stack } from "@mui/material"
45
import { useTheme } from "@mui/material/styles"
56
import TrailingToolbarItem from "@/features/projects/view/toolbar/TrailingToolbarItem"
67
import MobileToolbar from "@/features/projects/view/toolbar/MobileToolbar"
78
import { useProjectSelection } from "@/features/projects/data"
8-
import NotFound from "@/features/projects/view/NotFound"
9-
import dynamic from "next/dynamic"
9+
import { ProjectsContext } from "@/common"
1010
import SecondaryHeaderPlaceholder from "@/features/sidebar/view/SecondarySplitHeaderPlaceholder"
11-
12-
const SecondarySplitHeader = dynamic(() => import("@/features/sidebar/view/SecondarySplitHeader"),
13-
{
14-
loading: () => <SecondaryHeaderPlaceholder />,
15-
ssr: false,
16-
}
17-
)
11+
import SecondarySplitHeader from "@/features/sidebar/view/SecondarySplitHeader"
1812

1913
export default function Page({ children }: { children: React.ReactNode }) {
14+
const { cached } = useContext(ProjectsContext)
2015
const { project } = useProjectSelection()
2116
const theme = useTheme()
2217
return (
2318
<Stack sx={{ height: "100%" }}>
24-
{!project &&
25-
<>
26-
<SecondarySplitHeader>
27-
<TrailingToolbarItem/>
28-
</SecondarySplitHeader>
29-
<main style={{ flexGrow: "1", overflowY: "auto" }}>
30-
<NotFound />
31-
</main>
32-
</>
33-
}
34-
{project &&
35-
<>
19+
<>
20+
{project &&
3621
<SecondarySplitHeader mobileToolbar={<MobileToolbar/>}>
3722
<TrailingToolbarItem/>
3823
</SecondarySplitHeader>
39-
<Box sx={{ height: "0.5px", background: theme.palette.divider }} />
40-
<main style={{ flexGrow: "1", overflowY: "auto" }}>
41-
{children}
42-
</main>
43-
</>
44-
}
24+
}
25+
{!project && cached && <SecondaryHeaderPlaceholder/>}
26+
<Box sx={{ height: "0.5px", background: theme.palette.divider }} />
27+
<main style={{ flexGrow: "1", overflowY: "auto" }}>
28+
{children}
29+
</main>
30+
</>
4531
</Stack>
4632
)
4733
}

src/app/(authed)/(project-doc)/[...slug]/page.tsx

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,15 @@
11
"use client"
22

3-
import { useEffect } from "react"
3+
import { useEffect, useContext } from "react"
44
import ErrorMessage from "@/common/ui/ErrorMessage"
55
import { updateWindowTitle } from "@/features/projects/domain"
66
import { useProjectSelection } from "@/features/projects/data"
77
import Documentation from "@/features/projects/view/Documentation"
8+
import NotFound from "@/features/projects/view/NotFound"
9+
import { ProjectsContext } from "@/common"
810

911
export default function Page() {
12+
const { cached } = useContext(ProjectsContext)
1013
const { project, version, specification, navigateToSelectionIfNeeded } = useProjectSelection()
1114
// Ensure the URL reflects the current selection of project, version, and specification.
1215
useEffect(() => {
@@ -28,12 +31,13 @@ export default function Page() {
2831
{project && version && specification &&
2932
<Documentation url={specification.url} />
3033
}
31-
{project && !version &&
34+
{project && !version && !cached &&
3235
<ErrorMessage text="The selected branch or tag was not found."/>
3336
}
34-
{project && !specification &&
37+
{project && !specification && !cached &&
3538
<ErrorMessage text="The selected specification was not found."/>
3639
}
40+
{!project && !cached && <NotFound/>}
3741
</>
3842
)
3943
}

src/common/context/ProjectsContext.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,11 +6,13 @@ import { Project } from "@/features/projects/domain"
66
export const SidebarTogglableContext = createContext<boolean>(true)
77

88
type ProjectsContextValue = {
9+
cached: boolean,
910
projects: Project[],
1011
setProjects: (projects: Project[]) => void
1112
}
1213

1314
export const ProjectsContext = createContext<ProjectsContextValue>({
15+
cached: true,
1416
projects: [],
1517
setProjects: () => {}
1618
})

src/features/projects/view/ProjectsContextProvider.tsx

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,9 +11,18 @@ const ProjectsContextProvider = ({
1111
initialProjects?: Project[],
1212
children?: React.ReactNode
1313
}) => {
14+
const [cached, setCached] = useState<boolean>(true)
1415
const [projects, setProjects] = useState<Project[]>(initialProjects || [])
16+
const setProjectsAndCached = (projects: Project[]) => {
17+
setProjects(projects)
18+
setCached(false)
19+
}
1520
return (
16-
<ProjectsContext.Provider value={{ projects, setProjects }}>
21+
<ProjectsContext.Provider value={{
22+
cached,
23+
projects,
24+
setProjects: setProjectsAndCached
25+
}}>
1726
{children}
1827
</ProjectsContext.Provider>
1928
)

0 commit comments

Comments
 (0)