|
@@ -3,10 +3,12 @@ import React, {
|
|
|
} from 'react';
|
|
} from 'react';
|
|
|
|
|
|
|
|
import {
|
|
import {
|
|
|
- useCurrentSidebarContents, useDrawerMode, useDrawerOpened, usePreferDrawerModeByUser,
|
|
|
|
|
|
|
+ useDrawerMode, useDrawerOpened, usePreferDrawerModeByUser,
|
|
|
|
|
+ useSidebarCollapsed,
|
|
|
|
|
+ useCurrentSidebarContents,
|
|
|
useCurrentProductNavWidth,
|
|
useCurrentProductNavWidth,
|
|
|
- useSidebarCollapsed, putSidebarCollapsed,
|
|
|
|
|
useSidebarResizeDisabled,
|
|
useSidebarResizeDisabled,
|
|
|
|
|
+ putUserUISettings,
|
|
|
} from '~/stores/ui';
|
|
} from '~/stores/ui';
|
|
|
|
|
|
|
|
import DrawerToggler from './Navbar/DrawerToggler';
|
|
import DrawerToggler from './Navbar/DrawerToggler';
|
|
@@ -32,7 +34,7 @@ const GlobalNavigation = () => {
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
mutateSidebarCollapsed(newValue, false);
|
|
mutateSidebarCollapsed(newValue, false);
|
|
|
- putSidebarCollapsed(newValue);
|
|
|
|
|
|
|
+ putUserUISettings({ isSidebarCollapsed: newValue });
|
|
|
|
|
|
|
|
}, [currentContents, isCollapsed, mutateSidebarCollapsed]);
|
|
}, [currentContents, isCollapsed, mutateSidebarCollapsed]);
|
|
|
|
|
|
|
@@ -91,13 +93,12 @@ const SidebarSkeltonContents = () => {
|
|
|
|
|
|
|
|
|
|
|
|
|
type Props = {
|
|
type Props = {
|
|
|
- productNavWidth: number
|
|
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
const Sidebar: FC<Props> = (props: Props) => {
|
|
const Sidebar: FC<Props> = (props: Props) => {
|
|
|
const { data: isDrawerMode } = useDrawerMode();
|
|
const { data: isDrawerMode } = useDrawerMode();
|
|
|
const { data: isDrawerOpened, mutate: mutateDrawerOpened } = useDrawerOpened();
|
|
const { data: isDrawerOpened, mutate: mutateDrawerOpened } = useDrawerOpened();
|
|
|
- const { data: currentProductNavWidth, mutate: mutateProductNavWidth } = useCurrentProductNavWidth(props.productNavWidth);
|
|
|
|
|
|
|
+ const { data: currentProductNavWidth, mutate: mutateProductNavWidth } = useCurrentProductNavWidth();
|
|
|
const { data: isCollapsed, mutate: mutateSidebarCollapsed } = useSidebarCollapsed();
|
|
const { data: isCollapsed, mutate: mutateSidebarCollapsed } = useSidebarCollapsed();
|
|
|
const { data: isResizeDisabled, mutate: mutateSidebarResizeDisabled } = useSidebarResizeDisabled();
|
|
const { data: isResizeDisabled, mutate: mutateSidebarResizeDisabled } = useSidebarResizeDisabled();
|
|
|
|
|
|
|
@@ -135,7 +136,7 @@ const Sidebar: FC<Props> = (props: Props) => {
|
|
|
// }
|
|
// }
|
|
|
|
|
|
|
|
// disable resize
|
|
// disable resize
|
|
|
- mutateSidebarResizeDisabled(true);
|
|
|
|
|
|
|
+ mutateSidebarResizeDisabled(true, false);
|
|
|
}
|
|
}
|
|
|
// Drawer --> Dock
|
|
// Drawer --> Dock
|
|
|
else {
|
|
else {
|
|
@@ -145,7 +146,7 @@ const Sidebar: FC<Props> = (props: Props) => {
|
|
|
// }
|
|
// }
|
|
|
|
|
|
|
|
// enable resize
|
|
// enable resize
|
|
|
- mutateSidebarResizeDisabled(false);
|
|
|
|
|
|
|
+ mutateSidebarResizeDisabled(false, false);
|
|
|
|
|
|
|
|
// // restore width
|
|
// // restore width
|
|
|
// if (this.sidebarWidthCached != null) {
|
|
// if (this.sidebarWidthCached != null) {
|
|
@@ -165,7 +166,7 @@ const Sidebar: FC<Props> = (props: Props) => {
|
|
|
// }
|
|
// }
|
|
|
|
|
|
|
|
const backdropClickedHandler = useCallback(() => {
|
|
const backdropClickedHandler = useCallback(() => {
|
|
|
- mutateDrawerOpened(false);
|
|
|
|
|
|
|
+ mutateDrawerOpened(false, false);
|
|
|
}, [mutateDrawerOpened]);
|
|
}, [mutateDrawerOpened]);
|
|
|
|
|
|
|
|
const [isMounted, setMounted] = useState(false);
|
|
const [isMounted, setMounted] = useState(false);
|
|
@@ -208,7 +209,7 @@ const Sidebar: FC<Props> = (props: Props) => {
|
|
|
const toggleNavigationBtnClickHandler = useCallback(() => {
|
|
const toggleNavigationBtnClickHandler = useCallback(() => {
|
|
|
const newValue = !isCollapsed;
|
|
const newValue = !isCollapsed;
|
|
|
mutateSidebarCollapsed(newValue, false);
|
|
mutateSidebarCollapsed(newValue, false);
|
|
|
- putSidebarCollapsed(newValue);
|
|
|
|
|
|
|
+ putUserUISettings({ isSidebarCollapsed: newValue });
|
|
|
}, [isCollapsed, mutateSidebarCollapsed]);
|
|
}, [isCollapsed, mutateSidebarCollapsed]);
|
|
|
|
|
|
|
|
useEffect(() => {
|
|
useEffect(() => {
|
|
@@ -240,13 +241,14 @@ const Sidebar: FC<Props> = (props: Props) => {
|
|
|
|
|
|
|
|
if (resizableContainer.current.clientWidth < sidebarMinWidth) {
|
|
if (resizableContainer.current.clientWidth < sidebarMinWidth) {
|
|
|
// force collapsed
|
|
// force collapsed
|
|
|
- mutateSidebarCollapsed(true);
|
|
|
|
|
- mutateProductNavWidth(sidebarMinWidth);
|
|
|
|
|
- // TODO call API and save DB
|
|
|
|
|
|
|
+ mutateSidebarCollapsed(true, false);
|
|
|
|
|
+ mutateProductNavWidth(sidebarMinWidth, false);
|
|
|
|
|
+ putUserUISettings({ isSidebarCollapsed: true, currentProductNavWidth: sidebarMinWidth });
|
|
|
}
|
|
}
|
|
|
else {
|
|
else {
|
|
|
- mutateProductNavWidth(resizableContainer.current.clientWidth);
|
|
|
|
|
- // TODO call API and save DB
|
|
|
|
|
|
|
+ const newWidth = resizableContainer.current.clientWidth;
|
|
|
|
|
+ mutateProductNavWidth(newWidth, false);
|
|
|
|
|
+ putUserUISettings({ currentProductNavWidth: newWidth });
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
resizableContainer.current.classList.remove('dragging');
|
|
resizableContainer.current.classList.remove('dragging');
|