top panels code cleanup

This commit is contained in:
muerwre 2019-02-06 17:34:45 +07:00
parent eae5a893fc
commit 3e16ad4e37
3 changed files with 44 additions and 41 deletions

View file

@ -10,10 +10,7 @@ export class UserLocation extends React.Component {
const element = document.createElement('div');
this.icon = new DomMarker({
element,
className: 'location-marker',
});
this.icon = new DomMarker({ element, className: 'location-marker' });
this.mark = null;
this.map = editor.map.map;
@ -64,8 +61,10 @@ export class UserLocation extends React.Component {
render() {
return (
<div onClick={this.centerMapOnLocation}>
<Icon icon="icon-locate" size={30} />
<div className="status-bar square pointer pointer">
<div onClick={this.centerMapOnLocation}>
<Icon icon="icon-locate" size={30} />
</div>
</div>
);
}

View file

@ -0,0 +1,35 @@
// flow
import React from 'react';
import { toHours } from '$utils/format';
import { Icon } from '$components/panels/Icon';
import { connect } from 'react-redux';
type Props = {
distance: number,
estimated: number,
};
const Component = ({ distance, estimated }: Props) => (
<div className="status-bar padded desktop-only">
{distance} км&nbsp;
<Icon icon="icon-cycle" size={32} />
{
<span>{toHours(estimated)}</span>
}
</div>
);
function mapStateToProps(state) {
const {
user: { distance, estimated },
} = state;
return { distance, estimated };
}
const mapDispatchToProps = () => ({ });
export const DistanceBar = connect(
mapStateToProps,
mapDispatchToProps
)(Component);

View file

@ -1,42 +1,11 @@
// flow
import React from 'react';
import { toHours } from '$utils/format';
import { Icon } from '$components/panels/Icon';
import { UserLocation } from '$components/UserLocation';
import { connect } from 'react-redux';
import { DistanceBar } from '$components/panels/DistanceBar';
type Props = {
distance: number,
estimated: number,
};
const Component = ({ distance, estimated }: Props) => (
export const TopLeftPanel = () => (
<div className="status-panel top left">
<div className="status-bar square pointer pointer">
<UserLocation />
</div>
<div className="status-bar padded desktop-only">
{distance} км&nbsp;
<Icon icon="icon-cycle" size={32} />
{
<span>{toHours(estimated)}</span>
}
</div>
<UserLocation />
<DistanceBar />
</div>
);
function mapStateToProps(state) {
const {
user: { distance, estimated },
} = state;
return { distance, estimated };
}
const mapDispatchToProps = () => ({ });
export const TopLeftPanel = connect(
mapStateToProps,
mapDispatchToProps
)(Component);