@@ -24,7 +24,6 @@ import { OverallState } from '../application/ApplicationTypes';
24
24
import { ExternalLibraryName } from '../application/types/ExternalTypes' ;
25
25
import { LOGIN_GOOGLE , LOGOUT_GOOGLE } from '../application/types/SessionTypes' ;
26
26
import { retrieveFilesInWorkspaceAsRecord , rmFilesInDirRecursively , writeFileRecursively } from '../fileSystem/FileSystemUtils' ;
27
- import { refreshFileView } from '../fileSystemView/FileSystemViewList' ; // TODO broken when folder is open when reading folders
28
27
import { actions } from '../utils/ActionsHelper' ;
29
28
import Constants from '../utils/Constants' ;
30
29
import { showSimpleConfirmDialog , showSimplePromptDialog } from '../utils/DialogHelper' ;
@@ -196,7 +195,7 @@ export function* persistenceSaga(): SagaIterator {
196
195
// TODO find a file to open instead of deleting all active tabs?
197
196
// TODO without modifying WorkspaceReducer in one function this would cause errors - called by onChange of Playground.tsx?
198
197
// TODO change behaviour of WorkspaceReducer to not create program.js every time folder mode changes with 0 tabs existing?
199
- yield call ( refreshFileView ) ; // refreshes folder view TODO super jank?
198
+ yield call ( store . dispatch , actions . updateRefreshFileViewKey ( ) ) ; // refreshes folder view TODO super jank?
200
199
201
200
yield call ( showSuccessMessage , `Loaded folder ${ name } .` , 1000 ) ;
202
201
@@ -533,6 +532,9 @@ export function* persistenceSaga(): SagaIterator {
533
532
// Turn on folder mode TODO enable folder mode
534
533
//yield call (store.dispatch, actions.setFolderMode("playground", true));
535
534
yield call ( store . dispatch , actions . enableFileSystemContextMenus ( ) ) ;
535
+ yield call ( store . dispatch , actions . updateRefreshFileViewKey ( ) ) ;
536
+
537
+ yield call ( showSuccessMessage , `${ currFolderObject . name } successfully saved to Google Drive.` , 1000 ) ;
536
538
537
539
538
540
// Case 1: Open picker to select location for saving, similar to save all
@@ -609,7 +611,8 @@ export function* persistenceSaga(): SagaIterator {
609
611
yield call ( console . log , "parent not found " , newFilePath ) ;
610
612
return ;
611
613
}
612
- const newFileName = regexResult ! [ 2 ] ;
614
+ const newFileName = regexResult ! [ 2 ] + regexResult ! [ 3 ] ;
615
+ yield call ( console . log , regexResult , "regexresult!!!!!!!!!!!!!!!!!" ) ;
613
616
const persistenceFileArray : PersistenceFile [ ] = yield select ( ( state : OverallState ) => state . fileSystem . persistenceFileArray ) ;
614
617
const parentFolderPersistenceFile = persistenceFileArray . find ( e => e . path === parentFolderPath ) ;
615
618
if ( ! parentFolderPersistenceFile ) {
@@ -648,6 +651,37 @@ export function* persistenceSaga(): SagaIterator {
648
651
function * ( { payload } : ReturnType < typeof actions . persistenceCreateFolder > ) {
649
652
const newFolderPath = payload ;
650
653
yield call ( console . log , "create folder " , newFolderPath ) ;
654
+
655
+
656
+ // const persistenceFileArray: PersistenceFile[] = yield select((state: OverallState) => state.fileSystem.persistenceFileArray);
657
+
658
+ // look for parent folder persistenceFile
659
+ const regexResult = / ^ ( .* [ \\ \/ ] ) ? ( \. * .* ?) ( \. [ ^ . ] + ?| ) $ / . exec ( newFolderPath ) ;
660
+ const parentFolderPath = regexResult ? regexResult [ 1 ] . slice ( 0 , - 1 ) : undefined ;
661
+ if ( ! parentFolderPath ) {
662
+ yield call ( console . log , "parent not found " , newFolderPath ) ;
663
+ return ;
664
+ }
665
+ const newFolderName = regexResult ! [ 2 ] ;
666
+ const persistenceFileArray : PersistenceFile [ ] = yield select ( ( state : OverallState ) => state . fileSystem . persistenceFileArray ) ;
667
+ const parentFolderPersistenceFile = persistenceFileArray . find ( e => e . path === parentFolderPath ) ;
668
+ if ( ! parentFolderPersistenceFile ) {
669
+ yield call ( console . log , "parent pers file not found " , newFolderPath , " parent path " , parentFolderPath , " persArr " , persistenceFileArray , " reg res " , regexResult ) ;
670
+ return ;
671
+ }
672
+
673
+ yield call ( console . log , "parent found " , parentFolderPersistenceFile , " for file " , newFolderPath ) ;
674
+
675
+ // create folder
676
+ const parentFolderId = parentFolderPersistenceFile . id ;
677
+
678
+ const newFolderId : string = yield call ( createFolderAndReturnId , parentFolderId , newFolderName ) ;
679
+ yield put ( actions . addPersistenceFile ( { lastSaved : new Date ( ) , path : newFolderPath , id : newFolderId , name : newFolderName , parentId : parentFolderId } ) ) ;
680
+ yield call (
681
+ showSuccessMessage ,
682
+ `Folder ${ newFolderName } successfully saved to Google Drive.` ,
683
+ 1000
684
+ ) ;
651
685
}
652
686
) ;
653
687
@@ -656,6 +690,21 @@ export function* persistenceSaga(): SagaIterator {
656
690
function * ( { payload } : ReturnType < typeof actions . persistenceDeleteFile > ) {
657
691
const filePath = payload ;
658
692
yield call ( console . log , "delete file " , filePath ) ;
693
+
694
+ // look for file
695
+ const persistenceFileArray : PersistenceFile [ ] = yield select ( ( state : OverallState ) => state . fileSystem . persistenceFileArray ) ;
696
+ const persistenceFile = persistenceFileArray . find ( e => e . path === filePath ) ;
697
+ if ( ! persistenceFile ) {
698
+ yield call ( console . log , "cannot find pers file for " , filePath ) ;
699
+ return ;
700
+ }
701
+ yield call ( deleteFileOrFolder , persistenceFile . id ) ; // assume this succeeds all the time
702
+ yield put ( actions . deletePersistenceFile ( persistenceFile ) ) ;
703
+ yield call (
704
+ showSuccessMessage ,
705
+ `${ persistenceFile . name } successfully deleted from Google Drive.` ,
706
+ 1000
707
+ ) ;
659
708
}
660
709
) ;
661
710
@@ -664,13 +713,55 @@ export function* persistenceSaga(): SagaIterator {
664
713
function * ( { payload } : ReturnType < typeof actions . persistenceDeleteFolder > ) {
665
714
const folderPath = payload ;
666
715
yield call ( console . log , "delete folder " , folderPath ) ;
716
+
717
+ // identical to delete file
718
+ const persistenceFileArray : PersistenceFile [ ] = yield select ( ( state : OverallState ) => state . fileSystem . persistenceFileArray ) ;
719
+ const persistenceFile = persistenceFileArray . find ( e => e . path === folderPath ) ;
720
+ if ( ! persistenceFile ) {
721
+ yield call ( console . log , "cannot find pers file for " , folderPath ) ;
722
+ return ;
723
+ }
724
+ yield call ( deleteFileOrFolder , persistenceFile . id ) ; // assume this succeeds all the time
725
+ yield put ( actions . deletePersistenceFile ( persistenceFile ) ) ;
726
+ yield call (
727
+ showSuccessMessage ,
728
+ `Folder ${ persistenceFile . name } successfully deleted from Google Drive.` ,
729
+ 1000
730
+ ) ;
667
731
}
668
732
)
669
733
670
734
yield takeEvery (
671
735
PERSISTENCE_RENAME_FILE ,
672
736
function * ( { payload : { oldFilePath, newFilePath} } : ReturnType < typeof actions . persistenceRenameFile > ) {
673
737
yield call ( console . log , "rename file " , oldFilePath , " to " , newFilePath ) ;
738
+
739
+ // look for file
740
+ const persistenceFileArray : PersistenceFile [ ] = yield select ( ( state : OverallState ) => state . fileSystem . persistenceFileArray ) ;
741
+ const persistenceFile = persistenceFileArray . find ( e => e . path === oldFilePath ) ;
742
+ if ( ! persistenceFile ) {
743
+ yield call ( console . log , "cannot find pers file for " , oldFilePath ) ;
744
+ return ;
745
+ }
746
+
747
+ // new name
748
+ const regexResult = / ^ ( .* [ \\ \/ ] ) ? ( \. * .* ?) ( \. [ ^ . ] + ?| ) $ / . exec ( newFilePath ) ;
749
+ if ( ! regexResult ) {
750
+ yield call ( console . log , "regex fail " , newFilePath ) ;
751
+ return ;
752
+ }
753
+ const newFileName = regexResult [ 2 ] + regexResult [ 3 ] ;
754
+
755
+ // call gapi
756
+ yield call ( renameFileOrFolder , persistenceFile . id , newFileName ) ;
757
+
758
+ // handle pers file
759
+ yield put ( actions . updatePersistenceFilePathAndNameByPath ( oldFilePath , newFilePath , newFileName ) ) ;
760
+ yield call (
761
+ showSuccessMessage ,
762
+ `${ newFileName } successfully renamed in Google Drive.` ,
763
+ 1000
764
+ ) ;
674
765
}
675
766
) ;
676
767
@@ -912,6 +1003,24 @@ async function getFileFromFolder( // returns string id or empty string if failed
912
1003
}
913
1004
*/
914
1005
1006
+ function deleteFileOrFolder (
1007
+ id : string
1008
+ ) : Promise < any > {
1009
+ return gapi . client . drive . files . delete ( {
1010
+ fileId : id
1011
+ } ) ;
1012
+ }
1013
+
1014
+ function renameFileOrFolder (
1015
+ id : string ,
1016
+ newName : string ,
1017
+ ) : Promise < any > {
1018
+ return gapi . client . drive . files . update ( {
1019
+ fileId : id ,
1020
+ resource : { name : newName }
1021
+ } ) ;
1022
+ }
1023
+
915
1024
async function getContainingFolderIdRecursively ( // TODO memoize?
916
1025
parentFolders : string [ ] ,
917
1026
topFolderId : string ,
0 commit comments