-
Notifications
You must be signed in to change notification settings - Fork 6
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: group context providers into one
- Loading branch information
Showing
6 changed files
with
71 additions
and
39 deletions.
There are no files selected for viewing
46 changes: 46 additions & 0 deletions
46
packages/diracx-web-components/src/contexts/DiracXWebProviders.tsx
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,46 @@ | ||
import { CssBaseline, ThemeProvider as MUIThemeProvider } from "@mui/material"; | ||
import { useMUITheme } from "../hooks"; | ||
import { | ||
OIDCConfigurationProvider, | ||
ThemeProvider, | ||
NavigationProvider, | ||
ApplicationsProvider, | ||
} from "./index"; | ||
|
||
export function DiracXWebProviders({ | ||
children, | ||
getPath, | ||
setPath, | ||
getSearchParams, | ||
}: { | ||
children: React.ReactNode; | ||
getPath: () => string; | ||
setPath: (path: string) => void; | ||
getSearchParams: () => URLSearchParams; | ||
}) { | ||
return ( | ||
<OIDCConfigurationProvider> | ||
<ThemeProvider> | ||
<NavigationProvider | ||
getPath={getPath} | ||
setPath={setPath} | ||
getSearchParams={getSearchParams} | ||
> | ||
<ApplicationsProvider> | ||
<MUIProviders>{children}</MUIProviders> | ||
</ApplicationsProvider> | ||
</NavigationProvider> | ||
</ThemeProvider> | ||
</OIDCConfigurationProvider> | ||
); | ||
} | ||
|
||
function MUIProviders({ children }: { children: React.ReactNode }) { | ||
const theme = useMUITheme(); | ||
return ( | ||
<MUIThemeProvider theme={theme}> | ||
<CssBaseline /> | ||
{children} | ||
</MUIThemeProvider> | ||
); | ||
} |
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
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,55 +1,43 @@ | ||
"use client"; | ||
import React from "react"; | ||
import CssBaseline from "@mui/material/CssBaseline"; | ||
import { Box } from "@mui/material"; | ||
import { ThemeProvider as MUIThemeProvider } from "@mui/material/styles"; | ||
import { DiracXWebProviders } from "@diracgrid/diracx-web-components/contexts"; | ||
import { | ||
OIDCSecure, | ||
Dashboard, | ||
} from "@diracgrid/diracx-web-components/components"; | ||
import { | ||
ApplicationsProvider, | ||
NavigationProvider, | ||
} from "@diracgrid/diracx-web-components/contexts"; | ||
import { useMUITheme } from "@diracgrid/diracx-web-components/hooks"; | ||
import { usePathname, useRouter, useSearchParams } from "next/navigation"; | ||
|
||
export default function DashboardLayout({ | ||
children, | ||
}: { | ||
children: React.ReactNode; | ||
}) { | ||
const theme = useMUITheme(); | ||
const pathname = usePathname(); | ||
const router = useRouter(); | ||
const searchParams = useSearchParams(); | ||
return ( | ||
<section> | ||
<NavigationProvider | ||
<DiracXWebProviders | ||
getPath={() => pathname} | ||
setPath={(path: string) => { | ||
router.push(path); | ||
}} | ||
getSearchParams={() => searchParams} | ||
> | ||
<ApplicationsProvider> | ||
<OIDCSecure> | ||
<Dashboard> | ||
<MUIThemeProvider theme={theme}> | ||
<CssBaseline /> | ||
<Box | ||
sx={{ | ||
ml: "5%", | ||
mr: "5%", | ||
}} | ||
> | ||
{children} | ||
</Box> | ||
</MUIThemeProvider> | ||
</Dashboard> | ||
</OIDCSecure> | ||
</ApplicationsProvider> | ||
</NavigationProvider> | ||
<OIDCSecure> | ||
<Dashboard> | ||
<Box | ||
sx={{ | ||
ml: "5%", | ||
mr: "5%", | ||
}} | ||
> | ||
{children} | ||
</Box> | ||
</Dashboard> | ||
</OIDCSecure> | ||
</DiracXWebProviders> | ||
</section> | ||
); | ||
} |
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