Skip to content

Commit 217ddb1

Browse files
committed
added snapshotIndex and handler function
1 parent 1789b06 commit 217ddb1

File tree

4 files changed

+33
-16
lines changed

4 files changed

+33
-16
lines changed

extension/app/components/Action.jsx

Lines changed: 9 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2,12 +2,17 @@ import React, { Component } from 'react';
22
import PropTypes from 'prop-types';
33

44
const Action = (props) => {
5-
const { snapshot, selected } = props;
6-
console.log(selected);
5+
const {
6+
snapshot, selected, handleChangeSnapshot, index,
7+
} = props;
78
return (
8-
<div className="action-component">
9+
<div
10+
className={selected ? 'action-component selected' : 'action-component'}
11+
onClick={() => {
12+
handleChangeSnapshot(index);
13+
}}
14+
>
915
{snapshot.state}
10-
{' '}
1116
{selected.toString()}
1217
</div>
1318
);

extension/app/containers/ActionContainer.jsx

Lines changed: 10 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -7,13 +7,20 @@ class ActionContainer extends Component {
77
}
88

99
render() {
10-
const { snapshots, snapshotIndex } = this.props;
10+
const { snapshots, snapshotIndex, handleChangeSnapshot } = this.props;
1111
let actionsArr = [];
1212
if (snapshots) {
1313
actionsArr = snapshots.map((snapshot, index) => {
1414
const selected = index === snapshotIndex;
15-
console.log(selected);
16-
return <Action key={`action${index}`} snapshot={snapshot} selected={selected} />;
15+
return (
16+
<Action
17+
key={`action${index}`}
18+
index={index}
19+
snapshot={snapshot}
20+
selected={selected}
21+
handleChangeSnapshot={handleChangeSnapshot}
22+
/>
23+
);
1724
});
1825
}
1926
return <div className="action-container">{actionsArr}</div>;

extension/app/containers/MainContainer.jsx

Lines changed: 10 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,10 @@ import TravelContainer from './TravelContainer';
77
class MainContainer extends Component {
88
constructor() {
99
super();
10-
this.state = { snapshots: [], snapshotIndex: 0 };
10+
this.state = {
11+
snapshots: [{ state: 'snapshot1' }, { state: 'snapshot2' }, { state: 'snapshot3' }],
12+
snapshotIndex: 0,
13+
};
1114

1215
this.handleChangeSnapshot = this.handleChangeSnapshot.bind(this);
1316
}
@@ -24,16 +27,10 @@ class MainContainer extends Component {
2427
// },
2528
// false,
2629
// );
27-
28-
// MOCK DATA -- FOR TESTING PURPOSES ONLY
29-
this.setState({
30-
snapshots: [{ state: 'snapshot1' }, { state: 'snapshot2' }, { state: 'snapshot3' }],
31-
snapshotIndex: 1,
32-
});
3330
}
3431

3532
handleChangeSnapshot(snapshotIndex) {
36-
console.log('handleChangeSnapshot');
33+
console.log('handleChangeSnapshot', snapshotIndex);
3734
// change snapshotIndex
3835
// snapshotIndex could be changed from either the ActionContainer or the TravelContainer
3936
this.setState({ snapshotIndex });
@@ -46,7 +43,11 @@ class MainContainer extends Component {
4643
<div className="main-container">
4744
<HeadContainer />
4845
<div className="body-container">
49-
<ActionContainer snapshots={snapshots} snapshotIndex={snapshotIndex} />
46+
<ActionContainer
47+
snapshots={snapshots}
48+
snapshotIndex={snapshotIndex}
49+
handleChangeSnapshot={this.handleChangeSnapshot}
50+
/>
5051
<StateContainer snapshot={snapshots[snapshotIndex]} />
5152
</div>
5253
<TravelContainer />

extension/app/styles/styles.css

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -58,3 +58,7 @@
5858
border-width: thin;
5959
cursor: pointer;
6060
}
61+
62+
.action-component.selected {
63+
background-color: rgb(134, 134, 134);
64+
}

0 commit comments

Comments
 (0)