@@ -126,8 +126,6 @@ export function* persistenceSaga(): SagaIterator {
126
126
return ;
127
127
}
128
128
129
- // Close folder mode TODO disable the button
130
- //yield call(store.dispatch, actions.setFolderMode("playground", false));
131
129
yield call ( store . dispatch , actions . disableFileSystemContextMenus ( ) ) ;
132
130
133
131
// Note: for mimeType, text/plain -> file, application/vnd.google-apps.folder -> folder
@@ -153,7 +151,6 @@ export function* persistenceSaga(): SagaIterator {
153
151
yield call ( console . log , "no filesystem!" ) ;
154
152
return ;
155
153
}
156
- yield call ( console . log , "there is a filesystem" ) ;
157
154
158
155
// Begin
159
156
@@ -163,7 +160,15 @@ export function* persistenceSaga(): SagaIterator {
163
160
// clear all persistence files
164
161
yield call ( store . dispatch , actions . deleteAllPersistenceFiles ( ) ) ;
165
162
163
+ // add tlrf
164
+ yield put ( actions . addPersistenceFile ( { id, parentId, name, path : "/playground/" + name , isFolder : true } ) ) ;
165
+
166
166
for ( const currFile of fileList ) {
167
+ if ( currFile . isFolder == true ) {
168
+ yield call ( console . log , "not file " , currFile ) ;
169
+ yield put ( actions . addPersistenceFile ( { id : currFile . id , parentId : currFile . parentId , name : currFile . name , path : "/playground" + currFile . path , isFolder : true } ) ) ;
170
+ continue ;
171
+ }
167
172
yield put ( actions . addPersistenceFile ( { id : currFile . id , parentId : currFile . parentId , name : currFile . name , path : "/playground" + currFile . path , lastSaved : new Date ( ) } ) ) ;
168
173
const contents = yield call ( [ gapi . client . drive . files , 'get' ] , { fileId : currFile . id , alt : 'media' } ) ;
169
174
yield call ( writeFileRecursively , fileSystem , "/playground" + currFile . path , contents . body ) ;
@@ -427,7 +432,7 @@ export function* persistenceSaga(): SagaIterator {
427
432
external
428
433
} ;
429
434
430
- // check if top level folder has been renamed
435
+ // check if top level folder has been renamed TODO remove once instant sync done
431
436
// assuming only 1 top level folder exists, so get 1 file
432
437
const testPath = Object . keys ( currFiles ) [ 0 ] ;
433
438
const regexResult = / ^ ( .* [ \\ \/ ] ) ? ( \. * .* ?) ( \. [ ^ . ] + ?| ) $ / . exec ( testPath ) ;
@@ -444,8 +449,6 @@ export function* persistenceSaga(): SagaIterator {
444
449
}
445
450
446
451
// Start actually saving
447
- // Turn off folder mode TODO disable folder mode
448
- //yield call (store.dispatch, actions.setFolderMode("playground", false));
449
452
yield call ( store . dispatch , actions . disableFileSystemContextMenus ( ) ) ;
450
453
451
454
if ( topLevelFolderName !== currFolderObject . name ) {
@@ -477,9 +480,16 @@ export function* persistenceSaga(): SagaIterator {
477
480
478
481
const currPersistenceFile = persistenceFileArray . find ( e => e . path === currFullFilePath ) ;
479
482
if ( currPersistenceFile === undefined ) {
480
- yield call ( console . log , "error" ) ;
481
- return ;
483
+ yield call ( console . log , "this file is not in persistenceFileArray: " , currFullFilePath ) ;
484
+ continue ;
485
+ }
486
+
487
+ if ( ! currPersistenceFile . id || ! currPersistenceFile . parentId ) {
488
+ // get folder
489
+ yield call ( console . log , "this file does not have id/parentId: " , currFullFilePath ) ;
490
+ continue ;
482
491
}
492
+
483
493
const currFileId = currPersistenceFile . id ! ;
484
494
const currFileParentFolderId = currPersistenceFile . parentId ! ;
485
495
@@ -589,6 +599,47 @@ export function* persistenceSaga(): SagaIterator {
589
599
function * ( { payload } : ReturnType < typeof actions . persistenceCreateFile > ) {
590
600
const newFilePath = payload ;
591
601
yield call ( console . log , "create file " , newFilePath ) ;
602
+
603
+ // const persistenceFileArray: PersistenceFile[] = yield select((state: OverallState) => state.fileSystem.persistenceFileArray);
604
+
605
+ // look for parent folder persistenceFile
606
+ const regexResult = / ^ ( .* [ \\ \/ ] ) ? ( \. * .* ?) ( \. [ ^ . ] + ?| ) $ / . exec ( newFilePath ) ;
607
+ const parentFolderPath = regexResult ? regexResult [ 1 ] . slice ( 0 , - 1 ) : undefined ;
608
+ if ( ! parentFolderPath ) {
609
+ yield call ( console . log , "parent not found " , newFilePath ) ;
610
+ return ;
611
+ }
612
+ const newFileName = regexResult ! [ 2 ] ;
613
+ const persistenceFileArray : PersistenceFile [ ] = yield select ( ( state : OverallState ) => state . fileSystem . persistenceFileArray ) ;
614
+ const parentFolderPersistenceFile = persistenceFileArray . find ( e => e . path === parentFolderPath ) ;
615
+ if ( ! parentFolderPersistenceFile ) {
616
+ yield call ( console . log , "parent pers file not found " , newFilePath , " parent path " , parentFolderPath , " persArr " , persistenceFileArray , " reg res " , regexResult ) ;
617
+ return ;
618
+ }
619
+
620
+ yield call ( console . log , "parent found " , parentFolderPersistenceFile , " for file " , newFilePath ) ;
621
+
622
+ // create file
623
+ const parentFolderId = parentFolderPersistenceFile . id ;
624
+ const [ chapter , variant , external ] = yield select (
625
+ ( state : OverallState ) => [
626
+ state . workspaces . playground . context . chapter ,
627
+ state . workspaces . playground . context . variant ,
628
+ state . workspaces . playground . externalLibrary
629
+ ]
630
+ ) ;
631
+ const config : IPlaygroundConfig = {
632
+ chapter,
633
+ variant,
634
+ external
635
+ } ;
636
+ const newFilePersistenceFile : PersistenceFile = yield call ( createFile , newFileName , parentFolderId , MIME_SOURCE , '' , config ) ;
637
+ yield put ( actions . addPersistenceFile ( { ...newFilePersistenceFile , lastSaved : new Date ( ) , path : newFilePath } ) ) ;
638
+ yield call (
639
+ showSuccessMessage ,
640
+ `${ newFileName } successfully saved to Google Drive.` ,
641
+ 1000
642
+ ) ;
592
643
}
593
644
) ;
594
645
@@ -798,7 +849,7 @@ async function getFilesOfFolder( // recursively get files
798
849
name : currFolderName ,
799
850
id : folderId ,
800
851
path : currPath + '/' + currFolderName ,
801
- isFile : false
852
+ isFolder : true
802
853
} ] ;
803
854
}
804
855
@@ -809,15 +860,20 @@ async function getFilesOfFolder( // recursively get files
809
860
ans = ans . concat ( await
810
861
getFilesOfFolder ( currFile . id ! , currFile . name ! , currPath + '/' + currFolderName )
811
862
) ;
863
+ ans . push ( {
864
+ name : currFile . name ,
865
+ id : currFile . id ,
866
+ parentId : folderId ,
867
+ path : currPath + '/' + currFolderName + '/' + currFile . name ,
868
+ isFolder : true
869
+ } ) ;
812
870
}
813
871
else { // file
814
- console . log ( "found file " + currFile . name ) ;
815
872
ans . push ( {
816
873
name : currFile . name ,
817
874
id : currFile . id ,
818
875
parentId : folderId ,
819
- path : currPath + '/' + currFolderName + '/' + currFile . name ,
820
- isFile : true
876
+ path : currPath + '/' + currFolderName + '/' + currFile . name
821
877
} ) ;
822
878
}
823
879
}
@@ -934,7 +990,7 @@ function createFile(
934
990
headers,
935
991
body
936
992
} )
937
- . then ( ( { result } ) => ( { id : result . id , name : result . name , isFile : true } ) ) ;
993
+ . then ( ( { result } ) => ( { id : result . id , parentId : parent , name : result . name } ) ) ;
938
994
}
939
995
940
996
function updateFile (
0 commit comments