import React from 'react' import { connect } from 'react-redux' import { withRouter } from 'react-router' import classnames from 'classnames' import { translate } from 'react-i18next' import appFactory from '../appFactory.js' import WorkspaceListItem from '../component/Sidebar/WorkspaceListItem.jsx' import { setWorkspaceListIsOpenInSidebar } from '../action-creator.sync.js' import { PAGE, workspaceConfig } from '../helper.js' const qs = require('query-string') class Sidebar extends React.Component { constructor (props) { super(props) this.state = { sidebarClose: false, workspaceListLoaded: false, workspaceIdInUrl: props.match && props.match.params.idws ? parseInt(props.match.params.idws) : null } document.addEventListener('appCustomEvent', this.customEventReducer) } customEventReducer = async ({ detail: { type, data } }) => { // switch (type) { // default: // return // } } componentDidUpdate (prevProps, prevState) { const { props } = this if (!this.shouldDisplaySidebar()) return // console.log('%c Did Update', 'color: #c17838') if (props.match && props.match.params.idws !== undefined && !isNaN(props.match.params.idws)) { const newWorkspaceId = parseInt(props.match.params.idws) if (prevState.workspaceIdInUrl !== newWorkspaceId) this.setState({workspaceIdInUrl: newWorkspaceId}) } } shouldDisplaySidebar = () => { const pageWithoutSidebar = [PAGE.LOGIN] return !pageWithoutSidebar.includes(this.props.location.pathname) } handleClickWorkspace = (idWs, newIsOpenInSidebar) => this.props.dispatch(setWorkspaceListIsOpenInSidebar(idWs, newIsOpenInSidebar)) handleClickAllContent = idWs => this.props.history.push(PAGE.WORKSPACE.CONTENT_LIST(idWs)) handleClickToggleSidebar = () => this.setState(prev => ({sidebarClose: !prev.sidebarClose})) handleClickNewWorkspace = () => this.props.renderAppPopupCreation(workspaceConfig, this.props.user, null, null) render () { const { sidebarClose, workspaceIdInUrl } = this.state const { activeLang, workspaceList, t } = this.props if (!this.shouldDisplaySidebar()) return null return (
Copyright - 2013 - 2018
) } } const mapStateToProps = ({ lang, user, workspaceList }) => ({ activeLang: lang.find(l => l.active) || {id: 'en'}, user, workspaceList }) export default withRouter(connect(mapStateToProps)(appFactory(translate()(Sidebar))))