@@ -42,7 +42,7 @@ import {
42
42
showSuccessMessage ,
43
43
showWarningMessage
44
44
} from '../utils/notifications/NotificationsHelper' ;
45
- import { filePathRegex } from '../utils/PersistenceHelper' ;
45
+ import { areAllFilesSavedGoogleDrive , filePathRegex } from '../utils/PersistenceHelper' ;
46
46
import { AsyncReturnType } from '../utils/TypeHelper' ;
47
47
import { EditorTabState } from '../workspace/WorkspaceTypes' ;
48
48
import { safeTakeEvery as takeEvery , safeTakeLatest as takeLatest } from './SafeEffects' ;
@@ -299,7 +299,6 @@ export function* persistenceSaga(): SagaIterator {
299
299
} ) ;
300
300
301
301
yield takeLatest ( PERSISTENCE_SAVE_FILE_AS , function * ( ) : any {
302
- // TODO wrap first part in try catch finally block
303
302
let toastKey : string | undefined ;
304
303
const persistenceFileArray : PersistenceFile [ ] = yield select (
305
304
( state : OverallState ) => state . fileSystem . persistenceFileArray
@@ -425,6 +424,21 @@ export function* persistenceSaga(): SagaIterator {
425
424
) ;
426
425
yield call ( writeFileRecursively , fileSystem , localFileTarget . path ! , code ) ;
427
426
yield call ( store . dispatch , actions . updateRefreshFileViewKey ( ) ) ;
427
+
428
+ // Check if all files are now updated
429
+ const updatedPersistenceFileArray : PersistenceFile [ ] = yield select (
430
+ ( state : OverallState ) => state . fileSystem . persistenceFileArray
431
+ ) ;
432
+ if ( areAllFilesSavedGoogleDrive ( updatedPersistenceFileArray ) ) {
433
+ yield put (
434
+ actions . playgroundUpdatePersistenceFolder ( {
435
+ id : currPersistenceFile . id ,
436
+ name : currPersistenceFile . name ,
437
+ parentId : currPersistenceFile . parentId ,
438
+ lastSaved : new Date ( )
439
+ } )
440
+ ) ;
441
+ }
428
442
} else {
429
443
yield call ( updateFile , pickedFile . id , pickedFile . name , MIME_SOURCE , code , config ) ;
430
444
}
@@ -561,6 +575,7 @@ export function* persistenceSaga(): SagaIterator {
561
575
let toastKey : string | undefined ;
562
576
563
577
try {
578
+ yield call ( ensureInitialisedAndAuthorised ) ;
564
579
const [ currFolderObject ] = yield select ( ( state : OverallState ) => [
565
580
state . playground . persistenceFile
566
581
] ) ;
@@ -806,6 +821,12 @@ export function* persistenceSaga(): SagaIterator {
806
821
throw new Error ( 'this file is not in persistenceFileArray: ' + currFullFilePath ) ;
807
822
}
808
823
824
+ if ( ! currPersistenceFile . lastEdit || ( currPersistenceFile . lastSaved && currPersistenceFile . lastEdit < currPersistenceFile . lastSaved ) ) {
825
+ // no need to update
826
+ yield call ( console . log , "No need to update" , currPersistenceFile ) ;
827
+ continue ;
828
+ }
829
+
809
830
if ( ! currPersistenceFile . id || ! currPersistenceFile . parentId ) {
810
831
// get folder
811
832
throw new Error ( 'this file does not have id/parentId: ' + currFullFilePath ) ;
@@ -882,7 +903,6 @@ export function* persistenceSaga(): SagaIterator {
882
903
let toastKey : string | undefined ;
883
904
884
905
const [ currFolderObject ] = yield select (
885
- // TODO resolve type here?
886
906
( state : OverallState ) => [ state . playground . persistenceFile ]
887
907
) ;
888
908
@@ -941,6 +961,22 @@ export function* persistenceSaga(): SagaIterator {
941
961
`${ currPersistenceFile . name } successfully saved to Google Drive.` ,
942
962
1000
943
963
) ;
964
+
965
+ // Check if all files are now updated
966
+ const updatedPersistenceFileArray : PersistenceFile [ ] = yield select (
967
+ ( state : OverallState ) => state . fileSystem . persistenceFileArray
968
+ ) ;
969
+ if ( areAllFilesSavedGoogleDrive ( updatedPersistenceFileArray ) ) {
970
+ yield put (
971
+ actions . playgroundUpdatePersistenceFolder ( {
972
+ id : currFolderObject . id ,
973
+ name : currFolderObject . name ,
974
+ parentId : currFolderObject . parentId ,
975
+ lastSaved : new Date ( )
976
+ } )
977
+ ) ;
978
+ }
979
+
944
980
return ;
945
981
}
946
982
@@ -968,13 +1004,12 @@ export function* persistenceSaga(): SagaIterator {
968
1004
yield takeEvery (
969
1005
PERSISTENCE_CREATE_FILE ,
970
1006
function * ( { payload } : ReturnType < typeof actions . persistenceCreateFile > ) {
971
- yield call ( store . dispatch , actions . disableFileSystemContextMenus ( ) ) ;
972
-
973
1007
try {
1008
+ yield call ( store . dispatch , actions . disableFileSystemContextMenus ( ) ) ;
974
1009
const newFilePath = payload ;
975
1010
yield call ( console . log , 'create file ' , newFilePath ) ;
976
1011
977
- // look for parent folder persistenceFile TODO modify action so name is supplied?
1012
+ // look for parent folder persistenceFile
978
1013
const regexResult = filePathRegex . exec ( newFilePath ) ! ;
979
1014
const parentFolderPath = regexResult ? regexResult [ 1 ] . slice ( 0 , - 1 ) : undefined ;
980
1015
if ( ! parentFolderPath ) {
@@ -992,6 +1027,7 @@ export function* persistenceSaga(): SagaIterator {
992
1027
yield call ( console . log , 'parent pers file missing' ) ;
993
1028
return ;
994
1029
}
1030
+ yield call ( ensureInitialisedAndAuthorised ) ;
995
1031
996
1032
yield call (
997
1033
console . log ,
@@ -1042,9 +1078,8 @@ export function* persistenceSaga(): SagaIterator {
1042
1078
yield takeEvery (
1043
1079
PERSISTENCE_CREATE_FOLDER ,
1044
1080
function * ( { payload } : ReturnType < typeof actions . persistenceCreateFolder > ) {
1045
- yield call ( store . dispatch , actions . disableFileSystemContextMenus ( ) ) ;
1046
-
1047
1081
try {
1082
+ yield call ( store . dispatch , actions . disableFileSystemContextMenus ( ) ) ;
1048
1083
const newFolderPath = payload ;
1049
1084
yield call ( console . log , 'create folder ' , newFolderPath ) ;
1050
1085
@@ -1067,6 +1102,7 @@ export function* persistenceSaga(): SagaIterator {
1067
1102
yield call ( console . log , 'parent pers file missing' ) ;
1068
1103
return ;
1069
1104
}
1105
+ yield call ( ensureInitialisedAndAuthorised ) ;
1070
1106
1071
1107
yield call (
1072
1108
console . log ,
@@ -1090,7 +1126,8 @@ export function* persistenceSaga(): SagaIterator {
1090
1126
path : newFolderPath ,
1091
1127
id : newFolderId ,
1092
1128
name : newFolderName ,
1093
- parentId : parentFolderId
1129
+ parentId : parentFolderId ,
1130
+ isFolder : true
1094
1131
} )
1095
1132
) ;
1096
1133
yield call ( store . dispatch , actions . updateRefreshFileViewKey ( ) ) ;
@@ -1111,9 +1148,8 @@ export function* persistenceSaga(): SagaIterator {
1111
1148
yield takeEvery (
1112
1149
PERSISTENCE_DELETE_FILE ,
1113
1150
function * ( { payload } : ReturnType < typeof actions . persistenceDeleteFile > ) {
1114
- yield call ( store . dispatch , actions . disableFileSystemContextMenus ( ) ) ;
1115
-
1116
1151
try {
1152
+ yield call ( store . dispatch , actions . disableFileSystemContextMenus ( ) ) ;
1117
1153
const filePath = payload ;
1118
1154
yield call ( console . log , 'delete file ' , filePath ) ;
1119
1155
@@ -1126,6 +1162,7 @@ export function* persistenceSaga(): SagaIterator {
1126
1162
yield call ( console . log , 'cannot find pers file for ' , filePath ) ;
1127
1163
return ;
1128
1164
}
1165
+ yield call ( ensureInitialisedAndAuthorised ) ;
1129
1166
yield call ( deleteFileOrFolder , persistenceFile . id ) ; // assume this succeeds all the time? TODO
1130
1167
yield put ( actions . deletePersistenceFile ( persistenceFile ) ) ;
1131
1168
yield call ( store . dispatch , actions . updateRefreshFileViewKey ( ) ) ;
@@ -1146,9 +1183,8 @@ export function* persistenceSaga(): SagaIterator {
1146
1183
yield takeEvery (
1147
1184
PERSISTENCE_DELETE_FOLDER ,
1148
1185
function * ( { payload } : ReturnType < typeof actions . persistenceDeleteFolder > ) {
1149
- yield call ( store . dispatch , actions . disableFileSystemContextMenus ( ) ) ;
1150
-
1151
1186
try {
1187
+ yield call ( store . dispatch , actions . disableFileSystemContextMenus ( ) ) ;
1152
1188
const folderPath = payload ;
1153
1189
yield call ( console . log , 'delete folder ' , folderPath ) ;
1154
1190
@@ -1161,6 +1197,7 @@ export function* persistenceSaga(): SagaIterator {
1161
1197
yield call ( console . log , 'cannot find pers file' ) ;
1162
1198
return ;
1163
1199
}
1200
+ yield call ( ensureInitialisedAndAuthorised ) ;
1164
1201
yield call ( deleteFileOrFolder , persistenceFile . id ) ;
1165
1202
yield put ( actions . deletePersistenceFile ( persistenceFile ) ) ;
1166
1203
yield call ( store . dispatch , actions . updateRefreshFileViewKey ( ) ) ;
@@ -1183,9 +1220,8 @@ export function* persistenceSaga(): SagaIterator {
1183
1220
function * ( {
1184
1221
payload : { oldFilePath, newFilePath }
1185
1222
} : ReturnType < typeof actions . persistenceRenameFile > ) {
1186
- yield call ( store . dispatch , actions . disableFileSystemContextMenus ( ) ) ;
1187
-
1188
1223
try {
1224
+ yield call ( store . dispatch , actions . disableFileSystemContextMenus ( ) ) ;
1189
1225
yield call ( console . log , 'rename file ' , oldFilePath , ' to ' , newFilePath ) ;
1190
1226
1191
1227
// look for file
@@ -1198,6 +1234,8 @@ export function* persistenceSaga(): SagaIterator {
1198
1234
return ;
1199
1235
}
1200
1236
1237
+ yield call ( ensureInitialisedAndAuthorised ) ;
1238
+
1201
1239
// new name TODO: modify action so name is supplied?
1202
1240
const regexResult = filePathRegex . exec ( newFilePath ) ! ;
1203
1241
const newFileName = regexResult [ 2 ] + regexResult [ 3 ] ;
@@ -1229,9 +1267,8 @@ export function* persistenceSaga(): SagaIterator {
1229
1267
function * ( {
1230
1268
payload : { oldFolderPath, newFolderPath }
1231
1269
} : ReturnType < typeof actions . persistenceRenameFolder > ) {
1232
- yield call ( store . dispatch , actions . disableFileSystemContextMenus ( ) ) ;
1233
-
1234
1270
try {
1271
+ yield call ( store . dispatch , actions . disableFileSystemContextMenus ( ) ) ;
1235
1272
yield call ( console . log , 'rename folder ' , oldFolderPath , ' to ' , newFolderPath ) ;
1236
1273
1237
1274
// look for folder
@@ -1244,6 +1281,8 @@ export function* persistenceSaga(): SagaIterator {
1244
1281
return ;
1245
1282
}
1246
1283
1284
+ yield call ( ensureInitialisedAndAuthorised ) ;
1285
+
1247
1286
// new name TODO: modify action so name is supplied?
1248
1287
const regexResult = filePathRegex . exec ( newFolderPath ) ! ;
1249
1288
const newFolderName = regexResult [ 2 ] + regexResult [ 3 ] ;
0 commit comments