diff --git a/src/RootAppRouter.tsx b/src/RootAppRouter.tsx index 837c2f38b..4ce26864d 100644 --- a/src/RootAppRouter.tsx +++ b/src/RootAppRouter.tsx @@ -1,4 +1,4 @@ - +import { ThemeProvider } from '@mui/material/styles'; import React from 'react'; import { RouterProvider, @@ -15,7 +15,7 @@ import AppHeader from 'components/AppHeader'; import Backdrop from 'components/Backdrop'; import BangRedirect from 'components/router/BangRedirect'; import { createRouterHistory } from 'components/router/routerHistory'; -import UserThemeProvider from 'themes/UserThemeProvider'; +import appTheme from 'themes/themes'; const layoutMode = localStorage.getItem('layout'); const isExperimentalLayout = layoutMode === 'experimental'; @@ -51,11 +51,16 @@ function RootAppLayout() { .some(path => location.pathname.startsWith(`/${path}`)); return ( - + - + ); } diff --git a/src/scripts/themeManager.js b/src/scripts/themeManager.js index f976dba82..ecf153967 100644 --- a/src/scripts/themeManager.js +++ b/src/scripts/themeManager.js @@ -39,6 +39,10 @@ function setTheme(id) { currentThemeId = info.id; + // set the theme attribute for mui + document.documentElement.setAttribute('data-theme', info.id); + + // set the meta theme color document.getElementById('themeColor').content = info.color; }); }); diff --git a/src/themes/UserThemeProvider.tsx b/src/themes/UserThemeProvider.tsx deleted file mode 100644 index e3ea9eb17..000000000 --- a/src/themes/UserThemeProvider.tsx +++ /dev/null @@ -1,47 +0,0 @@ -import { type SupportedColorScheme, ThemeProvider, useColorScheme } from '@mui/material/styles'; -import React, { type FC, type PropsWithChildren, useState, useEffect } from 'react'; -import { useLocation } from 'react-router-dom'; - -import { DASHBOARD_APP_PATHS } from 'apps/dashboard/routes/routes'; -import { useUserTheme } from 'hooks/useUserTheme'; - -import appTheme, { COLOR_SCHEMES } from './themes'; - -const isDashboardThemePage = (pathname: string) => [ - // NOTE: The metadata manager doesn't seem to use the dashboard theme - DASHBOARD_APP_PATHS.Dashboard, - DASHBOARD_APP_PATHS.PluginConfig -].some(path => pathname.startsWith(`/${path}`)); - -const ColorSchemeSwitcher: FC = () => { - const [ isDashboard, setIsDashboard ] = useState(false); - const { setColorScheme, setMode } = useColorScheme(); - const location = useLocation(); - const { theme, dashboardTheme } = useUserTheme(); - - // Check if we are on a dashboard page when the path changes - useEffect(() => { - setIsDashboard(isDashboardThemePage(location.pathname)); - }, [ location.pathname ]); - - useEffect(() => { - const currentSchemeName = (isDashboard ? dashboardTheme : theme) as SupportedColorScheme; - const currentScheme = COLOR_SCHEMES[currentSchemeName]; - - setColorScheme(currentSchemeName); - setMode(currentScheme.palette?.mode || 'dark'); - }, [ dashboardTheme, isDashboard, setColorScheme, setMode, theme ]); - - return null; -}; - -const UserThemeProvider: FC> = ({ children }) => { - return ( - - - {children} - - ); -}; - -export default UserThemeProvider; diff --git a/src/themes/themes.ts b/src/themes/themes.ts index edf16a9ac..0af1cdc97 100644 --- a/src/themes/themes.ts +++ b/src/themes/themes.ts @@ -125,7 +125,7 @@ export const COLOR_SCHEMES = { const DEFAULT_THEME = createTheme({ cssVariables: { cssVarPrefix: 'jf', - colorSchemeSelector: 'data', + colorSchemeSelector: '[data-theme="%s"]', disableCssColorScheme: true }, defaultColorScheme: 'dark',