|
1 |
| -import React, { Component } from 'react'; |
| 1 | +import React from 'react'; |
| 2 | +import PropTypes from 'prop-types'; |
2 | 3 | import Action from '../components/Action';
|
3 | 4 |
|
4 |
| -class ActionContainer extends Component { |
5 |
| - constructor(props) { |
6 |
| - super(props); |
| 5 | +const ActionContainer = ({ |
| 6 | + snapshots, |
| 7 | + snapshotIndex, |
| 8 | + handleChangeSnapshot, |
| 9 | + handleJumpSnapshot, |
| 10 | + emptySnapshot, |
| 11 | +}) => { |
| 12 | + let actionsArr = []; |
| 13 | + if (snapshots.length > 0) { |
| 14 | + actionsArr = snapshots.map((snapshot, index) => { |
| 15 | + const selected = index === snapshotIndex; |
| 16 | + return ( |
| 17 | + <Action |
| 18 | + key={`action${index}`} |
| 19 | + index={index} |
| 20 | + snapshot={snapshot} |
| 21 | + selected={selected} |
| 22 | + handleChangeSnapshot={handleChangeSnapshot} |
| 23 | + handleJumpSnapshot={handleJumpSnapshot} |
| 24 | + /> |
| 25 | + ); |
| 26 | + }); |
7 | 27 | }
|
8 |
| - |
9 |
| - render() { |
10 |
| - const { |
11 |
| - snapshots, |
12 |
| - snapshotIndex, |
13 |
| - handleChangeSnapshot, |
14 |
| - handleJumpSnapshot, |
15 |
| - emptySnapshot, |
16 |
| - } = this.props; |
17 |
| - let actionsArr = []; |
18 |
| - if (snapshots.length > 0) { |
19 |
| - actionsArr = snapshots.map((snapshot, index) => { |
20 |
| - const selected = index === snapshotIndex; |
21 |
| - return ( |
22 |
| - <Action |
23 |
| - key={`action${index}`} |
24 |
| - index={index} |
25 |
| - snapshot={snapshot} |
26 |
| - selected={selected} |
27 |
| - handleChangeSnapshot={handleChangeSnapshot} |
28 |
| - handleJumpSnapshot={handleJumpSnapshot} |
29 |
| - /> |
30 |
| - ); |
31 |
| - }); |
32 |
| - } |
33 |
| - return ( |
34 |
| - <div className="action-container"> |
35 |
| - <div className="action-component"> |
36 |
| - <div className="empty-button" onClick={emptySnapshot}> |
37 |
| - emptySnapshot |
38 |
| - </div> |
| 28 | + return ( |
| 29 | + <div className="action-container"> |
| 30 | + <div className="action-component"> |
| 31 | + <div className="empty-button" onClick={emptySnapshot}> |
| 32 | + emptySnapshot |
39 | 33 | </div>
|
40 |
| - <div>{actionsArr}</div> |
41 | 34 | </div>
|
42 |
| - ); |
43 |
| - } |
44 |
| -} |
| 35 | + <div>{actionsArr}</div> |
| 36 | + </div> |
| 37 | + ); |
| 38 | +}; |
| 39 | + |
| 40 | +ActionContainer.propTypes = { |
| 41 | + snapshots: PropTypes.arrayOf( |
| 42 | + PropTypes.object, |
| 43 | + ).isRequired, |
| 44 | + snapshotIndex: PropTypes.number.isRequired, |
| 45 | + handleChangeSnapshot: PropTypes.func.isRequired, |
| 46 | + handleJumpSnapshot: PropTypes.func.isRequired, |
| 47 | + emptySnapshot: PropTypes.func.isRequired, |
| 48 | +}; |
45 | 49 |
|
46 | 50 | export default ActionContainer;
|
0 commit comments