import React from 'react'; import { Layout, NavDrawer, Panel, AppBar, Navigation, Link, List, ListItem } from 'react-toolbox'; export default class LayoutMain extends React.Component { constructor(props, context) { super(props, context); this.state = { drawerActive: false, title: 'Chronos', showPagination: false, }; this.context = context; // eslint-disable-next-line no-param-reassign this.context.tooling.onChange(this.setToolbar.bind(this)); this.paginatePrev = this.paginatePrev.bind(this); this.paginateNext = this.paginateNext.bind(this); this.toggleDrawerActive = this.toggleDrawerActive.bind(this); } setToolbar(o) { this.setState({ title: o.title || 'Chronos', showPagination: o.showPagination, }); } paginatePrev() { this.context.tooling.onPaginatePrev(); } paginateNext() { this.context.tooling.onPaginateNext(); } toggleDrawerActive() { this.setState({ drawerActive: !this.state.drawerActive, // TODO: use function instead }); } render() { return (
{this.context.user.email ? Hello, {this.context.user.name}! : 'Not logged in' }
{this.context.user.email ? [ this.context.router.history.push('/')} />, this.context.router.history.push('/groups')} />, ] : null } {}} /> {}} />
{this.state.showPagination && } {this.state.showPagination && } {this.context.user.email ? this.context.router.history.push('/logout')} /> : this.context.router.history.push('/login')} /> } {this.props.children}
); } } LayoutMain.defaultProps = { children: null, }; LayoutMain.propTypes = { children: React.PropTypes.node, }; LayoutMain.contextTypes = { router: React.PropTypes.shape({ history: React.PropTypes.shape({ push: React.PropTypes.func.isRequired, }).isRequired, }).isRequired, // eslint-disable-next-line react/forbid-prop-types user: React.PropTypes.object.isRequired, token: React.PropTypes.string, // eslint-disable-next-line react/forbid-prop-types tooling: React.PropTypes.object.isRequired, };