@@ -18,7 +18,7 @@ class MainContainer extends Component {
18
18
this . state = {
19
19
snapshots : [ ] ,
20
20
sliderIndex : 0 ,
21
- viewIndex : 0 ,
21
+ viewIndex : - 1 ,
22
22
port : null ,
23
23
playing : false ,
24
24
mode : {
@@ -47,8 +47,8 @@ class MainContainer extends Component {
47
47
}
48
48
case 'initialConnectSnapshots' : {
49
49
const { snapshots, mode } = payload ;
50
- const viewIndex = 0 ;
51
- const sliderIndex = viewIndex ;
50
+ const viewIndex = - 1 ;
51
+ const sliderIndex = 0 ;
52
52
this . setState ( { snapshots, mode, viewIndex, sliderIndex } ) ;
53
53
break ;
54
54
}
@@ -114,14 +114,17 @@ class MainContainer extends Component {
114
114
115
115
emptySnapshot ( ) {
116
116
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 } ) ;
118
118
port . postMessage ( { action : 'emptySnap' } ) ;
119
119
}
120
120
121
121
// change the view index
122
122
// this will change the state shown in the state container but won't change the DOM
123
123
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 } ) ;
125
128
}
126
129
127
130
// changes the slider index
@@ -194,6 +197,10 @@ class MainContainer extends Component {
194
197
const {
195
198
snapshots, viewIndex, sliderIndex, mode, playing, playSpeed,
196
199
} = this . state ;
200
+
201
+ // if viewIndex is -1, then use the sliderIndex instead
202
+ const snapshotView = ( viewIndex === - 1 ) ? snapshots [ sliderIndex ] : snapshots [ viewIndex ] ;
203
+
197
204
return (
198
205
< div className = "main-container" >
199
206
< HeadContainer />
@@ -206,7 +213,7 @@ class MainContainer extends Component {
206
213
handleJumpSnapshot = { this . handleJumpSnapshot }
207
214
emptySnapshot = { this . emptySnapshot }
208
215
/>
209
- { ( snapshots . length ) ? < StateContainer snapshot = { snapshots [ viewIndex ] } /> : null }
216
+ { ( snapshots . length ) ? < StateContainer snapshot = { snapshotView } /> : null }
210
217
< TravelContainer
211
218
snapshotsLength = { snapshots . length }
212
219
sliderIndex = { sliderIndex }
0 commit comments