@@ -24,6 +24,7 @@ import { store } from '../../pages/createStore';
24
24
import { OverallState } from '../application/ApplicationTypes' ;
25
25
import { LOGIN_GOOGLE , LOGOUT_GOOGLE } from '../application/types/SessionTypes' ;
26
26
import {
27
+ isGithubSyncing ,
27
28
retrieveFilesInWorkspaceAsRecord ,
28
29
rmFilesInDirRecursively ,
29
30
writeFileRecursively
@@ -569,7 +570,7 @@ export function* persistenceSaga(): SagaIterator {
569
570
570
571
571
572
// Case where playground PersistenceFile is in single file mode
572
- // Does nothing
573
+ // Does nothing extra
573
574
yield call (
574
575
showSuccessMessage ,
575
576
`${ response . value } successfully saved to Google Drive.` ,
@@ -627,17 +628,23 @@ export function* persistenceSaga(): SagaIterator {
627
628
} ;
628
629
629
630
if ( ! currFolderObject || ! ( currFolderObject as PersistenceFile ) . isFolder ) {
631
+ yield call ( console . log , 'here' ) ;
630
632
// Check if there is only a single top level folder
631
633
const testPaths : Set < string > = new Set ( ) ;
634
+ let fileExistsInTopLevel = false ;
632
635
Object . keys ( currFiles ) . forEach ( e => {
633
636
const regexResult = filePathRegex . exec ( e ) ! ;
637
+ const testStr = regexResult ! [ 1 ] . slice ( '/playground/' . length , - 1 ) . split ( '/' ) [ 0 ] ;
638
+ if ( testStr === '' ) {
639
+ fileExistsInTopLevel = true ;
640
+ }
634
641
testPaths . add ( regexResult ! [ 1 ] . slice ( '/playground/' . length , - 1 ) . split ( '/' ) [ 0 ] ) ; //TODO hardcoded playground
635
642
} ) ;
636
- if ( testPaths . size !== 1 ) {
643
+ if ( testPaths . size !== 1 || fileExistsInTopLevel ) {
637
644
yield call ( showSimpleErrorDialog , {
638
645
title : 'Unable to Save All' ,
639
646
contents : (
640
- < p > There must be exactly one top level folder present in order to use Save All.</ p >
647
+ < p > There must be only exactly one non-empty top level folder present to use Save All.</ p >
641
648
) ,
642
649
label : 'OK'
643
650
} ) ;
@@ -937,12 +944,24 @@ export function* persistenceSaga(): SagaIterator {
937
944
) ;
938
945
939
946
try {
940
- if ( activeEditorTabIndex === null && ! playgroundPersistenceFile . isFolder ) {
941
- yield call ( showWarningMessage , `Please have ${ name } open as the active editor tab.` , 1000 ) ;
947
+ if ( activeEditorTabIndex === null ) {
948
+ if ( ! playgroundPersistenceFile ) yield call ( showWarningMessage , `Please have an editor tab open.` , 1000 ) ;
949
+ else if ( ! playgroundPersistenceFile . isFolder ) {
950
+ yield call ( showWarningMessage , `Please have ${ name } open as the active editor tab.` , 1000 ) ;
951
+ } else {
952
+ yield call ( showWarningMessage , `Please have the file you want to save open as the active editor tab.` , 1000 ) ;
953
+ }
942
954
return ;
943
955
}
944
956
const code = editorTabs [ activeEditorTabIndex ] . value ;
945
957
958
+ // check if editor is correct for single file mode
959
+ if ( playgroundPersistenceFile && ! playgroundPersistenceFile . isFolder &&
960
+ ( editorTabs [ activeEditorTabIndex ] as EditorTabState ) . filePath !== playgroundPersistenceFile . path ) {
961
+ yield call ( showWarningMessage , `Please have ${ name } open as the active editor tab.` , 1000 ) ;
962
+ return ;
963
+ }
964
+
946
965
const config : IPlaygroundConfig = {
947
966
chapter,
948
967
variant,
@@ -1000,11 +1019,6 @@ export function* persistenceSaga(): SagaIterator {
1000
1019
return ;
1001
1020
}
1002
1021
1003
- if ( ( editorTabs [ activeEditorTabIndex ] as EditorTabState ) . filePath !== playgroundPersistenceFile . path ) {
1004
- yield call ( showWarningMessage , `Please have ${ name } open as the active editor tab.` , 1000 ) ;
1005
- return ;
1006
- }
1007
-
1008
1022
toastKey = yield call ( showMessage , {
1009
1023
message : `Saving as ${ name } ...` ,
1010
1024
timeout : 0 ,
@@ -1032,6 +1046,8 @@ export function* persistenceSaga(): SagaIterator {
1032
1046
yield takeEvery (
1033
1047
PERSISTENCE_CREATE_FILE ,
1034
1048
function * ( { payload } : ReturnType < typeof actions . persistenceCreateFile > ) {
1049
+ const bailNow : boolean = yield call ( isGithubSyncing ) ;
1050
+ if ( bailNow ) return ;
1035
1051
try {
1036
1052
yield call ( store . dispatch , actions . disableFileSystemContextMenus ( ) ) ;
1037
1053
const newFilePath = payload ;
@@ -1106,6 +1122,8 @@ export function* persistenceSaga(): SagaIterator {
1106
1122
yield takeEvery (
1107
1123
PERSISTENCE_CREATE_FOLDER ,
1108
1124
function * ( { payload } : ReturnType < typeof actions . persistenceCreateFolder > ) {
1125
+ const bailNow : boolean = yield call ( isGithubSyncing ) ;
1126
+ if ( bailNow ) return ;
1109
1127
try {
1110
1128
yield call ( store . dispatch , actions . disableFileSystemContextMenus ( ) ) ;
1111
1129
const newFolderPath = payload ;
@@ -1176,6 +1194,8 @@ export function* persistenceSaga(): SagaIterator {
1176
1194
yield takeEvery (
1177
1195
PERSISTENCE_DELETE_FILE ,
1178
1196
function * ( { payload } : ReturnType < typeof actions . persistenceDeleteFile > ) {
1197
+ const bailNow : boolean = yield call ( isGithubSyncing ) ;
1198
+ if ( bailNow ) return ;
1179
1199
try {
1180
1200
yield call ( store . dispatch , actions . disableFileSystemContextMenus ( ) ) ;
1181
1201
const filePath = payload ;
@@ -1191,9 +1211,19 @@ export function* persistenceSaga(): SagaIterator {
1191
1211
return ;
1192
1212
}
1193
1213
yield call ( ensureInitialisedAndAuthorised ) ;
1194
- yield call ( deleteFileOrFolder , persistenceFile . id ) ; // assume this succeeds all the time? TODO
1214
+ yield call ( deleteFileOrFolder , persistenceFile . id ) ;
1195
1215
yield put ( actions . deletePersistenceFile ( persistenceFile ) ) ;
1196
1216
yield call ( store . dispatch , actions . updateRefreshFileViewKey ( ) ) ;
1217
+
1218
+ // If the user comes here in single file mode, then the file they deleted
1219
+ // must be the file they are tracking.
1220
+ const [ currFileObject ] = yield select ( ( state : OverallState ) => [
1221
+ state . playground . persistenceFile
1222
+ ] ) ;
1223
+ if ( ! currFileObject . isFolder ) {
1224
+ yield put ( actions . playgroundUpdatePersistenceFile ( undefined ) ) ;
1225
+ }
1226
+
1197
1227
yield call (
1198
1228
showSuccessMessage ,
1199
1229
`${ persistenceFile . name } successfully deleted from Google Drive.` ,
@@ -1211,6 +1241,8 @@ export function* persistenceSaga(): SagaIterator {
1211
1241
yield takeEvery (
1212
1242
PERSISTENCE_DELETE_FOLDER ,
1213
1243
function * ( { payload } : ReturnType < typeof actions . persistenceDeleteFolder > ) {
1244
+ const bailNow : boolean = yield call ( isGithubSyncing ) ;
1245
+ if ( bailNow ) return ;
1214
1246
try {
1215
1247
yield call ( store . dispatch , actions . disableFileSystemContextMenus ( ) ) ;
1216
1248
const folderPath = payload ;
@@ -1255,6 +1287,8 @@ export function* persistenceSaga(): SagaIterator {
1255
1287
function * ( {
1256
1288
payload : { oldFilePath, newFilePath }
1257
1289
} : ReturnType < typeof actions . persistenceRenameFile > ) {
1290
+ const bailNow : boolean = yield call ( isGithubSyncing ) ;
1291
+ if ( bailNow ) return ;
1258
1292
try {
1259
1293
yield call ( store . dispatch , actions . disableFileSystemContextMenus ( ) ) ;
1260
1294
yield call ( console . log , 'rename file ' , oldFilePath , ' to ' , newFilePath ) ;
@@ -1275,13 +1309,27 @@ export function* persistenceSaga(): SagaIterator {
1275
1309
const regexResult = filePathRegex . exec ( newFilePath ) ! ;
1276
1310
const newFileName = regexResult [ 2 ] + regexResult [ 3 ] ;
1277
1311
1312
+ // old name
1313
+ const regexResult2 = filePathRegex . exec ( oldFilePath ) ! ;
1314
+ const oldFileName = regexResult2 [ 2 ] + regexResult2 [ 3 ] ;
1315
+
1278
1316
// call gapi
1279
1317
yield call ( renameFileOrFolder , persistenceFile . id , newFileName ) ;
1280
1318
1281
1319
// handle pers file
1282
1320
yield put (
1283
1321
actions . updatePersistenceFilePathAndNameByPath ( oldFilePath , newFilePath , newFileName )
1284
1322
) ;
1323
+ const [ currFileObject ] = yield select ( ( state : OverallState ) => [
1324
+ state . playground . persistenceFile
1325
+ ] ) ;
1326
+ if ( currFileObject . name === oldFileName ) {
1327
+ // update playground PersistenceFile
1328
+ yield put (
1329
+ actions . playgroundUpdatePersistenceFile ( { ...currFileObject , name : newFileName } )
1330
+ ) ;
1331
+ }
1332
+
1285
1333
yield call ( store . dispatch , actions . updateRefreshFileViewKey ( ) ) ;
1286
1334
yield call (
1287
1335
showSuccessMessage ,
@@ -1302,6 +1350,8 @@ export function* persistenceSaga(): SagaIterator {
1302
1350
function * ( {
1303
1351
payload : { oldFolderPath, newFolderPath }
1304
1352
} : ReturnType < typeof actions . persistenceRenameFolder > ) {
1353
+ const bailNow : boolean = yield call ( isGithubSyncing ) ;
1354
+ if ( bailNow ) return ;
1305
1355
try {
1306
1356
yield call ( store . dispatch , actions . disableFileSystemContextMenus ( ) ) ;
1307
1357
yield call ( console . log , 'rename folder ' , oldFolderPath , ' to ' , newFolderPath ) ;
0 commit comments