Theme preference logic moved to UISlice
This commit is contained in:
1 parent
8c2151dcf3
commit
0c3d8245e9
2 files changed
+1
-28
No files matched your search
@@ -39,17 +39,6 @@ import { useDispatch } from "react-redux";
|
|||||||
import { getAppSettings, updateAppSettings } from "./Features/Settings/settingsSlice";
|
import { getAppSettings, updateAppSettings } from "./Features/Settings/settingsSlice";
|
||||||
import { logger } from "./Utils/Logger"; // Import the logger
|
import { logger } from "./Utils/Logger"; // Import the logger
|
||||||
import { networkService } from "./main";
|
import { networkService } from "./main";
|
||||||
import { setMode } from "./Features/UI/uiSlice";
|
|
||||||
|
|
||||||
const getPreferredTheme = () => {
|
|
||||||
try {
|
|
||||||
return window?.matchMedia?.('(prefers-color-scheme: dark)')?.matches? 'dark': 'light';
|
|
||||||
}
|
|
||||||
catch {
|
|
||||||
return 'light';
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
function App() {
|
function App() {
|
||||||
const AdminCheckedRegister = withAdminCheck(Register);
|
const AdminCheckedRegister = withAdminCheck(Register);
|
||||||
const MonitorsWithAdminProp = withAdminProp(Monitors);
|
const MonitorsWithAdminProp = withAdminProp(Monitors);
|
||||||
@@ -69,22 +58,6 @@ function App() {
|
|||||||
}
|
}
|
||||||
}, [dispatch, authToken]);
|
}, [dispatch, authToken]);
|
||||||
|
|
||||||
useEffect(() => {
|
|
||||||
const theme = getPreferredTheme();
|
|
||||||
dispatch(setMode(theme));
|
|
||||||
|
|
||||||
const mediaQuery = window?.matchMedia?.('(prefers-color-scheme: dark)');
|
|
||||||
const handleThemeChange = (e) => {
|
|
||||||
dispatch(setMode(e.matches ? 'dark' : 'light'));
|
|
||||||
};
|
|
||||||
|
|
||||||
mediaQuery?.addEventListener?.('change', handleThemeChange);
|
|
||||||
|
|
||||||
return () => {
|
|
||||||
mediaQuery?.removeEventListener?.('change', handleThemeChange);
|
|
||||||
};
|
|
||||||
},[dispatch]);
|
|
||||||
|
|
||||||
// Cleanup
|
// Cleanup
|
||||||
useEffect(() => {
|
useEffect(() => {
|
||||||
return () => {
|
return () => {
|
||||||
|
|||||||
@@ -15,7 +15,7 @@ const initialState = {
|
|||||||
sidebar: {
|
sidebar: {
|
||||||
collapsed: false,
|
collapsed: false,
|
||||||
},
|
},
|
||||||
mode: "light",
|
mode: window?.matchMedia?.('(prefers-color-scheme: dark)')?.matches? "dark": "light",
|
||||||
greeting: { index: 0, lastUpdate: null },
|
greeting: { index: 0, lastUpdate: null },
|
||||||
timezone: "America/Toronto",
|
timezone: "America/Toronto",
|
||||||
};
|
};
|
||||||
|
|||||||
Reference in new issue
Block a user