@@ -82,6 +82,7 @@ function* googleLogin() {
82
82
export function * persistenceSaga ( ) : SagaIterator {
83
83
yield takeLatest ( LOGOUT_GOOGLE , function * ( ) : any {
84
84
yield put ( actions . playgroundUpdatePersistenceFile ( undefined ) ) ;
85
+ yield call ( store . dispatch , actions . deleteAllPersistenceFiles ( ) ) ;
85
86
yield call ( ensureInitialised ) ;
86
87
yield call ( gapi . client . setToken , null ) ;
87
88
yield put ( actions . removeGoogleUserAndAccessToken ( ) ) ;
@@ -348,23 +349,23 @@ export function* persistenceSaga(): SagaIterator {
348
349
}
349
350
350
351
yield call ( store . dispatch , actions . disableFileSystemContextMenus ( ) ) ;
352
+
353
+ const [ chapter , variant , external ] = yield select ( ( state : OverallState ) => [
354
+ state . workspaces . playground . context . chapter ,
355
+ state . workspaces . playground . context . variant ,
356
+ state . workspaces . playground . externalLibrary
357
+ ] ) ;
358
+ const config : IPlaygroundConfig = {
359
+ chapter,
360
+ variant,
361
+ external
362
+ } ;
351
363
// Case: Picked a file to overwrite
352
364
if ( currPersistenceFile && currPersistenceFile . isFolder ) {
353
365
yield call ( console . log , 'folder opened, handling save_as differently! overwriting file' ) ;
354
366
// First case: Chosen location is within TLRF - so need to call methods to update PersistenceFileArray
355
367
// Other case: Chosen location is outside TLRF - don't care
356
368
357
- const [ chapter , variant , external ] = yield select ( ( state : OverallState ) => [
358
- state . workspaces . playground . context . chapter ,
359
- state . workspaces . playground . context . variant ,
360
- state . workspaces . playground . externalLibrary
361
- ] ) ;
362
- const config : IPlaygroundConfig = {
363
- chapter,
364
- variant,
365
- external
366
- } ;
367
-
368
369
yield call (
369
370
console . log ,
370
371
'curr pers file ' ,
@@ -381,7 +382,6 @@ export function* persistenceSaga(): SagaIterator {
381
382
timeout : 0 ,
382
383
intent : Intent . PRIMARY
383
384
} ) ;
384
- // identical to just saving a file locally
385
385
const fileSystem : FSModule | null = yield select (
386
386
( state : OverallState ) => state . fileSystem . inBrowserFileSystem
387
387
) ;
@@ -424,7 +424,13 @@ export function* persistenceSaga(): SagaIterator {
424
424
} )
425
425
) ;
426
426
}
427
+ // Check if any editor tab is that updated file, and update contents
428
+ const targetEditorTabIndex = ( editorTabs as EditorTabState [ ] ) . findIndex ( e => e . filePath === localFileTarget . path ! ) ;
429
+ if ( targetEditorTabIndex !== - 1 ) {
430
+ yield put ( actions . updateEditorValue ( 'playground' , targetEditorTabIndex , code ) ) ;
431
+ }
427
432
} else {
433
+ // User overwriting file outside TLRF
428
434
yield call ( updateFile , pickedFile . id , pickedFile . name , MIME_SOURCE , code , config ) ;
429
435
}
430
436
yield call (
@@ -434,10 +440,33 @@ export function* persistenceSaga(): SagaIterator {
434
440
) ;
435
441
return ;
436
442
}
437
- // Single file mode case
438
- const singleFileModePersFile : PersistenceFile = { ...pickedFile , lastSaved : new Date ( ) , path : '/playground/' + pickedFile . name } ;
439
- yield put ( actions . playgroundUpdatePersistenceFile ( singleFileModePersFile ) ) ;
440
- yield put ( actions . persistenceSaveFile ( singleFileModePersFile ) ) ;
443
+
444
+ // Chose to overwrite file - single file case
445
+ if ( currPersistenceFile && currPersistenceFile . id === pickedFile . id ) {
446
+ // User chose to overwrite the tracked file
447
+ const newPersFile : PersistenceFile = { ...pickedFile , lastSaved : new Date ( ) , path : "/playground/" + pickedFile . name } ;
448
+ // Update playground persistenceFile
449
+ yield put ( actions . playgroundUpdatePersistenceFile ( newPersFile ) ) ;
450
+ // Update entry in persFileArray
451
+ yield put ( actions . addPersistenceFile ( newPersFile ) ) ;
452
+
453
+ }
454
+
455
+ // Save in Google Drive
456
+ yield call (
457
+ updateFile ,
458
+ pickedFile . id ,
459
+ pickedFile . name ,
460
+ MIME_SOURCE ,
461
+ code ,
462
+ config
463
+ ) ;
464
+
465
+ yield call (
466
+ showSuccessMessage ,
467
+ `${ pickedFile . name } successfully saved to Google Drive.` ,
468
+ 1000
469
+ ) ;
441
470
} else {
442
471
const response : AsyncReturnType < typeof showSimplePromptDialog > = yield call (
443
472
showSimplePromptDialog ,
@@ -539,20 +568,8 @@ export function* persistenceSaga(): SagaIterator {
539
568
}
540
569
541
570
542
- // Single file case
543
- const newPersFile : PersistenceFile = { ...newFile , lastSaved : new Date ( ) , path : "/playground/" + newFile . name } ;
544
- if ( ! currPersistenceFile ) { // no file loaded prior
545
- // update playground pers file
546
- yield put ( actions . playgroundUpdatePersistenceFile ( newPersFile ) ) ;
547
- // add new pers file to persFileArray
548
- } else { // file loaded prior
549
- // update playground pers file
550
- yield put ( actions . playgroundUpdatePersistenceFile ( newPersFile ) ) ;
551
- // remove old pers file from persFileArray
552
- // add new pers file to persFileArray
553
- }
554
-
555
- //
571
+ // Case where playground PersistenceFile is in single file mode
572
+ // Does nothing
556
573
yield call (
557
574
showSuccessMessage ,
558
575
`${ response . value } successfully saved to Google Drive.` ,
0 commit comments