Skip to content

Commit 7cf1651

Browse files
committed
merged with dev
2 parents e11a596 + d89359b commit 7cf1651

20 files changed

+4309
-124
lines changed

.gitignore

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,7 @@
11
node_modules
22
.DS_Store
3-
dist/
4-
extension/bundle.js
5-
package/react-time-travel-1.0.1.tgz
3+
src/extension/build/bundles
4+
package/react-time-travel-*.tgz
65
tictactoe
7-
tictactoe/build/bundle.js
8-
tictactoe/package-lock.json
96
parents
107
coverage

src/app/components/Action.jsx

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -12,14 +12,17 @@ const Action = (props) => {
1212
role="presentation"
1313
>
1414
<div className="action-component-text">{index}</div>
15-
<div
15+
<button
1616
className="jump-button"
17-
onClick={() => handleJumpSnapshot(index)}
17+
onClick={(e) => {
18+
e.stopPropagation();
19+
handleJumpSnapshot(index);
20+
}}
1821
tabIndex={index}
19-
role="button"
22+
type="button"
2023
>
2124
Jump
22-
</div>
25+
</button>
2326
</div>
2427
);
2528
};

src/app/components/MainSlider.jsx

Lines changed: 28 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
1-
import React, { Component } from 'react';
1+
import React from 'react';
22
import Slider from 'rc-slider';
33
import Tooltip from 'rc-tooltip';
4-
4+
import PropTypes from 'prop-types';
55

66
const { Handle } = Slider;
77

@@ -23,27 +23,31 @@ const handle = (props) => {
2323
);
2424
};
2525

26-
class mainSlider extends Component {
27-
constructor(props) {
28-
super(props);
29-
}
26+
const MainSlider = ({
27+
snapshotLength,
28+
sliderIndex,
29+
handleJumpSnapshot,
30+
pause,
31+
}) =>
32+
(
33+
<Slider
34+
min={0}
35+
max={snapshotLength - 1}
36+
value={sliderIndex}
37+
onChange={(index) => {
38+
const newIndex = index === -1 ? 0 : index;
39+
handleJumpSnapshot(newIndex);
40+
pause();
41+
}}
42+
handle={handle}
43+
/>
44+
);
3045

31-
render() {
32-
return (
33-
<Slider
34-
min={0}
35-
max={this.props.snapshotLength - 1}
36-
value={this.props.snapshotIndex}
37-
onChange={(index) => {
38-
index = index === -1 ? 0 : index;
39-
this.props.handleChangeSnapshot(index);
40-
this.props.handleJumpSnapshot(index);
41-
this.props.pause();
42-
}}
43-
handle={handle}
44-
/>
45-
);
46-
}
47-
}
46+
MainSlider.propTypes = {
47+
snapshotLength: PropTypes.number.isRequired,
48+
sliderIndex: PropTypes.number.isRequired,
49+
handleJumpSnapshot: PropTypes.func.isRequired,
50+
pause: PropTypes.func.isRequired,
51+
};
4852

49-
export default mainSlider;
53+
export default MainSlider;

src/app/components/Tree.jsx

Lines changed: 14 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,20 @@ import React from 'react';
22
import JSONTree from 'react-json-tree';
33
import PropTypes from 'prop-types';
44

5+
<<<<<<< HEAD
56
const getItemString = data => <span>{data.name}</span>;
7+
=======
8+
const getItemString = (type, data) => {
9+
// check to make sure that we are on the tree node, not anything else
10+
if (Object.keys(data).length === 3 && typeof data.state === 'object' && typeof data.name === 'string' && Array.isArray(data.children)) {
11+
return (
12+
<span>
13+
{data.name}
14+
</span>
15+
);
16+
}
17+
};
18+
>>>>>>> dev
619

720
const Tree = (props) => {
821
const { snapshot } = props;
@@ -15,7 +28,7 @@ const Tree = (props) => {
1528
shouldExpandNode={() => true}
1629
getItemString={getItemString}
1730
labelRenderer={(raw) => {
18-
if (typeof raw[0] !== 'number') return <span>{raw[0]}</span>;
31+
return (typeof raw[0] !== 'number') ? <span>{raw[0]}</span> : null;
1932
}}
2033
/>
2134
)}

src/app/containers/ActionContainer.jsx

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -4,15 +4,15 @@ import Action from '../components/Action';
44

55
const ActionContainer = ({
66
snapshots,
7-
snapshotIndex,
7+
viewIndex,
88
handleChangeSnapshot,
99
handleJumpSnapshot,
1010
emptySnapshot,
1111
}) => {
1212
let actionsArr = [];
1313
if (snapshots.length > 0) {
1414
actionsArr = snapshots.map((snapshot, index) => {
15-
const selected = index === snapshotIndex;
15+
const selected = index === viewIndex;
1616
return (
1717
<Action
1818
key={`action${index}`}
@@ -28,9 +28,9 @@ const ActionContainer = ({
2828
return (
2929
<div className="action-container">
3030
<div className="action-component exclude">
31-
<div className="empty-button" onClick={emptySnapshot}>
31+
<button className="empty-button" onClick={emptySnapshot} type="button">
3232
emptySnapshot
33-
</div>
33+
</button>
3434
</div>
3535
<div>{actionsArr}</div>
3636
</div>
@@ -41,7 +41,7 @@ ActionContainer.propTypes = {
4141
snapshots: PropTypes.arrayOf(
4242
PropTypes.object,
4343
).isRequired,
44-
snapshotIndex: PropTypes.number.isRequired,
44+
viewIndex: PropTypes.number.isRequired,
4545
handleChangeSnapshot: PropTypes.func.isRequired,
4646
handleJumpSnapshot: PropTypes.func.isRequired,
4747
emptySnapshot: PropTypes.func.isRequired,

src/app/containers/ButtonsContainer.jsx

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -8,21 +8,21 @@ const ButtonsContainer = ({
88
exportSnapshots,
99
}) => (
1010
<div className="buttons-container">
11-
<div className="pause-button" onClick={() => toggleMode('paused')}>
11+
<button className="pause-button" type="button" onClick={() => toggleMode('paused')}>
1212
{paused ? 'Resume' : 'Pause'}
13-
</div>
14-
<div className="lock-button" onClick={() => toggleMode('locked')}>
13+
</button>
14+
<button className="lock-button" type="button" onClick={() => toggleMode('locked')}>
1515
{locked ? 'Unlock' : 'Lock'}
16-
</div>
17-
<div className="persist-button" onClick={() => toggleMode('persist')}>
16+
</button>
17+
<button className="persist-button" type="button" onClick={() => toggleMode('persist')}>
1818
{persist ? 'Unpersist' : 'Persist'}
19-
</div>
20-
<div className="import-button" onClick={importSnapshots}>
19+
</button>
20+
<button className="import-button" type="button" onClick={importSnapshots}>
2121
Import
22-
</div>
23-
<div className="export-button" onClick={exportSnapshots}>
22+
</button>
23+
<button className="export-button" type="button" onClick={exportSnapshots}>
2424
Export
25-
</div>
25+
</button>
2626
</div>
2727
);
2828

src/app/containers/MainContainer.jsx

Lines changed: 32 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,8 @@ class MainContainer extends Component {
1717

1818
this.state = {
1919
snapshots: [],
20-
snapshotIndex: 0,
20+
sliderIndex: 0,
21+
viewIndex: 0,
2122
port: null,
2223
playing: false,
2324
mode: {
@@ -39,15 +40,16 @@ class MainContainer extends Component {
3940
const { action, payload } = message;
4041
switch (action) {
4142
case 'sendSnapshots': {
42-
const snapshotIndex = payload.length - 1;
43+
const sliderIndex = payload.length - 1;
4344
// set state with the information received from the background script
44-
this.setState({ snapshots: payload, snapshotIndex });
45+
this.setState({ snapshots: payload, sliderIndex });
4546
break;
4647
}
4748
case 'initialConnectSnapshots': {
4849
const { snapshots, mode } = payload;
49-
const snapshotIndex = snapshots.length - 1;
50-
this.setState({ snapshots, snapshotIndex, mode });
50+
const viewIndex = 0;
51+
const sliderIndex = viewIndex;
52+
this.setState({ snapshots, mode, viewIndex, sliderIndex });
5153
break;
5254
}
5355
default:
@@ -64,21 +66,21 @@ class MainContainer extends Component {
6466
}
6567

6668
moveBackward() {
67-
const { snapshots, snapshotIndex } = this.state;
69+
const { snapshots, sliderIndex } = this.state;
6870
this.pause();
69-
if (snapshots.length > 0 && snapshotIndex > 0) {
70-
const newIndex = snapshotIndex - 1;
71+
if (snapshots.length > 0 && sliderIndex > 0) {
72+
const newIndex = sliderIndex - 1;
7173
// second callback parameter of setState to invoke handleJumpSnapshot
72-
this.setState({ snapshotIndex: newIndex }, this.handleJumpSnapshot(newIndex));
74+
this.setState({ sliderIndex: newIndex }, this.handleJumpSnapshot(newIndex));
7375
}
7476
}
7577

7678
moveForward() {
77-
const { snapshots, snapshotIndex } = this.state;
79+
const { snapshots, sliderIndex } = this.state;
7880
this.pause();
79-
if (snapshotIndex < snapshots.length - 1) {
80-
const newIndex = snapshotIndex + 1;
81-
this.setState({ snapshotIndex: newIndex }, this.handleJumpSnapshot(newIndex));
81+
if (sliderIndex < snapshots.length - 1) {
82+
const newIndex = sliderIndex + 1;
83+
this.setState({ sliderIndex: newIndex }, this.handleJumpSnapshot(newIndex));
8284
}
8385
}
8486

@@ -88,10 +90,10 @@ class MainContainer extends Component {
8890
const { playing } = this.state;
8991
if (playing) {
9092
intervalId = setInterval(() => {
91-
const { snapshots, snapshotIndex } = this.state;
92-
if (snapshotIndex < snapshots.length - 1) {
93-
const newIndex = snapshotIndex + 1;
94-
this.setState({ snapshotIndex: newIndex }, this.handleJumpSnapshot(newIndex));
93+
const { snapshots, sliderIndex } = this.state;
94+
if (sliderIndex < snapshots.length - 1) {
95+
const newIndex = sliderIndex + 1;
96+
this.setState({ sliderIndex: newIndex }, this.handleJumpSnapshot(newIndex));
9597
} else {
9698
// clear interval when play reaches the end
9799
globalPlaying = false;
@@ -112,22 +114,22 @@ class MainContainer extends Component {
112114

113115
emptySnapshot() {
114116
const { port, snapshots } = this.state;
115-
this.setState({ snapshots: [snapshots[0]], snapshotIndex: 0 });
117+
this.setState({ snapshots: [snapshots[0]], sliderIndex: 0, viewIndex: 0 });
116118
port.postMessage({ action: 'emptySnap' });
117119
}
118120

119-
// change the snapshot index
121+
// change the view index
120122
// this will change the state shown in the state container but won't change the DOM
121-
handleChangeSnapshot(snapshotIndex) {
122-
// snapshotIndex
123-
// --> 1. affects the action that is highlighted
124-
// --> 2. moves the slider
125-
this.setState({ snapshotIndex });
123+
handleChangeSnapshot(viewIndex) {
124+
this.setState({ viewIndex });
126125
}
127126

128-
handleJumpSnapshot(snapshotIndex) {
127+
// changes the slider index
128+
// this will change the dom but not the state shown in the state container
129+
handleJumpSnapshot(sliderIndex) {
129130
const { snapshots, port } = this.state;
130-
port.postMessage({ action: 'jumpToSnap', payload: snapshots[snapshotIndex] });
131+
port.postMessage({ action: 'jumpToSnap', payload: snapshots[sliderIndex] });
132+
this.setState({ sliderIndex });
131133
}
132134

133135
importSnapshots() {
@@ -190,24 +192,23 @@ class MainContainer extends Component {
190192

191193
render() {
192194
const {
193-
snapshots, snapshotIndex, mode, playing, playSpeed,
195+
snapshots, viewIndex, sliderIndex, mode, playing, playSpeed,
194196
} = this.state;
195197
return (
196198
<div className="main-container">
197199
<HeadContainer />
198200
<div className="body-container">
199201
<ActionContainer
200202
snapshots={snapshots}
201-
snapshotIndex={snapshotIndex}
203+
viewIndex={viewIndex}
202204
handleChangeSnapshot={this.handleChangeSnapshot}
203205
handleJumpSnapshot={this.handleJumpSnapshot}
204206
emptySnapshot={this.emptySnapshot}
205207
/>
206-
{(snapshots.length) ? <StateContainer snapshot={snapshots[snapshotIndex]} /> : null}
208+
{(snapshots.length) ? <StateContainer snapshot={snapshots[viewIndex]} /> : null}
207209
<TravelContainer
208210
snapshotsLength={snapshots.length}
209-
snapshotIndex={snapshotIndex}
210-
handleChangeSnapshot={this.handleChangeSnapshot}
211+
sliderIndex={sliderIndex}
211212
handleJumpSnapshot={this.handleJumpSnapshot}
212213
moveBackward={this.moveBackward}
213214
moveForward={this.moveForward}

src/app/containers/TravelContainer.jsx

Lines changed: 9 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -27,32 +27,30 @@ class TravelContainer extends Component {
2727
moveBackward,
2828
moveForward,
2929
snapshotsLength,
30-
handleChangeSnapshot,
3130
handleJumpSnapshot,
32-
snapshotIndex,
31+
sliderIndex,
3332
play,
3433
playing,
3534
pause,
3635
} = this.props;
3736

3837
return (
3938
<div className="travel-container">
40-
<div className="play-button" onClick={() => play(playSpeed)}>
39+
<button className="play-button" onClick={() => play(playSpeed)} type="button">
4140
{playing ? 'Pause' : 'Play'}
42-
</div>
41+
</button>
4342
<MainSlider
4443
snapshotLength={snapshotsLength}
45-
handleChangeSnapshot={handleChangeSnapshot}
46-
snapshotIndex={snapshotIndex}
44+
sliderIndex={sliderIndex}
4745
handleJumpSnapshot={handleJumpSnapshot}
4846
pause={pause}
4947
/>
50-
<div className="backward-button" role="button" onClick={moveBackward}>
48+
<button className="backward-button" onClick={moveBackward} type="button">
5149
{'<'}
52-
</div>
53-
<div className="forward-button" role="button" onClick={moveForward}>
50+
</button>
51+
<button className="forward-button" onClick={moveForward} type="button">
5452
{'>'}
55-
</div>
53+
</button>
5654
<Dropdown
5755
options={options}
5856
selectedOption={selectedOption}
@@ -69,9 +67,8 @@ TravelContainer.propTypes = {
6967
moveBackward: PropTypes.func.isRequired,
7068
moveForward: PropTypes.func.isRequired,
7169
snapshotsLength: PropTypes.number.isRequired,
72-
handleChangeSnapshot: PropTypes.func.isRequired,
7370
handleJumpSnapshot: PropTypes.func.isRequired,
74-
snapshotIndex: PropTypes.number.isRequired,
71+
sliderIndex: PropTypes.number.isRequired,
7572
playing: PropTypes.bool.isRequired,
7673
};
7774
export default TravelContainer;

0 commit comments

Comments
 (0)