2023-08-08 07:20:27 +00:00
|
|
|
import { useEffect } from "react";
|
2023-08-10 07:33:42 +00:00
|
|
|
// next themes
|
|
|
|
import { useTheme } from "next-themes";
|
2023-08-08 07:20:27 +00:00
|
|
|
// mobx store
|
|
|
|
import { useMobxStore } from "lib/mobx/store-provider";
|
2023-08-10 07:33:42 +00:00
|
|
|
// theme helpers
|
|
|
|
import { applyTheme, unsetCustomCssVariables } from "helpers/theme.helper";
|
2023-08-08 07:20:27 +00:00
|
|
|
|
|
|
|
const MobxStoreInit = () => {
|
|
|
|
const store: any = useMobxStore();
|
2023-08-10 07:33:42 +00:00
|
|
|
const { setTheme } = useTheme();
|
2023-08-08 07:20:27 +00:00
|
|
|
|
|
|
|
useEffect(() => {
|
|
|
|
// sidebar collapsed toggle
|
|
|
|
if (
|
|
|
|
localStorage &&
|
|
|
|
localStorage.getItem("app_sidebar_collapsed") &&
|
|
|
|
store?.theme?.sidebarCollapsed === null
|
|
|
|
)
|
|
|
|
store.theme.setSidebarCollapsed(
|
|
|
|
localStorage.getItem("app_sidebar_collapsed")
|
|
|
|
? localStorage.getItem("app_sidebar_collapsed") === "true"
|
|
|
|
? true
|
|
|
|
: false
|
|
|
|
: false
|
|
|
|
);
|
|
|
|
|
|
|
|
// theme
|
2023-08-10 07:33:42 +00:00
|
|
|
if (store.theme.theme === null && store?.user?.currentUserSettings) {
|
|
|
|
let currentTheme = localStorage.getItem("theme");
|
|
|
|
currentTheme = currentTheme ? currentTheme : "system";
|
|
|
|
|
|
|
|
// validating the theme and applying for initial state
|
|
|
|
if (currentTheme) {
|
|
|
|
setTheme(currentTheme);
|
|
|
|
store.theme.setTheme({ theme: { theme: currentTheme } });
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}, [store?.theme, store?.user, setTheme]);
|
|
|
|
|
|
|
|
useEffect(() => {
|
|
|
|
// current user
|
|
|
|
if (store?.user?.currentUser === null) store.user.setCurrentUser();
|
|
|
|
|
|
|
|
// current user settings
|
|
|
|
if (store?.user?.currentUserSettings === null) store.user.setCurrentUserSettings();
|
|
|
|
}, [store?.user]);
|
2023-08-08 07:20:27 +00:00
|
|
|
|
|
|
|
return <></>;
|
|
|
|
};
|
|
|
|
|
|
|
|
export default MobxStoreInit;
|