From 5acca662062b57667910da3208740f6ad1a5ccd2 Mon Sep 17 00:00:00 2001 From: Stefan Fleckenstein Date: Tue, 16 Apr 2024 19:42:43 +0200 Subject: [PATCH] fix: set theme without reload --- frontend/src/App.tsx | 5 +++-- frontend/src/commons/layout/AppBar.tsx | 13 +++++++++++-- frontend/src/commons/settings/Settings.tsx | 10 ---------- 3 files changed, 14 insertions(+), 14 deletions(-) diff --git a/frontend/src/App.tsx b/frontend/src/App.tsx index 9070a6fda..ff7ef44cf 100644 --- a/frontend/src/App.tsx +++ b/frontend/src/App.tsx @@ -11,10 +11,10 @@ import authorization_groups from "./access_control/authorization_groups"; import users from "./access_control/users"; import englishMessages from "./commons/i18n/en"; import { Layout } from "./commons/layout"; +import { darkTheme, lightTheme } from "./commons/layout/themes"; import notifications from "./commons/notifications"; import drfProvider from "./commons/ra-data-django-rest-framework"; import Settings from "./commons/settings/Settings"; -import { getTheme } from "./commons/settings/functions"; import evidences from "./core/evidences"; import observation_logs from "./core/observation_logs"; import observations from "./core/observations"; @@ -45,7 +45,8 @@ const App = () => { layout={Layout} i18nProvider={i18nProvider} disableTelemetry - theme={getTheme()} + theme={lightTheme} + darkTheme={darkTheme} > } /> diff --git a/frontend/src/commons/layout/AppBar.tsx b/frontend/src/commons/layout/AppBar.tsx index 8dc4492c3..e0ee4e876 100644 --- a/frontend/src/commons/layout/AppBar.tsx +++ b/frontend/src/commons/layout/AppBar.tsx @@ -3,7 +3,7 @@ import PersonIcon from "@mui/icons-material/Person"; import SettingsIcon from "@mui/icons-material/Settings"; import { Box, Divider, ListItemIcon, ListItemText, MenuItem, Theme, Typography, useMediaQuery } from "@mui/material"; import { forwardRef } from "react"; -import { AppBar, Logout, UserMenu, useUserMenu } from "react-admin"; +import { AppBar, LoadingIndicator, Logout, UserMenu, useUserMenu } from "react-admin"; import { Link } from "react-router-dom"; import About from "../about/About"; @@ -89,7 +89,16 @@ const CustomUserMenu = () => { const CustomAppBar = () => { const isLargeEnough = useMediaQuery((theme) => theme.breakpoints.up("sm")); return ( - }> + } + toolbar={ + <> + + + } + > { - const [previousTheme, setPreviousTheme] = useState(getSettingTheme()); const [, setTheme] = useTheme(); function setLightTheme() { setTheme(lightTheme); saveSettingTheme("light"); - if (previousTheme != "light") { - window.location.reload(); - } - setPreviousTheme("light"); } function setDarkTheme() { setTheme(darkTheme); saveSettingTheme("dark"); - if (previousTheme != "dark") { - window.location.reload(); - } - setPreviousTheme("dark"); } return (