From 58377de98cab466d5e706a719baaec7777f65310 Mon Sep 17 00:00:00 2001 From: John Duprey Date: Mon, 29 Apr 2024 15:27:34 -0400 Subject: [PATCH] Move Helmet/Title to DefaultLayout --- src/App.jsx | 108 ++++++++++++++--------------- src/hooks/useNavFavouriteCheck.jsx | 2 +- src/layout/DefaultLayout.jsx | 46 ++++++++---- 3 files changed, 85 insertions(+), 71 deletions(-) diff --git a/src/App.jsx b/src/App.jsx index 276f9dcc21a5..422ebac60c62 100644 --- a/src/App.jsx +++ b/src/App.jsx @@ -1,8 +1,8 @@ import React, { Suspense } from 'react' -import { BrowserRouter, Route, Routes, Navigate } from 'react-router-dom' +import { BrowserRouter, Route, Routes, Navigate, useLocation } from 'react-router-dom' import { PrivateRoute, FullScreenLoading, ErrorBoundary } from 'src/components/utilities' import 'src/scss/style.scss' -import { Helmet } from 'react-helmet-async' +import { Helmet, HelmetProvider } from 'react-helmet-async' import Skeleton from 'react-loading-skeleton' import TimeAgo from 'javascript-time-ago' import en from 'javascript-time-ago/locale/en.json' @@ -10,7 +10,6 @@ TimeAgo.addDefaultLocale(en) import { library } from '@fortawesome/fontawesome-svg-core' import { fas } from '@fortawesome/free-solid-svg-icons' import routes from 'src/routes' -import { useAuthCheck } from './components/utilities/CippauthCheck' import importsMap from './importsMap' library.add(fas) @@ -32,59 +31,58 @@ const Logout = React.lazy(() => import('./views/pages/login/Logout')) const App = () => { return ( - }> - - CIPP - - - } /> - } /> - } /> - } /> - } /> - } /> - } /> - - - - } - > - {routes.map((route, idx) => { - const allowedRoles = route.allowedRoles - const Routecomponent = dynamicImport(route.path) - //console.log('route', route) - //console.log('Routecomponent', Routecomponent) - return ( - route.component && ( - - }> - - CIPP - {route.name} - - - - - - - } - /> + + }> + + CIPP + + + } /> + } /> + } /> + } /> + } /> + } /> + } /> + + + + } + > + {routes.map((route, idx) => { + const allowedRoles = route.allowedRoles + const Routecomponent = dynamicImport(route.path) + //console.log('route', route) + //console.log('Routecomponent', Routecomponent) + return ( + route.component && ( + + }> + + + + + + } + /> + ) ) - ) - })} - } /> - - } /> - - + })} + } /> + + } /> + + + ) } diff --git a/src/hooks/useNavFavouriteCheck.jsx b/src/hooks/useNavFavouriteCheck.jsx index 1f04018f089e..dc53534dfddc 100644 --- a/src/hooks/useNavFavouriteCheck.jsx +++ b/src/hooks/useNavFavouriteCheck.jsx @@ -28,7 +28,7 @@ export const useNavFavouriteCheck = (navigation) => { var items = [] recentPages.map((path) => { - const item = routes.find((route) => route.path === path) + const item = routes.find((route) => route.path.toLowerCase() === path.toLowerCase()) if (item?.path) { items.push({ name: item.name, diff --git a/src/layout/DefaultLayout.jsx b/src/layout/DefaultLayout.jsx index aa39ae8273b3..0b08e4ad8b8c 100644 --- a/src/layout/DefaultLayout.jsx +++ b/src/layout/DefaultLayout.jsx @@ -8,6 +8,8 @@ import { toggleSwitcher } from 'src/store/features/switcher' import { useHotkeys } from 'react-hotkeys-hook' import { useMediaPredicate } from 'react-media-hook' import { setRecentPages } from 'src/store/features/app' +import routes from 'src/routes' +import { Helmet } from 'react-helmet-async' const DefaultLayout = () => { const preferredTheme = useMediaPredicate('(prefers-color-scheme: dark)') ? 'impact' : 'cyberdrain' @@ -17,6 +19,15 @@ const DefaultLayout = () => { const dispatch = useDispatch() const location = useLocation() + const [title, setTitle] = useState('CIPP') + useEffect(() => { + let route = routes.find((route) => route.path.toLowerCase() === location.pathname.toLowerCase()) + if (route?.name) { + console.log(route) + setTitle(route.name) + } + }, [setTitle, location.pathname]) + let theme if (themePreference === 'default') { theme = preferredTheme @@ -70,24 +81,29 @@ const DefaultLayout = () => { ) return ( -
- - - + <> + + CIPP - {title} + +
+ + + - -
- -
- - }> - - - + +
+ +
+ + }> + + + +
+
-
-
+ ) }