import React from 'react'; import { MODES } from '$constants/modes'; import classnames from 'classnames'; import { toHours } from '$utils/format'; import { Icon } from '$components/panels/Icon'; import { EditorDialog } from '$components/panels/EditorDialog'; import { LogoPreview } from '$components/logo/LogoPreview'; import { bindActionCreators } from 'redux'; import { connect } from 'react-redux'; import { setMode, startEditing, stopEditing, setLogo, takeAShot, keyPressed } from '$redux/user/actions'; import { UserLocation } from '$components/UserLocation'; import { PROVIDERS } from '$constants/providers'; import { LOGOS } from '$constants/logos'; type Props = { editing: false, mode: String, changed: Boolean, distance: Number, logo: String, estimated: Number, // todo: implement! provider: String, setMode: Function, startEditing: Function, stopEditing: Function, takeAShot: Function, keyPressed: Function, } class Component extends React.PureComponent { componentDidMount() { window.addEventListener('keydown', this.keyPressed); const obj = document.getElementById('control-dialog'); const { width } = this.panel.getBoundingClientRect(); if (!this.panel || !obj) return; obj.style.width = width; } componentWillUnmount() { window.removeEventListener('keydown', this.keyPressed); } keyPressed = e => { // if ( // e.target.tagName === 'INPUT' || // e.target.tagName === 'TEXTAREA' // ) { // if (e.key === 'Escape') e.target.blur(); // return; // } this.props.keyPressed(e); }; startPolyMode = () => this.props.setMode(MODES.POLY); startStickerMode = () => this.props.setMode(MODES.STICKERS_SELECT); startRouterMode = () => this.props.setMode(MODES.ROUTER); startProviderMode = () => this.props.setMode(MODES.PROVIDER); startTrashMode = () => this.props.setMode(MODES.TRASH); startLogoMode = () => this.props.setMode(MODES.LOGO); startSaveMode = () => { if (!this.props.changed) return; this.props.setMode(MODES.SAVE); }; render() { const { mode, distance, estimated, changed, logo, editing, provider, } = this.props; return (
{distance} км  { {toHours(estimated)} }
{(provider && PROVIDERS[provider] && PROVIDERS[provider].name) || '...'}
{(logo && LOGOS[logo] && LOGOS[logo][0]) || '...'}
{ this.panel = el; }}>
); } } function mapStateToProps(state) { const { user: { user, editing, mode, routerPoints, distance, estimated, activeSticker, logo, title, address, changed, provider, }, } = state; return { user, editing, mode, routerPoints, distance, estimated, activeSticker, logo, title, address, changed, provider, }; } const mapDispatchToProps = dispatch => bindActionCreators({ setMode, setLogo, startEditing, stopEditing, takeAShot, keyPressed, }, dispatch); export const EditorPanel = connect( mapStateToProps, mapDispatchToProps )(Component);