@@ -11,6 +11,7 @@ import {
11
11
deleteAllPersistenceFiles ,
12
12
deleteGithubSaveInfo ,
13
13
deletePersistenceFile ,
14
+ deletePersistenceFolderAndChildren ,
14
15
setInBrowserFileSystem ,
15
16
setPersistenceFileLastEditByPath ,
16
17
updateLastEditedFilePath ,
@@ -133,6 +134,33 @@ export const FileSystemReducer: Reducer<FileSystemState, SourceActionType> = cre
133
134
state . persistenceFileArray = newPersistenceFileArray ;
134
135
}
135
136
} )
137
+ . addCase ( deletePersistenceFolderAndChildren , ( state , action ) => { // check if github is syncing?
138
+ const newPersistenceFileArray = state [ 'persistenceFileArray' ] . filter (
139
+ e => e . id !== action . payload . id
140
+ ) ;
141
+ // get children
142
+ // get current level of folder
143
+ const regexResult = filePathRegex . exec ( action . payload . path ! ) ! ;
144
+
145
+ const currFolderSplit : string [ ] = regexResult [ 0 ] . slice ( 1 ) . split ( '/' ) ;
146
+ const folderName = regexResult [ 2 ] ;
147
+ const currFolderLevel = currFolderSplit . length - 1 ;
148
+
149
+ state . persistenceFileArray = newPersistenceFileArray
150
+ . filter ( e => e . path )
151
+ . filter ( e => {
152
+ const r = filePathRegex . exec ( e . path ! ) ! ;
153
+ const currParentFolders = r [ 0 ] . slice ( 1 ) . split ( '/' ) ;
154
+ console . log ( 'currParentFolders' , currParentFolders , 'folderLevel' , currFolderLevel ) ;
155
+ if ( currParentFolders . length <= currFolderLevel ) {
156
+ return true ; // not a child of folder
157
+ }
158
+ if ( currParentFolders [ currFolderLevel ] !== folderName ) {
159
+ return true ; // not a child of folder
160
+ }
161
+ return false ;
162
+ } ) ;
163
+ } )
136
164
. addCase ( deleteAllPersistenceFiles , ( state , action ) => {
137
165
state . persistenceFileArray = [ ] ;
138
166
} )
@@ -158,7 +186,7 @@ export const FileSystemReducer: Reducer<FileSystemState, SourceActionType> = cre
158
186
const regexResult = filePathRegex . exec ( action . payload . newPath ) ! ;
159
187
160
188
const currFolderSplit : string [ ] = regexResult [ 0 ] . slice ( 1 ) . split ( '/' ) ;
161
- const currFolderIndex = currFolderSplit . length - 1 ;
189
+ const currFolderLevel = currFolderSplit . length - 1 ;
162
190
163
191
// /fold1/ becomes ["fold1"]
164
192
// /fold1/fold2/ becomes ["fold1", "fold2"]
@@ -172,15 +200,15 @@ export const FileSystemReducer: Reducer<FileSystemState, SourceActionType> = cre
172
200
. map ( e => {
173
201
const r = filePathRegex . exec ( e . path ! ) ! ;
174
202
const currParentFolders = r [ 0 ] . slice ( 1 ) . split ( '/' ) ;
175
- console . log ( 'currParentFolders' , currParentFolders , 'folderLevel' , currFolderIndex ) ;
176
- if ( currParentFolders . length <= currFolderIndex ) {
203
+ console . log ( 'currParentFolders' , currParentFolders , 'folderLevel' , currFolderLevel ) ;
204
+ if ( currParentFolders . length <= currFolderLevel ) {
177
205
return e ; // not a child of folder
178
206
}
179
- if ( currParentFolders [ currFolderIndex ] !== action . payload . oldFolderName ) {
207
+ if ( currParentFolders [ currFolderLevel ] !== action . payload . oldFolderName ) {
180
208
return e ; // not a child of folder
181
209
}
182
210
// only children remain
183
- currParentFolders [ currFolderIndex ] = action . payload . newFolderName ;
211
+ currParentFolders [ currFolderLevel ] = action . payload . newFolderName ;
184
212
currParentFolders [ 0 ] = '/' + currParentFolders [ 0 ] ;
185
213
const newPath = currParentFolders . join ( '/' ) ;
186
214
console . log ( 'from' , e . path , 'to' , newPath ) ;
0 commit comments