@@ -69,7 +69,7 @@ class MainContainer extends Component {
69
69
if ( snapshots . length > 0 && snapshotIndex > 0 ) {
70
70
const newIndex = snapshotIndex - 1 ;
71
71
// second callback parameter of setState to invoke handleJumpSnapshot
72
- this . setState ( { snapshotIndex : newIndex } , this . handleJumpSnapshot ( newIndex ) ) ;
72
+ this . setState ( { snapshotIndex : newIndex } , this . handleJumpSnapshot ( newIndex ) ) ;
73
73
}
74
74
}
75
75
@@ -78,25 +78,25 @@ class MainContainer extends Component {
78
78
this . pause ( ) ;
79
79
if ( snapshotIndex < snapshots . length - 1 ) {
80
80
const newIndex = snapshotIndex + 1 ;
81
- this . setState ( { snapshotIndex : newIndex } , this . handleJumpSnapshot ( newIndex ) ) ;
81
+ this . setState ( { snapshotIndex : newIndex } , this . handleJumpSnapshot ( newIndex ) ) ;
82
82
}
83
83
}
84
84
85
85
play ( ) {
86
86
globalPlaying = ! globalPlaying
87
- this . setState ( { playing : globalPlaying } , ( ) => {
88
- if ( this . state . playing ) {
87
+ this . setState ( { playing : globalPlaying } , ( ) => {
88
+ if ( this . state . playing ) {
89
89
intervalId = setInterval ( ( ) => {
90
90
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
- }
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
+ }
100
100
} , 1000 ) ;
101
101
} else {
102
102
clearInterval ( intervalId ) ;
@@ -105,7 +105,7 @@ class MainContainer extends Component {
105
105
}
106
106
107
107
pause ( ) {
108
- this . setState ( { playing : false } , clearInterval ( intervalId ) )
108
+ this . setState ( { playing : false } , clearInterval ( intervalId ) )
109
109
}
110
110
111
111
emptySnapshot ( ) {
@@ -128,6 +128,28 @@ class MainContainer extends Component {
128
128
port . postMessage ( { action : 'jumpToSnap' , payload : snapshots [ snapshotIndex ] } ) ;
129
129
}
130
130
131
+ importSnapshots ( ) {
132
+ const { snapshots } = this . state ;
133
+ const fileDownload = document . createElement ( 'a' ) ;
134
+ fileDownload . style . display = 'none' ;
135
+ document . body . appendChild ( fileDownload ) ;
136
+ fileDownload . href = URL . createObjectURL (
137
+ new Blob ( [ JSON . stringify ( snapshots ) ] , { type : 'application/json' } ) ,
138
+ ) ;
139
+ fileDownload . setAttribute ( 'download' , 'snapshot.json' ) ;
140
+ fileDownload . click ( ) ;
141
+ URL . revokeObjectURL ( fileDownload . href ) ;
142
+ document . body . removeChild ( fileDownload ) ;
143
+ }
144
+
145
+ exportSnapshots ( ) {
146
+ const fileUpload = document . createElement ( 'input' ) ;
147
+ fileUpload . setAttribute ( 'type' , 'file' ) ;
148
+
149
+ fileUpload . click ( ) ;
150
+ this ;
151
+ }
152
+
131
153
toggleMode ( targetMode ) {
132
154
const { mode, mode : { locked, paused, persist } , port } = this . state ;
133
155
switch ( targetMode ) {
@@ -170,10 +192,15 @@ class MainContainer extends Component {
170
192
moveBackward = { this . moveBackward }
171
193
moveForward = { this . moveForward }
172
194
play = { this . play }
173
- playing = { playing }
174
- pause = { this . pause }
195
+ playing = { playing }
196
+ pause = { this . pause }
197
+ />
198
+ < ButtonsContainer
199
+ mode = { mode }
200
+ toggleMode = { this . toggleMode }
201
+ importSnapshots = { this . importSnapshots }
202
+ exportSnapshots = { this . exportSnapshots }
175
203
/>
176
- < ButtonsContainer mode = { mode } toggleMode = { this . toggleMode } />
177
204
</ div >
178
205
</ div >
179
206
) ;
0 commit comments