mirror of
https://github.com/muerwre/orchidmap-front.git
synced 2025-04-25 11:06:40 +07:00
moved components to TypeScript
This commit is contained in:
parent
85b8860862
commit
0a01c91271
54 changed files with 2771 additions and 5134 deletions
91
src/components/panels/DistanceBar.tsx
Normal file
91
src/components/panels/DistanceBar.tsx
Normal file
|
@ -0,0 +1,91 @@
|
|||
// flow
|
||||
import * as React from 'react';
|
||||
import { toHours } from '$utils/format';
|
||||
import { Icon } from '$components/panels/Icon';
|
||||
import { connect } from 'react-redux';
|
||||
import Slider from 'rc-slider';
|
||||
import { bindActionCreators } from 'redux';
|
||||
import { setSpeed } from '$redux/user/actions';
|
||||
import { IRootState } from "$redux/user/reducer";
|
||||
|
||||
interface Props extends IRootState {
|
||||
setSpeed: typeof setSpeed,
|
||||
}
|
||||
|
||||
interface State {
|
||||
dialogOpened: boolean,
|
||||
}
|
||||
|
||||
class Component extends React.PureComponent<Props, State> {
|
||||
constructor(props) {
|
||||
super(props);
|
||||
this.state = {
|
||||
dialogOpened: false,
|
||||
};
|
||||
}
|
||||
|
||||
step: number = 5;
|
||||
min: number = 5;
|
||||
max: number = 30;
|
||||
|
||||
marks: { [x: number]: string } = [...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)),
|
||||
}), { });
|
||||
|
||||
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) {
|
||||
const {
|
||||
user: { distance, estimated, speed },
|
||||
} = state;
|
||||
|
||||
return { distance, estimated, speed };
|
||||
}
|
||||
|
||||
const mapDispatchToProps = dispatch => bindActionCreators({
|
||||
setSpeed,
|
||||
}, dispatch);
|
||||
|
||||
export const DistanceBar = connect(
|
||||
mapStateToProps,
|
||||
mapDispatchToProps
|
||||
)(Component);
|
Loading…
Add table
Add a link
Reference in a new issue