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 } 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, } class Component extends React.PureComponent { componentDidMount() { const obj = document.getElementById('control-dialog'); const { width } = this.panel.getBoundingClientRect(); if (!this.panel || !obj) return; obj.style.width = width; } startPolyMode = () => this.props.setMode(MODES.POLY); startStickerMode = () => this.props.setMode(MODES.STICKERS); 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 = () => 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, }, dispatch); export const EditorPanel = connect( mapStateToProps, mapDispatchToProps )(Component);