Skip to content

Commit 3e4cdda

Browse files
committed
made view and slider index more like redux-dev-tools. snapshot view can be unselected now.
1 parent 26784b8 commit 3e4cdda

File tree

3 files changed

+52
-44
lines changed

3 files changed

+52
-44
lines changed

package-lock.json

Lines changed: 38 additions & 38 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

src/app/containers/ActionContainer.jsx

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -42,6 +42,7 @@ const ActionContainer = ({
4242
ActionContainer.propTypes = {
4343
snapshots: PropTypes.arrayOf(PropTypes.object).isRequired,
4444
viewIndex: PropTypes.number.isRequired,
45+
sliderIndex: PropTypes.number.isRequired,
4546
handleChangeSnapshot: PropTypes.func.isRequired,
4647
handleJumpSnapshot: PropTypes.func.isRequired,
4748
emptySnapshot: PropTypes.func.isRequired,

src/app/containers/MainContainer.jsx

Lines changed: 13 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ class MainContainer extends Component {
1818
this.state = {
1919
snapshots: [],
2020
sliderIndex: 0,
21-
viewIndex: 0,
21+
viewIndex: -1,
2222
port: null,
2323
playing: false,
2424
mode: {
@@ -47,8 +47,8 @@ class MainContainer extends Component {
4747
}
4848
case 'initialConnectSnapshots': {
4949
const { snapshots, mode } = payload;
50-
const viewIndex = 0;
51-
const sliderIndex = viewIndex;
50+
const viewIndex = -1;
51+
const sliderIndex = 0;
5252
this.setState({ snapshots, mode, viewIndex, sliderIndex });
5353
break;
5454
}
@@ -114,14 +114,17 @@ class MainContainer extends Component {
114114

115115
emptySnapshot() {
116116
const { port, snapshots } = this.state;
117-
this.setState({ snapshots: [snapshots[0]], sliderIndex: 0, viewIndex: 0 });
117+
this.setState({ snapshots: [snapshots[0]], sliderIndex: 0, viewIndex: -1 });
118118
port.postMessage({ action: 'emptySnap' });
119119
}
120120

121121
// change the view index
122122
// this will change the state shown in the state container but won't change the DOM
123123
handleChangeSnapshot(viewIndex) {
124-
this.setState({ viewIndex });
124+
const { viewIndex: oldViewIndex } = this.state;
125+
// unselect view if same index was selected
126+
if (viewIndex === oldViewIndex) this.setState({ viewIndex: -1 });
127+
else this.setState({ viewIndex });
125128
}
126129

127130
// changes the slider index
@@ -194,6 +197,10 @@ class MainContainer extends Component {
194197
const {
195198
snapshots, viewIndex, sliderIndex, mode, playing, playSpeed,
196199
} = this.state;
200+
201+
// if viewIndex is -1, then use the sliderIndex instead
202+
const snapshotView = (viewIndex === -1) ? snapshots[sliderIndex] : snapshots[viewIndex];
203+
197204
return (
198205
<div className="main-container">
199206
<HeadContainer />
@@ -206,7 +213,7 @@ class MainContainer extends Component {
206213
handleJumpSnapshot={this.handleJumpSnapshot}
207214
emptySnapshot={this.emptySnapshot}
208215
/>
209-
{(snapshots.length) ? <StateContainer snapshot={snapshots[viewIndex]} /> : null}
216+
{(snapshots.length) ? <StateContainer snapshot={snapshotView} /> : null}
210217
<TravelContainer
211218
snapshotsLength={snapshots.length}
212219
sliderIndex={sliderIndex}

0 commit comments

Comments
 (0)