|
@@ -20,8 +20,14 @@ const sidebarDefaultWidth = 240;
|
|
|
|
|
|
|
|
class Sidebar extends React.Component {
|
|
class Sidebar extends React.Component {
|
|
|
|
|
|
|
|
|
|
+ static propTypes = {
|
|
|
|
|
+ appContainer: PropTypes.instanceOf(AppContainer).isRequired,
|
|
|
|
|
+ navigationUIController: PropTypes.any.isRequired,
|
|
|
|
|
+ isDrawerModeOnInit: PropTypes.bool,
|
|
|
|
|
+ };
|
|
|
|
|
+
|
|
|
state = {
|
|
state = {
|
|
|
- isDrawerMode: this.props.isDrawerModeOnInit,
|
|
|
|
|
|
|
+ isDeviceSizeSmall: true,
|
|
|
currentContentsId: 'recent',
|
|
currentContentsId: 'recent',
|
|
|
};
|
|
};
|
|
|
|
|
|
|
@@ -30,6 +36,14 @@ class Sidebar extends React.Component {
|
|
|
this.initBreakpointEvents();
|
|
this.initBreakpointEvents();
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
|
|
+ get isDrawerMode() {
|
|
|
|
|
+ const { appContainer } = this.props;
|
|
|
|
|
+ const { isDeviceSizeSmall } = this.state;
|
|
|
|
|
+ const { preferDrowerModeByUser } = appContainer.state;
|
|
|
|
|
+
|
|
|
|
|
+ return isDeviceSizeSmall || preferDrowerModeByUser;
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
/**
|
|
/**
|
|
|
* hack and override UIController.storeState
|
|
* hack and override UIController.storeState
|
|
|
*
|
|
*
|
|
@@ -52,42 +66,38 @@ class Sidebar extends React.Component {
|
|
|
const mdOrAvobeHandler = (mql) => {
|
|
const mdOrAvobeHandler = (mql) => {
|
|
|
// sm -> md
|
|
// sm -> md
|
|
|
if (mql.matches) {
|
|
if (mql.matches) {
|
|
|
- if (appContainer.state.preferDrowerModeByUser) {
|
|
|
|
|
- this.toggleDrawerMode(true);
|
|
|
|
|
- }
|
|
|
|
|
- else {
|
|
|
|
|
- this.toggleDrawerMode(false);
|
|
|
|
|
- }
|
|
|
|
|
|
|
+ this.setState({ isDeviceSizeSmall: false });
|
|
|
}
|
|
}
|
|
|
// md -> sm
|
|
// md -> sm
|
|
|
else {
|
|
else {
|
|
|
// cache width
|
|
// cache width
|
|
|
this.sidebarWidthCached = navigationUIController.state.productNavWidth;
|
|
this.sidebarWidthCached = navigationUIController.state.productNavWidth;
|
|
|
|
|
|
|
|
- this.toggleDrawerMode(true);
|
|
|
|
|
|
|
+ this.setState({ isDeviceSizeSmall: true });
|
|
|
}
|
|
}
|
|
|
|
|
+
|
|
|
|
|
+ this.updateDrawerMode();
|
|
|
};
|
|
};
|
|
|
|
|
|
|
|
appContainer.addBreakpointListener('md', mdOrAvobeHandler, true);
|
|
appContainer.addBreakpointListener('md', mdOrAvobeHandler, true);
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
- toggleDrawerMode(bool) {
|
|
|
|
|
|
|
+ updateDrawerMode() {
|
|
|
const { appContainer, navigationUIController } = this.props;
|
|
const { appContainer, navigationUIController } = this.props;
|
|
|
|
|
|
|
|
- this.setState({ isDrawerMode: bool });
|
|
|
|
|
|
|
+ // close Drawer anyway
|
|
|
|
|
+ appContainer.setState({ isDrawerOpened: false });
|
|
|
|
|
|
|
|
- // Drawer
|
|
|
|
|
- if (bool) {
|
|
|
|
|
- appContainer.setState({ isDrawerOpened: false });
|
|
|
|
|
|
|
+ // switch to Drawer
|
|
|
|
|
+ if (this.isDrawerMode) {
|
|
|
navigationUIController.disableResize();
|
|
navigationUIController.disableResize();
|
|
|
navigationUIController.expand();
|
|
navigationUIController.expand();
|
|
|
|
|
|
|
|
// fix width
|
|
// fix width
|
|
|
navigationUIController.setState({ productNavWidth: sidebarDefaultWidth });
|
|
navigationUIController.setState({ productNavWidth: sidebarDefaultWidth });
|
|
|
}
|
|
}
|
|
|
- // Dock
|
|
|
|
|
|
|
+ // switch to Dock
|
|
|
else {
|
|
else {
|
|
|
- appContainer.setState({ isDrawerOpened: false });
|
|
|
|
|
navigationUIController.enableResize();
|
|
navigationUIController.enableResize();
|
|
|
|
|
|
|
|
// restore width
|
|
// restore width
|
|
@@ -134,7 +144,7 @@ class Sidebar extends React.Component {
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
render() {
|
|
render() {
|
|
|
- const { isDrawerMode } = this.state;
|
|
|
|
|
|
|
+ const { isDrawerMode } = this;
|
|
|
const { isDrawerOpened } = this.props.appContainer.state;
|
|
const { isDrawerOpened } = this.props.appContainer.state;
|
|
|
|
|
|
|
|
return (
|
|
return (
|
|
@@ -170,16 +180,14 @@ class Sidebar extends React.Component {
|
|
|
|
|
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
-Sidebar.propTypes = {
|
|
|
|
|
- appContainer: PropTypes.instanceOf(AppContainer).isRequired,
|
|
|
|
|
- navigationUIController: PropTypes.any.isRequired,
|
|
|
|
|
- isDrawerModeOnInit: PropTypes.bool,
|
|
|
|
|
-};
|
|
|
|
|
|
|
+
|
|
|
|
|
+const SidebarWithNavigationUIController = withNavigationUIController(Sidebar);
|
|
|
|
|
|
|
|
/**
|
|
/**
|
|
|
- * Wrapper component for using unstated and NavigationProvider
|
|
|
|
|
|
|
+ * Wrapper component for using unstated
|
|
|
*/
|
|
*/
|
|
|
-const SidebarWithNavigation = withNavigationUIController((props) => {
|
|
|
|
|
|
|
+
|
|
|
|
|
+const SidebarWithNavigation = (props) => {
|
|
|
const { preferDrowerModeByUser: isDrawerModeOnInit } = props.appContainer.state;
|
|
const { preferDrowerModeByUser: isDrawerModeOnInit } = props.appContainer.state;
|
|
|
|
|
|
|
|
const initUICForDrawerMode = isDrawerModeOnInit
|
|
const initUICForDrawerMode = isDrawerModeOnInit
|
|
@@ -194,10 +202,10 @@ const SidebarWithNavigation = withNavigationUIController((props) => {
|
|
|
|
|
|
|
|
return (
|
|
return (
|
|
|
<NavigationProvider initialUIController={initUICForDrawerMode}>
|
|
<NavigationProvider initialUIController={initUICForDrawerMode}>
|
|
|
- <Sidebar {...props} isDrawerModeOnInit />
|
|
|
|
|
|
|
+ <SidebarWithNavigationUIController {...props} isDrawerModeOnInit={isDrawerModeOnInit} />
|
|
|
</NavigationProvider>
|
|
</NavigationProvider>
|
|
|
-);
|
|
|
|
|
-});
|
|
|
|
|
|
|
+ );
|
|
|
|
|
+};
|
|
|
|
|
|
|
|
SidebarWithNavigation.propTypes = {
|
|
SidebarWithNavigation.propTypes = {
|
|
|
appContainer: PropTypes.instanceOf(AppContainer).isRequired,
|
|
appContainer: PropTypes.instanceOf(AppContainer).isRequired,
|