|
1 |
| -import React, { Component } from 'react'; |
| 1 | +import React, { useState } from 'react'; |
2 | 2 | import PropTypes from 'prop-types';
|
3 | 3 | import MainSlider from '../components/MainSlider';
|
4 | 4 | import Dropdown from '../components/Dropdown';
|
5 | 5 |
|
6 |
| -const options = [ |
| 6 | +const speeds = [ |
7 | 7 | { value: 2000, label: '0.5x' },
|
8 | 8 | { value: 1000, label: '1.0x' },
|
9 | 9 | { value: 500, label: '2.0x' },
|
10 | 10 | ];
|
11 | 11 |
|
12 |
| -class TravelContainer extends Component { |
13 |
| - constructor(props) { |
14 |
| - super(props); |
15 |
| - this.state = { selectedOption: options[1] }; |
16 |
| - this.handleChangeSpeed = this.handleChangeSpeed.bind(this); |
17 |
| - } |
| 12 | +const TravelContainer = (props) => { |
| 13 | + const [selectedSpeed, setSpeed] = useState(speeds[1]); |
18 | 14 |
|
19 |
| - handleChangeSpeed(selectedOption) { |
20 |
| - this.setState({ selectedOption }); |
21 |
| - } |
| 15 | + const { |
| 16 | + moveBackward, |
| 17 | + moveForward, |
| 18 | + snapshotsLength, |
| 19 | + handleJumpSnapshot, |
| 20 | + sliderIndex, |
| 21 | + play, |
| 22 | + playing, |
| 23 | + pause, |
| 24 | + } = props; |
22 | 25 |
|
23 |
| - render() { |
24 |
| - const { selectedOption } = this.state; |
25 |
| - const { |
26 |
| - moveBackward, |
27 |
| - moveForward, |
28 |
| - snapshotsLength, |
29 |
| - handleJumpSnapshot, |
30 |
| - sliderIndex, |
31 |
| - play, |
32 |
| - playing, |
33 |
| - pause, |
34 |
| - } = this.props; |
35 |
| - |
36 |
| - return ( |
37 |
| - <div className="travel-container"> |
38 |
| - <button className="play-button" type="button" onClick={() => play(selectedOption.value)}> |
39 |
| - {playing ? 'Pause' : 'Play'} |
40 |
| - </button> |
41 |
| - <MainSlider |
42 |
| - snapshotLength={snapshotsLength} |
43 |
| - sliderIndex={sliderIndex} |
44 |
| - handleJumpSnapshot={handleJumpSnapshot} |
45 |
| - pause={pause} |
46 |
| - /> |
47 |
| - <button className="backward-button" onClick={moveBackward} type="button"> |
48 |
| - {'<'} |
49 |
| - </button> |
50 |
| - <button className="forward-button" onClick={moveForward} type="button"> |
51 |
| - {'>'} |
52 |
| - </button> |
53 |
| - <Dropdown |
54 |
| - options={options} |
55 |
| - selectedOption={selectedOption} |
56 |
| - handleChangeSpeed={this.handleChangeSpeed} |
57 |
| - /> |
58 |
| - </div> |
59 |
| - ); |
60 |
| - } |
| 26 | + return ( |
| 27 | + <div className="travel-container"> |
| 28 | + <button className="play-button" type="button" onClick={() => play(selectedSpeed.value)}> |
| 29 | + {playing ? 'Pause' : 'Play'} |
| 30 | + </button> |
| 31 | + <MainSlider |
| 32 | + snapshotLength={snapshotsLength} |
| 33 | + sliderIndex={sliderIndex} |
| 34 | + handleJumpSnapshot={handleJumpSnapshot} |
| 35 | + pause={pause} |
| 36 | + /> |
| 37 | + <button className="backward-button" onClick={moveBackward} type="button"> |
| 38 | + {'<'} |
| 39 | + </button> |
| 40 | + <button className="forward-button" onClick={moveForward} type="button"> |
| 41 | + {'>'} |
| 42 | + </button> |
| 43 | + <Dropdown |
| 44 | + speeds={speeds} |
| 45 | + selectedSpeed={selectedSpeed} |
| 46 | + setSpeed={setSpeed} |
| 47 | + /> |
| 48 | + </div> |
| 49 | + ); |
61 | 50 | }
|
62 | 51 |
|
| 52 | + |
63 | 53 | TravelContainer.propTypes = {
|
64 | 54 | pause: PropTypes.func.isRequired,
|
65 | 55 | play: PropTypes.func.isRequired,
|
|
0 commit comments