-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Uses Suspense when loading projects (#322)
* Moves MenuItemHover to client * Removes unused SidebarContext * Uses Suspense to load projects * Moves ProjectsContextProvider to fix unit tests * Moves contexts.ts to client-side * Moves ProjectsContextProvider.tsx to client-side * Fixes build errors
- Loading branch information
Showing
20 changed files
with
227 additions
and
248 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,19 +1,14 @@ | ||
"use client" | ||
|
||
import { createContext } from "react" | ||
import { Project, } from "@/features/projects/domain" | ||
import { Project } from "@/features/projects/domain" | ||
|
||
export const SidebarContext = createContext<{ isToggleable: boolean }>({ isToggleable: true }) | ||
|
||
type ProjectsContainer = { | ||
readonly projects: Project[] | ||
readonly isLoading: boolean | ||
readonly error?: Error | ||
type ProjectsContextValue = { | ||
projects: Project[], | ||
setProjects: (projects: Project[]) => void | ||
} | ||
|
||
export const ProjectsContainerContext = createContext<ProjectsContainer>({ | ||
isLoading: true, | ||
projects: [] | ||
export const ProjectsContext = createContext<ProjectsContextValue>({ | ||
projects: [], | ||
setProjects: () => {} | ||
}) | ||
|
||
export const ServerSideCachedProjectsContext = createContext<Project[] | undefined>(undefined) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,6 +1,5 @@ | ||
export { default as GitHubProjectDataSource } from "./GitHubProjectDataSource" | ||
export * from "./GitHubProjectDataSource" | ||
export { default as useProjects } from "./useProjects" | ||
export { default as useProjectSelection } from "./useProjectSelection" | ||
export { default as GitHubLoginDataSource } from "./GitHubLoginDataSource" | ||
export { default as GitHubRepositoryDataSource } from "./GitHubRepositoryDataSource" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,22 @@ | ||
"use client" | ||
|
||
import { useState } from "react" | ||
import { ProjectsContext } from "@/common" | ||
import { Project } from "@/features/projects/domain" | ||
|
||
const ProjectsContextProvider = ({ | ||
initialProjects, | ||
children | ||
}: { | ||
initialProjects?: Project[], | ||
children?: React.ReactNode | ||
}) => { | ||
const [projects, setProjects] = useState<Project[]>(initialProjects || []) | ||
return ( | ||
<ProjectsContext.Provider value={{ projects, setProjects }}> | ||
{children} | ||
</ProjectsContext.Provider> | ||
) | ||
} | ||
|
||
export default ProjectsContextProvider |
20 changes: 0 additions & 20 deletions
20
src/features/projects/view/ServerSideCachedProjectsProvider.tsx
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,52 +1,22 @@ | ||
"use client" | ||
import ClientSplitView from "./internal/ClientSplitView" | ||
import { projectDataSource } from "@/composition" | ||
import BaseSidebar from "./internal/sidebar/Sidebar" | ||
import ProjectList from "./internal/sidebar/projects/ProjectList" | ||
|
||
import { useEffect } from "react" | ||
import { Stack } from "@mui/material" | ||
import { isMac, useKeyboardShortcut } from "@/common" | ||
import { useSidebarOpen } from "../data" | ||
import PrimaryContainer from "./internal/primary/Container" | ||
import SecondaryContainer from "./internal/secondary/Container" | ||
import Sidebar from "./internal/sidebar/Sidebar" | ||
|
||
const SplitView = ({ | ||
canToggleSidebar: _canToggleSidebar, | ||
children | ||
}: { | ||
canToggleSidebar?: boolean | ||
children?: React.ReactNode | ||
}) => { | ||
const [isSidebarOpen, setSidebarOpen] = useSidebarOpen() | ||
const canToggleSidebar = _canToggleSidebar !== undefined ? _canToggleSidebar : true | ||
useEffect(() => { | ||
// Show the sidebar if no project is selected. | ||
if (!canToggleSidebar) { | ||
setSidebarOpen(true) | ||
} | ||
}, [canToggleSidebar, setSidebarOpen]) | ||
useKeyboardShortcut(event => { | ||
const isActionKey = isMac() ? event.metaKey : event.ctrlKey | ||
if (isActionKey && event.key === ".") { | ||
event.preventDefault() | ||
if (canToggleSidebar) { | ||
setSidebarOpen(!isSidebarOpen) | ||
} | ||
} | ||
}, [canToggleSidebar, setSidebarOpen]) | ||
const sidebarWidth = 320 | ||
const SplitView = ({ children }: { children?: React.ReactNode }) => { | ||
return ( | ||
<Stack direction="row" spacing={0} sx={{ width: "100%", height: "100%" }}> | ||
<PrimaryContainer | ||
width={sidebarWidth} | ||
isOpen={isSidebarOpen} | ||
onClose={() => setSidebarOpen(false)} | ||
> | ||
<Sidebar/> | ||
</PrimaryContainer> | ||
<SecondaryContainer sidebarWidth={sidebarWidth} offsetContent={isSidebarOpen}> | ||
{children} | ||
</SecondaryContainer> | ||
</Stack> | ||
<ClientSplitView sidebar={<Sidebar/>}> | ||
{children} | ||
</ClientSplitView> | ||
) | ||
} | ||
|
||
export default SplitView | ||
|
||
const Sidebar = () => { | ||
return ( | ||
<BaseSidebar> | ||
<ProjectList projectDataSource={projectDataSource} /> | ||
</BaseSidebar> | ||
) | ||
} |
Oops, something went wrong.