@@ -39,12 +39,11 @@ class MainContainer extends Component {
39
39
switch ( action ) {
40
40
case 'sendSnapshots' : {
41
41
const snapshotIndex = payload . length - 1 ;
42
-
43
42
// set state with the information received from the background script
44
43
this . setState ( { snapshots : payload , snapshotIndex } ) ;
45
44
break ;
46
45
}
47
- case 'initialConnectSnapshot ' : {
46
+ case 'initialConnectSnapshots ' : {
48
47
const { snapshots, mode } = payload ;
49
48
const snapshotIndex = snapshots . length - 1 ;
50
49
this . setState ( { snapshots, snapshotIndex, mode } ) ;
@@ -69,7 +68,7 @@ class MainContainer extends Component {
69
68
if ( snapshots . length > 0 && snapshotIndex > 0 ) {
70
69
const newIndex = snapshotIndex - 1 ;
71
70
// second callback parameter of setState to invoke handleJumpSnapshot
72
- this . setState ( { snapshotIndex : newIndex } , this . handleJumpSnapshot ( newIndex ) ) ;
71
+ this . setState ( { snapshotIndex : newIndex } , this . handleJumpSnapshot ( newIndex ) ) ;
73
72
}
74
73
}
75
74
@@ -78,34 +77,34 @@ class MainContainer extends Component {
78
77
this . pause ( ) ;
79
78
if ( snapshotIndex < snapshots . length - 1 ) {
80
79
const newIndex = snapshotIndex + 1 ;
81
- this . setState ( { snapshotIndex : newIndex } , this . handleJumpSnapshot ( newIndex ) ) ;
80
+ this . setState ( { snapshotIndex : newIndex } , this . handleJumpSnapshot ( newIndex ) ) ;
82
81
}
83
82
}
84
83
85
84
play ( ) {
86
- globalPlaying = ! globalPlaying
87
- this . setState ( { playing : globalPlaying } , ( ) => {
88
- if ( this . state . playing ) {
85
+ globalPlaying = ! globalPlaying ;
86
+ this . setState ( { playing : globalPlaying } , ( ) => {
87
+ if ( this . state . playing ) {
89
88
intervalId = setInterval ( ( ) => {
90
89
const { snapshots, snapshotIndex } = this . state ;
91
- if ( snapshotIndex < snapshots . length - 1 ) {
92
- const newIndex = snapshotIndex + 1 ;
93
- this . setState ( { snapshotIndex : newIndex } , this . handleJumpSnapshot ( newIndex ) ) ;
94
- } else {
95
- // clear interval when play reaches the end
96
- globalPlaying = false ;
97
- clearInterval ( intervalId ) ;
98
- this . setState ( { playing : false } )
99
- }
90
+ if ( snapshotIndex < snapshots . length - 1 ) {
91
+ const newIndex = snapshotIndex + 1 ;
92
+ this . setState ( { snapshotIndex : newIndex } , this . handleJumpSnapshot ( newIndex ) ) ;
93
+ } else {
94
+ // clear interval when play reaches the end
95
+ globalPlaying = false ;
96
+ clearInterval ( intervalId ) ;
97
+ this . setState ( { playing : false } )
98
+ }
100
99
} , 1000 ) ;
101
100
} else {
102
101
clearInterval ( intervalId ) ;
103
102
}
104
- } )
103
+ } ) ;
105
104
}
106
105
107
106
pause ( ) {
108
- this . setState ( { playing : false } , clearInterval ( intervalId ) )
107
+ this . setState ( { playing : false } , clearInterval ( intervalId ) ) ;
109
108
}
110
109
111
110
emptySnapshot ( ) {
@@ -161,7 +160,7 @@ class MainContainer extends Component {
161
160
handleJumpSnapshot = { this . handleJumpSnapshot }
162
161
emptySnapshot = { this . emptySnapshot }
163
162
/>
164
- < StateContainer snapshot = { snapshots [ snapshotIndex ] } />
163
+ { ( snapshots . length ) ? < StateContainer snapshot = { snapshots [ snapshotIndex ] } /> : null }
165
164
< TravelContainer
166
165
snapshotsLength = { snapshots . length }
167
166
snapshotIndex = { snapshotIndex }
@@ -170,8 +169,8 @@ class MainContainer extends Component {
170
169
moveBackward = { this . moveBackward }
171
170
moveForward = { this . moveForward }
172
171
play = { this . play }
173
- playing = { playing }
174
- pause = { this . pause }
172
+ playing = { playing }
173
+ pause = { this . pause }
175
174
/>
176
175
< ButtonsContainer mode = { mode } toggleMode = { this . toggleMode } />
177
176
</ div >
0 commit comments