plane/apps/app/lib/mobx/store-init.tsx
guru_sainath b6744dcd29
Chore: mobx setup and app sidebar and theme management (#1798)
* dev: Mobx integration for app sidebar and custom theme

* dev: Handled edge case and conditional rendering for mobx store
2023-08-08 12:50:27 +05:30

34 lines
882 B
TypeScript

import { useEffect } from "react";
// mobx store
import { useMobxStore } from "lib/mobx/store-provider";
const MobxStoreInit = () => {
const store: any = useMobxStore();
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
if (localStorage && localStorage.getItem("theme") && store.theme.theme === null)
store.theme.setTheme(
localStorage.getItem("theme") ? localStorage.getItem("theme") : "system"
);
}, [store?.theme]);
return <></>;
};
export default MobxStoreInit;