Skip to content

Commit bb8bbf1

Browse files
authored
Merge pull request #8 from oslabs-beta/josh/statecontainer
Josh/statecontainer
2 parents 4245ed3 + 217ddb1 commit bb8bbf1

File tree

7 files changed

+212
-25
lines changed

7 files changed

+212
-25
lines changed

extension/app/components/Action.jsx

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

44
const Action = (props) => {
5-
const { snapshot } = props;
6-
return <div className="action-component">{snapshot.state}</div>;
5+
const {
6+
snapshot, selected, handleChangeSnapshot, index,
7+
} = props;
8+
return (
9+
<div
10+
className={selected ? 'action-component selected' : 'action-component'}
11+
onClick={() => {
12+
handleChangeSnapshot(index);
13+
}}
14+
>
15+
{snapshot.state}
16+
{selected.toString()}
17+
</div>
18+
);
719
};
820

921
Action.propTypes = {

extension/app/containers/ActionContainer.jsx

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

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

extension/app/containers/MainContainer.jsx

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

1318
componentDidMount() {
@@ -22,22 +27,28 @@ class MainContainer extends Component {
2227
// },
2328
// false,
2429
// );
30+
}
2531

26-
// MOCK DATA -- FOR TESTING PURPOSES ONLY
27-
this.setState({
28-
snapshots: [{ state: 'snapshot1' }, { state: 'snapshot2' }, { state: 'snapshot3' }],
29-
});
32+
handleChangeSnapshot(snapshotIndex) {
33+
console.log('handleChangeSnapshot', snapshotIndex);
34+
// change snapshotIndex
35+
// snapshotIndex could be changed from either the ActionContainer or the TravelContainer
36+
this.setState({ snapshotIndex });
3037
}
3138

3239
render() {
33-
const { snapshots } = this.state;
40+
const { snapshots, snapshotIndex } = this.state;
3441

3542
return (
3643
<div className="main-container">
3744
<HeadContainer />
3845
<div className="body-container">
39-
<ActionContainer snapshots={snapshots} />
40-
<StateContainer />
46+
<ActionContainer
47+
snapshots={snapshots}
48+
snapshotIndex={snapshotIndex}
49+
handleChangeSnapshot={this.handleChangeSnapshot}
50+
/>
51+
<StateContainer snapshot={snapshots[snapshotIndex]} />
4152
</div>
4253
<TravelContainer />
4354
</div>

extension/app/containers/StateContainer.jsx

Lines changed: 14 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,23 @@
11
import React, { Component } from 'react';
2+
import ReactJson from 'react-json-view';
23

34
class StateContainer extends Component {
4-
constructor() {
5-
super();
5+
constructor(props) {
6+
super(props);
67
}
78

89
render() {
9-
return <div className="state-container">StateContainer</div>;
10+
const { snapshot } = this.props;
11+
return (
12+
<div className="state-container">
13+
<ReactJson
14+
enableClipboard={false}
15+
theme="solarized"
16+
groupArraysAfterLength={50}
17+
src={snapshot}
18+
/>
19+
</div>
20+
);
1021
}
1122
}
1223

extension/app/styles/styles.css

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,9 @@
2121
}
2222

2323
.state-container {
24+
font-size: 15px;
2425
flex: 7 auto;
26+
background-color: rgb(0, 43, 54);
2527
}
2628

2729
/* if extension width is less than 500px, stack the body containers */
@@ -54,4 +56,9 @@
5456
background-color: rgb(170, 170, 170);
5557
border-style: solid;
5658
border-width: thin;
59+
cursor: pointer;
60+
}
61+
62+
.action-component.selected {
63+
background-color: rgb(134, 134, 134);
5764
}

0 commit comments

Comments
 (0)