theme is saving properly to local storage

This commit is contained in:
Carter 2025-04-16 12:29:02 -06:00
parent 9df40db30f
commit 67f8645a25
2 changed files with 49 additions and 48 deletions

View file

@ -8,7 +8,6 @@ import { ErrorBoundary } from "react-error-boundary";
import { getWhitelabel } from "services/whiteLabel";
import Ventilation from "pages/VentEditor";
import { useGlobalState } from "providers";
import { Box } from "@mui/material";
const DeviceHistory = lazy(() => import("pages/DeviceHistory"));
const DevicePage = lazy(() => import("pages/Device"));
@ -289,7 +288,6 @@ export default function Router() {
return (
<BrowserRouter>
<Header />
{/* <Box sx={{ height: "100%", minHeight: "200px" }}> */}
<Suspense fallback={<LoadingScreen message="Loading Page"/>}>
<Routes>
@ -336,7 +334,6 @@ export default function Router() {
</Routes>
</Suspense>
{/* </Box> */}
</BrowserRouter>
)
}

View file

@ -24,7 +24,11 @@ export const useThemeMode = () => {
};
export const AppThemeProvider: React.FC<{ children: React.ReactNode }> = ({ children }) => {
const [mode, setMode] = useState<ThemeMode>("system");
const savedTheme = localStorage.getItem("theme");
const isValidTheme = (theme: string | null): theme is ThemeMode =>
theme === "light" || theme === "dark" || theme === "system";
const [mode, setMode] = useState<ThemeMode>(isValidTheme(savedTheme) ? savedTheme : "system");
const prefersDark = useMediaQuery("(prefers-color-scheme: dark)");
const resolvedMode: PaletteMode = mode === "system" ? (prefersDark ? "dark" : "light") : mode;