@@ -136,9 +136,6 @@ export function* persistenceSaga(): SagaIterator {
136
136
}
137
137
138
138
yield call ( store . dispatch , actions . disableFileSystemContextMenus ( ) ) ;
139
-
140
- // Note: for mimeType, text/plain -> file, application/vnd.google-apps.folder -> folder
141
-
142
139
if ( mimeType === MIME_FOLDER ) {
143
140
// handle folders
144
141
toastKey = yield call ( showMessage , {
@@ -148,27 +145,20 @@ export function* persistenceSaga(): SagaIterator {
148
145
} ) ;
149
146
150
147
const fileList = yield call ( getFilesOfFolder , id , name ) ; // this needed the extra scope mimetypes to have every file
151
- // TODO: add type for each resp?
152
148
yield call ( console . log , 'fileList' , fileList ) ;
153
149
154
150
const fileSystem : FSModule | null = yield select (
155
151
( state : OverallState ) => state . fileSystem . inBrowserFileSystem
156
152
) ;
157
153
// If the file system is not initialised, do nothing.
158
154
if ( fileSystem === null ) {
159
- yield call ( console . log , 'no filesystem!' ) ;
160
- return ;
155
+ throw new Error ( "No filesystem!" ) ;
161
156
}
162
157
163
- // Begin
164
-
165
- // rm everything TODO replace everything hardcoded with playground?
166
158
yield call ( rmFilesInDirRecursively , fileSystem , '/playground' ) ;
167
-
168
- // clear all persistence files
169
159
yield call ( store . dispatch , actions . deleteAllPersistenceFiles ( ) ) ;
170
160
171
- // add tlrf
161
+ // add top level root folder
172
162
yield put (
173
163
actions . addPersistenceFile ( {
174
164
id,
@@ -179,6 +169,8 @@ export function* persistenceSaga(): SagaIterator {
179
169
} )
180
170
) ;
181
171
172
+ yield call ( store . dispatch , actions . updateRefreshFileViewKey ( ) ) ;
173
+
182
174
for ( const currFile of fileList ) {
183
175
if ( currFile . isFolder === true ) {
184
176
yield call ( console . log , 'not file ' , currFile ) ;
@@ -191,6 +183,14 @@ export function* persistenceSaga(): SagaIterator {
191
183
isFolder : true
192
184
} )
193
185
) ;
186
+ yield call (
187
+ writeFileRecursively ,
188
+ fileSystem ,
189
+ '/playground' + currFile . path + "/dummy" , // workaround to make empty folders
190
+ "" ,
191
+ true
192
+ ) ;
193
+ yield call ( store . dispatch , actions . updateRefreshFileViewKey ( ) ) ;
194
194
continue ;
195
195
}
196
196
yield put (
@@ -206,50 +206,39 @@ export function* persistenceSaga(): SagaIterator {
206
206
fileId : currFile . id ,
207
207
alt : 'media'
208
208
} ) ;
209
- console . log ( currFile . path ) ;
210
- console . log ( contents . body === '' ) ;
211
209
yield call (
212
210
writeFileRecursively ,
213
211
fileSystem ,
214
212
'/playground' + currFile . path ,
215
213
contents . body
216
214
) ;
217
215
yield call ( showSuccessMessage , `Loaded file ${ currFile . path } .` , 1000 ) ;
216
+ yield call ( store . dispatch , actions . updateRefreshFileViewKey ( ) ) ;
218
217
}
219
218
220
219
// set source to chapter 4 TODO is there a better way of handling this
221
220
yield put (
222
221
actions . chapterSelect ( parseInt ( '4' , 10 ) as Chapter , Variant . DEFAULT , 'playground' )
223
222
) ;
224
- // open folder mode TODO enable button
225
- //yield call(store.dispatch, actions.setFolderMode("playground", true));
226
- yield call ( store . dispatch , actions . enableFileSystemContextMenus ( ) ) ;
227
-
228
- // DDDDDDDDDDDDDDDebug
229
- const test = yield select ( ( state : OverallState ) => state . fileSystem . persistenceFileArray ) ;
230
- yield call ( console . log , test ) ;
231
223
232
- // refresh needed
224
+ yield call ( store . dispatch , actions . enableFileSystemContextMenus ( ) ) ;
233
225
yield call (
234
226
store . dispatch ,
235
227
actions . removeEditorTabsForDirectory ( 'playground' , WORKSPACE_BASE_PATHS [ 'playground' ] )
236
- ) ; // TODO hardcoded
237
- // TODO find a file to open instead of deleting all active tabs?
238
- // TODO without modifying WorkspaceReducer in one function this would cause errors - called by onChange of Playground.tsx?
239
- // TODO change behaviour of WorkspaceReducer to not create program.js every time folder mode changes with 0 tabs existing?
240
- yield call ( store . dispatch , actions . updateRefreshFileViewKey ( ) ) ;
241
-
242
- yield call ( showSuccessMessage , `Loaded folder ${ name } .` , 1000 ) ;
228
+ ) ;
243
229
244
- // TODO does not update playground on loading folder
245
- yield call ( console . log , 'ahfdaskjhfkjsadf' , parentId ) ;
246
230
yield put (
247
231
actions . playgroundUpdatePersistenceFolder ( { id, name, parentId, lastSaved : new Date ( ) } )
248
232
) ;
249
233
234
+ // delay to increase likelihood addPersistenceFile for last loaded file has completed
235
+ // and for the toasts to not overlap
236
+ yield call ( ( ) => new Promise ( resolve => setTimeout ( resolve , 1000 ) ) ) ;
237
+ yield call ( showSuccessMessage , `Loaded folder ${ name } .` , 1000 ) ;
250
238
return ;
251
239
}
252
240
241
+ // Below is for handling opening of single files
253
242
toastKey = yield call ( showMessage , {
254
243
message : 'Opening file...' ,
255
244
timeout : 0 ,
@@ -286,15 +275,15 @@ export function* persistenceSaga(): SagaIterator {
286
275
)
287
276
) ;
288
277
}
289
-
290
278
yield call ( showSuccessMessage , `Loaded ${ name } .` , 1000 ) ;
291
279
} catch ( ex ) {
292
280
console . error ( ex ) ;
293
- yield call ( showWarningMessage , `Error while opening file.` , 1000 ) ;
281
+ yield call ( showWarningMessage , `Error while opening file/folder .` , 1000 ) ;
294
282
} finally {
295
283
if ( toastKey ) {
296
284
dismiss ( toastKey ) ;
297
285
}
286
+ yield call ( store . dispatch , actions . updateRefreshFileViewKey ( ) ) ;
298
287
}
299
288
} ) ;
300
289
0 commit comments