Added UI store with sidebar toggling
This commit is contained in:
@@ -40,7 +40,7 @@ function requireAuth(nextState, replace) {
|
|||||||
|
|
||||||
render((
|
render((
|
||||||
<div style={{ display: 'flex', flex: 1, }}>
|
<div style={{ display: 'flex', flex: 1, }}>
|
||||||
<Provider user={ stores.user }>
|
<Provider { ...stores }>
|
||||||
<Router history={History}>
|
<Router history={History}>
|
||||||
<Route path="/" component={ Application }>
|
<Route path="/" component={ Application }>
|
||||||
<IndexRoute component={Home} />
|
<IndexRoute component={Home} />
|
||||||
|
|||||||
@@ -1,4 +1,4 @@
|
|||||||
import React from 'react';
|
import React, { PropTypes } from 'react';
|
||||||
import { toJS } from 'mobx';
|
import { toJS } from 'mobx';
|
||||||
import { Link, browserHistory } from 'react-router';
|
import { Link, browserHistory } from 'react-router';
|
||||||
import { observer } from 'mobx-react';
|
import { observer } from 'mobx-react';
|
||||||
@@ -21,13 +21,16 @@ const cx = classNames.bind(styles);
|
|||||||
|
|
||||||
import treeStyles from 'components/Tree/Tree.scss';
|
import treeStyles from 'components/Tree/Tree.scss';
|
||||||
|
|
||||||
@observer
|
@observer(['ui'])
|
||||||
class DocumentScene extends React.Component {
|
class DocumentScene extends React.Component {
|
||||||
|
static propTypes = {
|
||||||
|
ui: PropTypes.object.isRequired,
|
||||||
|
}
|
||||||
|
|
||||||
static store;
|
static store;
|
||||||
|
|
||||||
state = {
|
state = {
|
||||||
didScroll: false,
|
didScroll: false,
|
||||||
showSidebar: true,
|
|
||||||
}
|
}
|
||||||
|
|
||||||
constructor(props) {
|
constructor(props) {
|
||||||
@@ -84,10 +87,6 @@ class DocumentScene extends React.Component {
|
|||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
toggleSidebar = () => {
|
|
||||||
this.setState({ showSidebar: !this.state.showSidebar });
|
|
||||||
}
|
|
||||||
|
|
||||||
renderNode = (node) => {
|
renderNode = (node) => {
|
||||||
return (
|
return (
|
||||||
<span className={ treeStyles.nodeLabel } onClick={this.onClickNode.bind(null, node)}>
|
<span className={ treeStyles.nodeLabel } onClick={this.onClickNode.bind(null, node)}>
|
||||||
@@ -97,6 +96,11 @@ class DocumentScene extends React.Component {
|
|||||||
}
|
}
|
||||||
|
|
||||||
render() {
|
render() {
|
||||||
|
const {
|
||||||
|
sidebar,
|
||||||
|
toggleSidebar,
|
||||||
|
} = this.props.ui;
|
||||||
|
|
||||||
const doc = this.store.document;
|
const doc = this.store.document;
|
||||||
const allowDelete = doc && doc.atlas.type === 'atlas' &&
|
const allowDelete = doc && doc.atlas.type === 'atlas' &&
|
||||||
doc.id !== doc.atlas.navigationTree.id;
|
doc.id !== doc.atlas.navigationTree.id;
|
||||||
@@ -135,7 +139,7 @@ class DocumentScene extends React.Component {
|
|||||||
</CenteredContent>
|
</CenteredContent>
|
||||||
) : (
|
) : (
|
||||||
<Flex flex={ true }>
|
<Flex flex={ true }>
|
||||||
{ this.store.isAtlas && this.state.showSidebar ? (
|
{ this.store.isAtlas && sidebar && (
|
||||||
<div className={ styles.sidebar }>
|
<div className={ styles.sidebar }>
|
||||||
<Tree
|
<Tree
|
||||||
paddingLeft={ 10 }
|
paddingLeft={ 10 }
|
||||||
@@ -146,13 +150,13 @@ class DocumentScene extends React.Component {
|
|||||||
renderNode={ this.renderNode }
|
renderNode={ this.renderNode }
|
||||||
/>
|
/>
|
||||||
</div>
|
</div>
|
||||||
) : null }
|
) }
|
||||||
<Flex flex={ true } justify={ 'center' } className={ styles.content}>
|
<Flex flex={ true } justify={ 'center' } className={ styles.content}>
|
||||||
<img
|
{ this.store.isAtlas && (<img
|
||||||
src={ require("assets/icons/menu.svg") }
|
src={ require("assets/icons/menu.svg") }
|
||||||
className={ styles.menuIcon }
|
className={ styles.menuIcon }
|
||||||
onClick={ this.toggleSidebar }
|
onClick={ toggleSidebar }
|
||||||
/>
|
/>) }
|
||||||
<CenteredContent>
|
<CenteredContent>
|
||||||
{ this.store.updatingContent ? (
|
{ this.store.updatingContent ? (
|
||||||
<AtlasPreviewLoading />
|
<AtlasPreviewLoading />
|
||||||
|
|||||||
@@ -19,7 +19,7 @@
|
|||||||
top: 22px;
|
top: 22px;
|
||||||
left: 17px;
|
left: 17px;
|
||||||
height: 28px;
|
height: 28px;
|
||||||
opacity: 0.5;
|
opacity: 0.15;
|
||||||
|
|
||||||
&:hover {
|
&:hover {
|
||||||
opacity: 1;
|
opacity: 1;
|
||||||
|
|||||||
32
src/stores/UiStore.js
Normal file
32
src/stores/UiStore.js
Normal file
@@ -0,0 +1,32 @@
|
|||||||
|
import { observable, action, computed } from 'mobx';
|
||||||
|
|
||||||
|
const UI_STORE = 'UI_STORE';
|
||||||
|
|
||||||
|
class UiStore {
|
||||||
|
@observable sidebar;
|
||||||
|
|
||||||
|
/* Computed */
|
||||||
|
|
||||||
|
@computed get asJson() {
|
||||||
|
return JSON.stringify({
|
||||||
|
sidebar: this.sidebar,
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
/* Actions */
|
||||||
|
|
||||||
|
@action toggleSidebar = () => {
|
||||||
|
this.sidebar = !this.sidebar;
|
||||||
|
};
|
||||||
|
|
||||||
|
constructor() {
|
||||||
|
// Rehydrate
|
||||||
|
const data = JSON.parse(localStorage.getItem(UI_STORE) || '{}');
|
||||||
|
this.sidebar = data.sidebar;
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
|
export default UiStore;
|
||||||
|
export {
|
||||||
|
UI_STORE,
|
||||||
|
};
|
||||||
@@ -64,7 +64,7 @@ class UserStore {
|
|||||||
|
|
||||||
constructor() {
|
constructor() {
|
||||||
// Rehydrate
|
// Rehydrate
|
||||||
const data = JSON.parse(localStorage.getItem(USER_STORE)) || {};
|
const data = JSON.parse(localStorage.getItem(USER_STORE) || '{}');
|
||||||
this.user = data.user;
|
this.user = data.user;
|
||||||
this.team = data.team;
|
this.team = data.team;
|
||||||
this.token = data.token;
|
this.token = data.token;
|
||||||
|
|||||||
@@ -1,13 +1,16 @@
|
|||||||
import UserStore, { USER_STORE } from './UserStore';
|
import UserStore, { USER_STORE } from './UserStore';
|
||||||
import { autorun } from 'mobx';
|
import UiStore, { UI_STORE } from './UiStore';
|
||||||
|
import { autorun, toJS } from 'mobx';
|
||||||
|
|
||||||
const stores = {
|
const stores = {
|
||||||
user: new UserStore(),
|
user: new UserStore(),
|
||||||
|
ui: new UiStore(),
|
||||||
};
|
};
|
||||||
|
|
||||||
// Persist store to localStorage
|
// Persist stores to localStorage
|
||||||
autorun(() => {
|
autorun(() => {
|
||||||
localStorage.setItem(USER_STORE, stores.user.asJson);
|
localStorage.setItem(USER_STORE, stores.user.asJson);
|
||||||
|
localStorage.setItem(UI_STORE, stores.ui.asJson);
|
||||||
});
|
});
|
||||||
|
|
||||||
export default stores;
|
export default stores;
|
||||||
|
|||||||
Reference in New Issue
Block a user