Skip to content

Commit

Permalink
fix: set theme without reload (#1396)
Browse files Browse the repository at this point in the history
  • Loading branch information
StefanFl authored Apr 16, 2024
1 parent bff789a commit 1332c72
Show file tree
Hide file tree
Showing 3 changed files with 14 additions and 14 deletions.
5 changes: 3 additions & 2 deletions frontend/src/App.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -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";
Expand Down Expand Up @@ -45,7 +45,8 @@ const App = () => {
layout={Layout}
i18nProvider={i18nProvider}
disableTelemetry
theme={getTheme()}
theme={lightTheme}
darkTheme={darkTheme}
>
<CustomRoutes>
<Route path="/access_control/users" element={<AccessControlAdministration />} />
Expand Down
13 changes: 11 additions & 2 deletions frontend/src/commons/layout/AppBar.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -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";
Expand Down Expand Up @@ -89,7 +89,16 @@ const CustomUserMenu = () => {
const CustomAppBar = () => {
const isLargeEnough = useMediaQuery<Theme>((theme) => theme.breakpoints.up("sm"));
return (
<AppBar color="secondary" elevation={1} userMenu={<CustomUserMenu />}>
<AppBar
color="secondary"
elevation={1}
userMenu={<CustomUserMenu />}
toolbar={
<>
<LoadingIndicator />
</>
}
>
<Typography
variant="h6"
color="inherit"
Expand Down
10 changes: 0 additions & 10 deletions frontend/src/commons/settings/Settings.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -9,32 +9,22 @@ import {
RadioGroup,
Stack,
} from "@mui/material";
import { useState } from "react";
import { Title, useTheme } from "react-admin";

import { darkTheme, lightTheme } from "../layout/themes";
import { getSettingListSize, getSettingTheme, saveSettingListSize, saveSettingTheme } from "./functions";

const Settings = () => {
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 (
Expand Down

0 comments on commit 1332c72

Please sign in to comment.