refactor: guide atoms (#2196)

This commit is contained in:
Himself65 authored and GitHub committed 2023-04-28 15:59:59 -05:00
1 parent 31cccafb40
commit 1031fbc7ec
11 files changed
+85 -231

No files matched your search

@@ -1,7 +1,8 @@
import { atomWithStorage } from 'jotai/utils';
export const APP_SIDEBAR_OPEN = 'app-sidebar-open';
export const appSidebarOpenAtom = atomWithStorage(
'app-sidebar-open',
APP_SIDEBAR_OPEN,
undefined as boolean | undefined
);
export const appSidebarWidthAtom = atomWithStorage(
@@ -21,7 +21,11 @@ import {
sidebarButtonStyle,
sidebarFloatMaskStyle,
} from './index.css';
import { appSidebarOpenAtom, appSidebarWidthAtom } from './index.jotai';
import {
APP_SIDEBAR_OPEN,
appSidebarOpenAtom,
appSidebarWidthAtom,
} from './index.jotai';
export { appSidebarOpenAtom };
@@ -41,7 +45,10 @@ export const AppSidebar = forwardRef<HTMLElement, AppSidebarProps>(
}, [setOpen]);
useEffect(() => {
if (open === undefined) {
if (
open === undefined &&
localStorage.getItem(APP_SIDEBAR_OPEN) === null
) {
// give the initial value,
// so that the sidebar can be closed on mobile by default
const { matches } = window.matchMedia(