mirror of
https://github.com/muerwre/orchidmap-front.git
synced 2025-04-25 19:16:41 +07:00
redux: fixed estimated
This commit is contained in:
parent
185fe80fc5
commit
5d2c534aa9
6 changed files with 30 additions and 38 deletions
|
@ -1,7 +1,8 @@
|
||||||
import React from 'react';
|
import React from 'react';
|
||||||
import L, { marker } from 'leaflet';
|
import { marker } from 'leaflet';
|
||||||
import { DomMarker } from '$utils/DomMarker';
|
import { DomMarker } from '$utils/DomMarker';
|
||||||
import { Icon } from '$components/panels/Icon';
|
import { Icon } from '$components/panels/Icon';
|
||||||
|
import { editor } from '$modules/Editor';
|
||||||
|
|
||||||
export class UserLocation extends React.Component {
|
export class UserLocation extends React.Component {
|
||||||
constructor(props) {
|
constructor(props) {
|
||||||
|
@ -15,7 +16,7 @@ export class UserLocation extends React.Component {
|
||||||
});
|
});
|
||||||
|
|
||||||
this.mark = null;
|
this.mark = null;
|
||||||
this.map = props.editor.map.map;
|
this.map = editor.map.map;
|
||||||
this.location = [];
|
this.location = [];
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -24,6 +25,7 @@ export class UserLocation extends React.Component {
|
||||||
}
|
}
|
||||||
|
|
||||||
getUserLocation = callback => {
|
getUserLocation = callback => {
|
||||||
|
// todo: TO SAGAS
|
||||||
if (!window.navigator || !window.navigator.geolocation) return;
|
if (!window.navigator || !window.navigator.geolocation) return;
|
||||||
|
|
||||||
window.navigator.geolocation.getCurrentPosition(position => {
|
window.navigator.geolocation.getCurrentPosition(position => {
|
||||||
|
|
|
@ -24,7 +24,7 @@ type Props = {
|
||||||
logo: String,
|
logo: String,
|
||||||
routerPoints: Number,
|
routerPoints: Number,
|
||||||
activeSticker: String,
|
activeSticker: String,
|
||||||
estimateTime: Number, // todo: implement!
|
estimated: Number, // todo: implement!
|
||||||
|
|
||||||
setMode: Function,
|
setMode: Function,
|
||||||
startEditing: Function,
|
startEditing: Function,
|
||||||
|
@ -61,7 +61,7 @@ class Component extends React.PureComponent<Props, void> {
|
||||||
|
|
||||||
render() {
|
render() {
|
||||||
const {
|
const {
|
||||||
mode, routerPoints, distance, estimateTime, activeSticker, logo, user, editing, title, address, changed,
|
mode, routerPoints, distance, estimated, activeSticker, logo, user, editing, title, address, changed,
|
||||||
} = this.props;
|
} = this.props;
|
||||||
|
|
||||||
return (
|
return (
|
||||||
|
@ -87,8 +87,8 @@ class Component extends React.PureComponent<Props, void> {
|
||||||
<Icon icon="icon-cycle" size={32} />
|
<Icon icon="icon-cycle" size={32} />
|
||||||
{
|
{
|
||||||
<span>{
|
<span>{
|
||||||
// toHours(estimateTime)
|
toHours(estimated)
|
||||||
}HOURS HERE</span>
|
}</span>
|
||||||
}
|
}
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
|
@ -184,7 +184,7 @@ function mapStateToProps(state) {
|
||||||
mode,
|
mode,
|
||||||
routerPoints,
|
routerPoints,
|
||||||
distance,
|
distance,
|
||||||
estimateTime,
|
estimated,
|
||||||
activeSticker,
|
activeSticker,
|
||||||
logo,
|
logo,
|
||||||
title,
|
title,
|
||||||
|
@ -199,7 +199,7 @@ function mapStateToProps(state) {
|
||||||
mode,
|
mode,
|
||||||
routerPoints,
|
routerPoints,
|
||||||
distance,
|
distance,
|
||||||
estimateTime,
|
estimated,
|
||||||
activeSticker,
|
activeSticker,
|
||||||
logo,
|
logo,
|
||||||
title,
|
title,
|
||||||
|
|
|
@ -91,18 +91,7 @@ export class Component extends React.PureComponent<Props, void> {
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
function mapStateToProps(state) {
|
const mapStateToProps = ({ user: { user } }) => ({ user });
|
||||||
const { user: { user } } = state;
|
const mapDispatchToProps = dispatch => bindActionCreators({ setUser, userLogout }, dispatch);
|
||||||
|
|
||||||
return { user };
|
export const UserPanel = connect(mapStateToProps, mapDispatchToProps)(Component);
|
||||||
}
|
|
||||||
|
|
||||||
const mapDispatchToProps = dispatch => bindActionCreators({
|
|
||||||
setUser,
|
|
||||||
userLogout,
|
|
||||||
}, dispatch);
|
|
||||||
|
|
||||||
export const UserPanel = connect(
|
|
||||||
mapStateToProps,
|
|
||||||
mapDispatchToProps
|
|
||||||
)(Component);
|
|
||||||
|
|
|
@ -200,21 +200,11 @@ class Component extends React.Component<Props, void> {
|
||||||
// };
|
// };
|
||||||
|
|
||||||
render() {
|
render() {
|
||||||
const { props: { user } } = this;
|
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<div>
|
<div>
|
||||||
<Fills />
|
<Fills />
|
||||||
|
<UserLocation />
|
||||||
<UserLocation editor={editor} />
|
<UserPanel />
|
||||||
|
|
||||||
<UserPanel
|
|
||||||
editor={editor}
|
|
||||||
user={user}
|
|
||||||
// setUser={this.setUser}
|
|
||||||
// userLogout={this.userLogout}
|
|
||||||
/>
|
|
||||||
|
|
||||||
<EditorPanel />
|
<EditorPanel />
|
||||||
</div>
|
</div>
|
||||||
);
|
);
|
||||||
|
@ -229,7 +219,7 @@ function mapStateToProps(state) {
|
||||||
mode,
|
mode,
|
||||||
routerPoints,
|
routerPoints,
|
||||||
totalDistance,
|
totalDistance,
|
||||||
estimateTime,
|
estimated,
|
||||||
activeSticker,
|
activeSticker,
|
||||||
logo,
|
logo,
|
||||||
title,
|
title,
|
||||||
|
@ -244,7 +234,7 @@ function mapStateToProps(state) {
|
||||||
mode,
|
mode,
|
||||||
routerPoints,
|
routerPoints,
|
||||||
totalDistance,
|
totalDistance,
|
||||||
estimateTime,
|
estimated,
|
||||||
activeSticker,
|
activeSticker,
|
||||||
logo,
|
logo,
|
||||||
title,
|
title,
|
||||||
|
|
|
@ -4,6 +4,11 @@ import { DEFAULT_USER } from '$constants/auth';
|
||||||
import { MODES } from '$constants/modes';
|
import { MODES } from '$constants/modes';
|
||||||
import { DEFAULT_LOGO } from '$constants/logos';
|
import { DEFAULT_LOGO } from '$constants/logos';
|
||||||
|
|
||||||
|
const getEstimated = distance => {
|
||||||
|
const time = (distance && (distance / 15)) || 0;
|
||||||
|
return (time && parseFloat(time.toFixed(1)));
|
||||||
|
};
|
||||||
|
|
||||||
const setUser = (state, { user }) => ({
|
const setUser = (state, { user }) => ({
|
||||||
...state,
|
...state,
|
||||||
user: {
|
user: {
|
||||||
|
@ -15,7 +20,12 @@ const setUser = (state, { user }) => ({
|
||||||
const setEditing = (state, { editing }) => ({ ...state, editing });
|
const setEditing = (state, { editing }) => ({ ...state, editing });
|
||||||
const setChanged = (state, { changed }) => ({ ...state, changed });
|
const setChanged = (state, { changed }) => ({ ...state, changed });
|
||||||
const setMode = (state, { mode }) => ({ ...state, mode });
|
const setMode = (state, { mode }) => ({ ...state, mode });
|
||||||
const setDistance = (state, { distance }) => ({ ...state, distance });
|
const setDistance = (state, { distance }) => ({
|
||||||
|
...state,
|
||||||
|
distance,
|
||||||
|
estimated: getEstimated(distance),
|
||||||
|
});
|
||||||
|
|
||||||
const setRouterPoints = (state, { routerPoints }) => ({ ...state, routerPoints });
|
const setRouterPoints = (state, { routerPoints }) => ({ ...state, routerPoints });
|
||||||
|
|
||||||
const setActiveSticker = (state, { activeSticker }) => ({ ...state, activeSticker });
|
const setActiveSticker = (state, { activeSticker }) => ({ ...state, activeSticker });
|
||||||
|
@ -43,7 +53,7 @@ export const INITIAL_STATE = {
|
||||||
logo: DEFAULT_LOGO,
|
logo: DEFAULT_LOGO,
|
||||||
routerPoints: 0,
|
routerPoints: 0,
|
||||||
distance: 0,
|
distance: 0,
|
||||||
estimateTime: 0,
|
estimated: 0,
|
||||||
activeSticker: null,
|
activeSticker: null,
|
||||||
title: 0,
|
title: 0,
|
||||||
address: '',
|
address: '',
|
||||||
|
|
|
@ -126,6 +126,7 @@ function* setLogoSaga({ logo }) {
|
||||||
yield put(setMode(MODES.NONE));
|
yield put(setMode(MODES.NONE));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
export function* userSaga() {
|
export function* userSaga() {
|
||||||
// ASYNCHRONOUS!!! :-)
|
// ASYNCHRONOUS!!! :-)
|
||||||
|
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue