mirror of
https://github.com/muerwre/orchidmap-front.git
synced 2025-04-25 11:06:40 +07:00
riding speed slider
This commit is contained in:
parent
3e16ad4e37
commit
c3ed100105
7 changed files with 91 additions and 19 deletions
|
@ -3,31 +3,88 @@ import React from 'react';
|
||||||
import { toHours } from '$utils/format';
|
import { toHours } from '$utils/format';
|
||||||
import { Icon } from '$components/panels/Icon';
|
import { Icon } from '$components/panels/Icon';
|
||||||
import { connect } from 'react-redux';
|
import { connect } from 'react-redux';
|
||||||
|
import Slider from 'rc-slider';
|
||||||
|
import { bindActionCreators } from 'redux';
|
||||||
|
import { setSpeed } from '$redux/user/actions';
|
||||||
|
|
||||||
type Props = {
|
type Props = {
|
||||||
distance: number,
|
distance: number,
|
||||||
estimated: number,
|
estimated: number,
|
||||||
|
speed: number,
|
||||||
|
setSpeed: Function,
|
||||||
};
|
};
|
||||||
|
|
||||||
const Component = ({ distance, estimated }: Props) => (
|
type State = {
|
||||||
<div className="status-bar padded desktop-only">
|
dialogOpened: boolean,
|
||||||
{distance} км
|
}
|
||||||
<Icon icon="icon-cycle" size={32} />
|
class Component extends React.PureComponent<Props, State> {
|
||||||
{
|
constructor(props) {
|
||||||
<span>{toHours(estimated)}</span>
|
super(props);
|
||||||
}
|
this.step = 5;
|
||||||
</div>
|
this.min = 5;
|
||||||
);
|
this.max = 30;
|
||||||
|
|
||||||
|
this.marks = [...Array((Math.floor(this.max - this.min) / this.step) + 1)].reduce((obj, el, index) => ({
|
||||||
|
...obj,
|
||||||
|
[this.min + (index * this.step)]: String(this.min + (index * this.step)),
|
||||||
|
}), { });
|
||||||
|
|
||||||
|
this.state = {
|
||||||
|
dialogOpened: false,
|
||||||
|
};
|
||||||
|
}
|
||||||
|
|
||||||
|
toggleDialog = () => this.setState({ dialogOpened: !this.state.dialogOpened });
|
||||||
|
|
||||||
|
render() {
|
||||||
|
const {
|
||||||
|
props: { distance, estimated, speed },
|
||||||
|
state: { dialogOpened },
|
||||||
|
min, max, step, marks,
|
||||||
|
} = this;
|
||||||
|
|
||||||
|
|
||||||
|
return (
|
||||||
|
<React.Fragment>
|
||||||
|
<div className="status-bar padded desktop-only pointer" onClick={this.toggleDialog}>
|
||||||
|
{distance} км
|
||||||
|
<Icon icon="icon-cycle" size={32} />
|
||||||
|
{
|
||||||
|
<span>{toHours(estimated)}</span>
|
||||||
|
}
|
||||||
|
</div>
|
||||||
|
{
|
||||||
|
dialogOpened &&
|
||||||
|
<div className="control-dialog top left" style={{ left: 0, top: 42 }}>
|
||||||
|
<div className="helper speed-helper">
|
||||||
|
<Slider
|
||||||
|
min={min}
|
||||||
|
max={max}
|
||||||
|
step={step}
|
||||||
|
onChange={this.props.setSpeed}
|
||||||
|
defaultValue={15}
|
||||||
|
value={speed}
|
||||||
|
marks={marks}
|
||||||
|
/>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
}
|
||||||
|
</React.Fragment>
|
||||||
|
);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
function mapStateToProps(state) {
|
function mapStateToProps(state) {
|
||||||
const {
|
const {
|
||||||
user: { distance, estimated },
|
user: { distance, estimated, speed },
|
||||||
} = state;
|
} = state;
|
||||||
|
|
||||||
return { distance, estimated };
|
return { distance, estimated, speed };
|
||||||
}
|
}
|
||||||
|
|
||||||
const mapDispatchToProps = () => ({ });
|
const mapDispatchToProps = dispatch => bindActionCreators({
|
||||||
|
setSpeed,
|
||||||
|
}, dispatch);
|
||||||
|
|
||||||
export const DistanceBar = connect(
|
export const DistanceBar = connect(
|
||||||
mapStateToProps,
|
mapStateToProps,
|
||||||
|
|
|
@ -3,7 +3,6 @@
|
||||||
todo save spinner
|
todo save spinner
|
||||||
todo cancelling editing someone's else map return back to it's original address /razminochnyj/
|
todo cancelling editing someone's else map return back to it's original address /razminochnyj/
|
||||||
|
|
||||||
todo riding speed slider
|
|
||||||
todo public maps
|
todo public maps
|
||||||
todo editing map on map list
|
todo editing map on map list
|
||||||
todo setting map public on map list
|
todo setting map public on map list
|
||||||
|
@ -29,6 +28,7 @@
|
||||||
|
|
||||||
OBLIVION STARTS HERE:
|
OBLIVION STARTS HERE:
|
||||||
|
|
||||||
|
done riding speed slider
|
||||||
done dont close map list on click
|
done dont close map list on click
|
||||||
done fix loaded stickers has wrong text placement for right-sided captions
|
done fix loaded stickers has wrong text placement for right-sided captions
|
||||||
done fix save button should not react to clicks
|
done fix save button should not react to clicks
|
||||||
|
|
|
@ -11,7 +11,7 @@ import { locationChanged } from '$redux/user/actions';
|
||||||
|
|
||||||
const userPersistConfig = {
|
const userPersistConfig = {
|
||||||
key: 'user',
|
key: 'user',
|
||||||
whitelist: ['user', 'logo', 'provider'],
|
whitelist: ['user', 'logo', 'provider', 'speed'],
|
||||||
storage,
|
storage,
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
|
@ -14,6 +14,7 @@ export const setLogo = logo => ({ type: ACTIONS.SET_LOGO, logo });
|
||||||
export const setTitle = title => ({ type: ACTIONS.SET_TITLE, title });
|
export const setTitle = title => ({ type: ACTIONS.SET_TITLE, title });
|
||||||
export const setAddress = address => ({ type: ACTIONS.SET_ADDRESS, address });
|
export const setAddress = address => ({ type: ACTIONS.SET_ADDRESS, address });
|
||||||
export const setPublic = is_public => ({ type: ACTIONS.SET_PUBLIC, is_public });
|
export const setPublic = is_public => ({ type: ACTIONS.SET_PUBLIC, is_public });
|
||||||
|
export const setSpeed = speed => ({ type: ACTIONS.SET_SPEED, speed });
|
||||||
|
|
||||||
export const startEditing = () => ({ type: ACTIONS.START_EDITING });
|
export const startEditing = () => ({ type: ACTIONS.START_EDITING });
|
||||||
export const stopEditing = () => ({ type: ACTIONS.STOP_EDITING });
|
export const stopEditing = () => ({ type: ACTIONS.STOP_EDITING });
|
||||||
|
|
|
@ -60,4 +60,5 @@ export const ACTIONS = ({
|
||||||
SEARCH_SET_LOADING: 'SEARCH_SET_LOADING',
|
SEARCH_SET_LOADING: 'SEARCH_SET_LOADING',
|
||||||
|
|
||||||
OPEN_MAP_DIALOG: 'OPEN_MAP_DIALOG',
|
OPEN_MAP_DIALOG: 'OPEN_MAP_DIALOG',
|
||||||
|
SET_SPEED: 'SET_SPEED',
|
||||||
}: { [key: String]: String });
|
}: { [key: String]: String });
|
||||||
|
|
|
@ -8,8 +8,8 @@ import { TIPS } from '$constants/tips';
|
||||||
import { DEFAULT_PROVIDER } from '$constants/providers';
|
import { DEFAULT_PROVIDER } from '$constants/providers';
|
||||||
import { DIALOGS, TABS } from '$constants/dialogs';
|
import { DIALOGS, TABS } from '$constants/dialogs';
|
||||||
|
|
||||||
const getEstimated = distance => {
|
const getEstimated = (distance, speed = 15) => {
|
||||||
const time = (distance && (distance / 15)) || 0;
|
const time = (distance && (distance / speed)) || 0;
|
||||||
return (time && parseFloat(time.toFixed(1)));
|
return (time && parseFloat(time.toFixed(1)));
|
||||||
};
|
};
|
||||||
|
|
||||||
|
@ -27,7 +27,7 @@ const setMode = (state, { mode }) => ({ ...state, mode });
|
||||||
const setDistance = (state, { distance }) => ({
|
const setDistance = (state, { distance }) => ({
|
||||||
...state,
|
...state,
|
||||||
distance,
|
distance,
|
||||||
estimated: getEstimated(distance),
|
estimated: getEstimated(distance, state.speed),
|
||||||
});
|
});
|
||||||
|
|
||||||
const setRouterPoints = (state, { routerPoints }) => ({ ...state, routerPoints });
|
const setRouterPoints = (state, { routerPoints }) => ({ ...state, routerPoints });
|
||||||
|
@ -152,9 +152,11 @@ const searchSetLoading = (state, { loading = false }) => ({
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
const setPublic = (state, { is_public = false }) => ({
|
const setPublic = (state, { is_public = false }) => ({ ...state, is_public });
|
||||||
|
const setSpeed = (state, { speed = 15 }) => ({
|
||||||
...state,
|
...state,
|
||||||
is_public,
|
speed,
|
||||||
|
estimated: getEstimated(state.distance, speed),
|
||||||
});
|
});
|
||||||
|
|
||||||
const HANDLERS = ({
|
const HANDLERS = ({
|
||||||
|
@ -191,6 +193,7 @@ const HANDLERS = ({
|
||||||
[ACTIONS.SEARCH_PUT_ROUTES]: searchPutRoutes,
|
[ACTIONS.SEARCH_PUT_ROUTES]: searchPutRoutes,
|
||||||
[ACTIONS.SEARCH_SET_LOADING]: searchSetLoading,
|
[ACTIONS.SEARCH_SET_LOADING]: searchSetLoading,
|
||||||
[ACTIONS.SET_PUBLIC]: setPublic,
|
[ACTIONS.SET_PUBLIC]: setPublic,
|
||||||
|
[ACTIONS.SET_SPEED]: setSpeed,
|
||||||
}: { [key: String]: Function });
|
}: { [key: String]: Function });
|
||||||
|
|
||||||
export const INITIAL_STATE = {
|
export const INITIAL_STATE = {
|
||||||
|
@ -202,6 +205,7 @@ export const INITIAL_STATE = {
|
||||||
routerPoints: 0,
|
routerPoints: 0,
|
||||||
distance: 0,
|
distance: 0,
|
||||||
estimated: 0,
|
estimated: 0,
|
||||||
|
speed: 15,
|
||||||
activeSticker: { set: null, sticker: null },
|
activeSticker: { set: null, sticker: null },
|
||||||
title: '',
|
title: '',
|
||||||
address: '',
|
address: '',
|
||||||
|
|
|
@ -494,3 +494,12 @@
|
||||||
.dialog-prefetch-progress {
|
.dialog-prefetch-progress {
|
||||||
padding: 10px 0 5px;
|
padding: 10px 0 5px;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
.speed-helper {
|
||||||
|
width: 300px;
|
||||||
|
padding: 0 20px;
|
||||||
|
|
||||||
|
.rc-slider {
|
||||||
|
width: 100%;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue