@@ -47,6 +47,7 @@ const ProjectSaverHOC = function (WrappedComponent) {
47
47
constructor ( props ) {
48
48
super ( props ) ;
49
49
bindAll ( this , [
50
+ 'getProjectThumbnail' ,
50
51
'leavePageConfirm' ,
51
52
'tryToAutoSave'
52
53
] ) ;
@@ -57,6 +58,7 @@ const ProjectSaverHOC = function (WrappedComponent) {
57
58
// but then it'd be hard to turn this listening off in our tests
58
59
window . onbeforeunload = e => this . leavePageConfirm ( e ) ;
59
60
}
61
+ this . props . onSetProjectThumbnailer ( this . getProjectThumbnail ) ;
60
62
}
61
63
componentDidUpdate ( prevProps ) {
62
64
if ( this . props . projectChanged && ! prevProps . projectChanged ) {
@@ -104,6 +106,8 @@ const ProjectSaverHOC = function (WrappedComponent) {
104
106
// i.e. if another of this component has been mounted before this one gets unmounted
105
107
// which happens when going from project to editor view.
106
108
// window.onbeforeunload = undefined; // eslint-disable-line no-undefined
109
+ // Remove project thumbnailer function since the components are unmounting
110
+ this . props . onSetProjectThumbnailer ( null ) ;
107
111
}
108
112
leavePageConfirm ( e ) {
109
113
if ( this . props . projectChanged ) {
@@ -282,20 +286,25 @@ const ProjectSaverHOC = function (WrappedComponent) {
282
286
*/
283
287
storeProjectThumbnail ( projectId ) {
284
288
try {
285
- this . props . vm . postIOData ( 'video' , { forceTransparentPreview : true } ) ;
286
- this . props . vm . renderer . requestSnapshot ( dataURI => {
287
- this . props . vm . postIOData ( 'video' , { forceTransparentPreview : false } ) ;
288
- this . props . onUpdateProjectThumbnail (
289
- projectId , dataURItoBlob ( dataURI ) ) ;
289
+ this . getProjectThumbnail ( dataURI => {
290
+ this . props . onUpdateProjectThumbnail ( projectId , dataURItoBlob ( dataURI ) ) ;
290
291
} ) ;
291
- this . props . vm . renderer . draw ( ) ;
292
292
} catch ( e ) {
293
293
log . error ( 'Project thumbnail save error' , e ) ;
294
294
// This is intentionally fire/forget because a failure
295
295
// to save the thumbnail is not vitally important to the user.
296
296
}
297
297
}
298
298
299
+ getProjectThumbnail ( callback ) {
300
+ this . props . vm . postIOData ( 'video' , { forceTransparentPreview : true } ) ;
301
+ this . props . vm . renderer . requestSnapshot ( dataURI => {
302
+ this . props . vm . postIOData ( 'video' , { forceTransparentPreview : false } ) ;
303
+ callback ( dataURI ) ;
304
+ } ) ;
305
+ this . props . vm . renderer . draw ( ) ;
306
+ }
307
+
299
308
render ( ) {
300
309
const {
301
310
/* eslint-disable no-unused-vars */
@@ -318,6 +327,7 @@ const ProjectSaverHOC = function (WrappedComponent) {
318
327
onProjectError,
319
328
onRemixing,
320
329
onSetProjectUnchanged,
330
+ onSetProjectThumbnailer,
321
331
onShowAlert,
322
332
onShowCopySuccessAlert,
323
333
onShowRemixSuccessAlert,
@@ -378,7 +388,8 @@ const ProjectSaverHOC = function (WrappedComponent) {
378
388
} ;
379
389
ProjectSaverComponent . defaultProps = {
380
390
autoSaveIntervalSecs : 120 ,
381
- onRemixing : ( ) => { }
391
+ onRemixing : ( ) => { } ,
392
+ onSetProjectThumbnailer : ( ) => { }
382
393
} ;
383
394
const mapStateToProps = ( state , ownProps ) => {
384
395
const loadingState = state . scratchGui . projectState . loadingState ;
0 commit comments