import React from 'react'; import { CSSTransitionGroup } from 'react-transition-group'; import { WorkspaceStore } from 'mailspring-exports'; import Sheet from './sheet'; import Toolbar from './sheet-toolbar'; import Flexbox from './components/flexbox'; import InjectedComponentSet from './components/injected-component-set'; export default class SheetContainer extends React.Component { static displayName = 'SheetContainer'; constructor(props) { super(props); this._toolbarComponents = {}; this.state = this._getStateFromStores(); } componentDidMount() { this.unsubscribe = WorkspaceStore.listen(this._onStoreChange); } componentDidCatch(error, info) { // We don't currently display the error, but we need to call setState within // this function or the component does not re-render after being reset. this.setState({ error: error.stack }); AppEnv.reportError(error); } componentWillUnmount() { if (this.unsubscribe) { this.unsubscribe(); } } _getStateFromStores() { return { stack: WorkspaceStore.sheetStack(), mode: WorkspaceStore.layoutMode(), }; } _onColumnSizeChanged = sheet => { const toolbar = this._toolbarComponents[sheet.props.depth]; if (toolbar) { toolbar.recomputeLayout(); } window.dispatchEvent(new Event('resize')); }; _onStoreChange = () => { this.setState(this._getStateFromStores()); }; _toolbarContainerElement() { const { toolbar } = AppEnv.getLoadSettings(); if (!toolbar) { return []; } const components = this.state.stack.map((sheet, index) => ( { this._toolbarComponents[index] = cm; }} key={`${index}:${sheet.id}:toolbar`} depth={index} /> )); return (
{components[0]} {components.slice(1)}
); } render() { const totalSheets = this.state.stack.length; const topSheet = this.state.stack[totalSheets - 1]; if (!topSheet) { return
; } const sheetComponents = this.state.stack.map((sheet, index) => ( )); return ( {this._toolbarContainerElement()}
{sheetComponents[0]} {sheetComponents.slice(1)}
); } }