Added User theme preference detection
-> Used window.matchMedia API to get the user's theme preference.
This commit is contained in:
1 parent
268f302eb7
commit
77e9457614
1 file changed
+13
@@ -39,6 +39,14 @@ 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 = () => {
|
||||||
|
if(window.matchMedia && window.matchMedia('(prefers-color-scheme: dark)').matches) {
|
||||||
|
return 'dark';
|
||||||
|
}
|
||||||
|
return 'light';
|
||||||
|
}
|
||||||
function App() {
|
function App() {
|
||||||
const AdminCheckedRegister = withAdminCheck(Register);
|
const AdminCheckedRegister = withAdminCheck(Register);
|
||||||
const MonitorsWithAdminProp = withAdminProp(Monitors);
|
const MonitorsWithAdminProp = withAdminProp(Monitors);
|
||||||
@@ -58,6 +66,11 @@ function App() {
|
|||||||
}
|
}
|
||||||
}, [dispatch, authToken]);
|
}, [dispatch, authToken]);
|
||||||
|
|
||||||
|
useEffect(() => {
|
||||||
|
const theme = getPreferredTheme();
|
||||||
|
dispatch(setMode(theme));
|
||||||
|
},[dispatch]);
|
||||||
|
|
||||||
// Cleanup
|
// Cleanup
|
||||||
useEffect(() => {
|
useEffect(() => {
|
||||||
return () => {
|
return () => {
|
||||||
|
|||||||
Reference in new issue
Block a user