import * as React from 'react'; import { MODES } from '$constants/modes'; import classnames from 'classnames'; import { Icon } from '$components/panels/Icon'; import { EditorDialog } from '$components/panels/EditorDialog'; import { bindActionCreators } from 'redux'; import { connect } from 'react-redux'; import { setMode, startEditing, stopEditing, setLogo, takeAShot, keyPressed } from '$redux/user/actions'; import { IRootState } from "$redux/user"; import { Tooltip } from "$components/panels/Tooltip"; interface Props extends IRootState { routing: IRootState['features']['routing'], setMode: typeof setMode, startEditing: typeof startEditing, stopEditing: typeof stopEditing, keyPressed: EventListenerOrEventListenerObject, } class Component extends React.PureComponent { componentDidMount() { window.addEventListener('keydown', this.props.keyPressed); const obj = document.getElementById('control-dialog'); const { width } = this.panel.getBoundingClientRect(); if (!this.panel || !obj) return; obj.style.width = String(width); } panel: HTMLElement = null; componentWillUnmount() { window.removeEventListener('keydown', this.props.keyPressed); } startPolyMode = () => this.props.setMode(MODES.POLY); startStickerMode = () => this.props.setMode(MODES.STICKERS_SELECT); startRouterMode = () => this.props.setMode(MODES.ROUTER); startTrashMode = () => this.props.setMode(MODES.TRASH); startSaveMode = () => { // if (!this.props.changed) return; this.props.setMode(MODES.SAVE); }; render() { const { mode, changed, editing, routing, } = this.props; return (
{ this.panel = el; }}>
{ routing && }
); } } function mapStateToProps(state) { const { user: { editing, mode, changed, features: { routing, } }, } = state; return { editing, mode, changed, routing, }; } const mapDispatchToProps = dispatch => bindActionCreators({ setMode, setLogo, startEditing, stopEditing, takeAShot, keyPressed, }, dispatch); export const EditorPanel = connect( mapStateToProps, mapDispatchToProps )(Component);