@@ -158,10 +158,28 @@ const files = (state, action) => {
158
158
}
159
159
return Object . assign ( { } , file , { blobURL : action . blobURL } ) ;
160
160
} ) ;
161
- case ActionTypes . NEW_PROJECT :
162
- return setFilePaths ( action . files ) ;
163
- case ActionTypes . SET_PROJECT :
164
- return setFilePaths ( action . files ) ;
161
+ case ActionTypes . NEW_PROJECT : {
162
+ const newFiles = action . files . map ( ( file ) => {
163
+ const corrospondingObj = state . find ( ( obj ) => obj . id === file . id ) ;
164
+ if ( corrospondingObj && corrospondingObj . fileType === 'folder' ) {
165
+ const isFolderClosed = corrospondingObj . isFolderClosed || false ;
166
+ return { ...file , isFolderClosed } ;
167
+ }
168
+ return file ;
169
+ } ) ;
170
+ return setFilePaths ( newFiles ) ;
171
+ }
172
+ case ActionTypes . SET_PROJECT : {
173
+ const newFiles = action . files . map ( ( file ) => {
174
+ const corrospondingObj = state . find ( ( obj ) => obj . id === file . id ) ;
175
+ if ( corrospondingObj && corrospondingObj . fileType === 'folder' ) {
176
+ const isFolderClosed = corrospondingObj . isFolderClosed || false ;
177
+ return { ...file , isFolderClosed } ;
178
+ }
179
+ return file ;
180
+ } ) ;
181
+ return setFilePaths ( newFiles ) ;
182
+ }
165
183
case ActionTypes . RESET_PROJECT :
166
184
return initialState ( ) ;
167
185
case ActionTypes . CREATE_FILE : {
@@ -188,6 +206,7 @@ const files = (state, action) => {
188
206
filePath
189
207
}
190
208
] ;
209
+
191
210
return newState . map ( ( file ) => {
192
211
if ( file . id === action . parentId ) {
193
212
file . children = sortedChildrenId ( newState , file . children ) ;
0 commit comments