Skip to content

Commit 54744a5

Browse files
committed
fix : folders auto-expand on save
1 parent 4af0d77 commit 54744a5

File tree

3 files changed

+29
-66
lines changed

3 files changed

+29
-66
lines changed

client/modules/IDE/actions/files.js

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -93,7 +93,6 @@ export function handleCreateFile(formProps, setSelected = true) {
9393
submitFile(formProps, files, parentId, projectId)
9494
.then((response) => {
9595
const { file, updatedAt } = response;
96-
file.fileType = 'file';
9796
dispatch(createFile(file, parentId));
9897
if (updatedAt) dispatch(setProjectSavedTime(updatedAt));
9998
dispatch(closeNewFileModal());
@@ -154,7 +153,6 @@ export function handleCreateFolder(formProps) {
154153
submitFolder(formProps, files, parentId, projectId)
155154
.then((response) => {
156155
const { file, updatedAt } = response;
157-
file.isFolderClosed = false;
158156
dispatch(createFile(file, parentId));
159157
if (updatedAt) dispatch(setProjectSavedTime(updatedAt));
160158
dispatch(closeNewFolderModal());

client/modules/IDE/reducers/files.js

Lines changed: 28 additions & 62 deletions
Original file line numberDiff line numberDiff line change
@@ -18,8 +18,7 @@ export const initialState = () => {
1818
_id: r,
1919
children: [b, a, c],
2020
fileType: 'folder',
21-
content: '',
22-
isFolderClosed: false
21+
content: ''
2322
},
2423
{
2524
name: 'sketch.js',
@@ -159,24 +158,28 @@ const files = (state, action) => {
159158
}
160159
return Object.assign({}, file, { blobURL: action.blobURL });
161160
});
162-
case ActionTypes.NEW_PROJECT:
163-
action.files = action.files.map((file) => {
161+
case ActionTypes.NEW_PROJECT: {
162+
const newFiles = action.files.map((file) => {
164163
const corrospondingObj = state.find((obj) => obj.id === file.id);
165164
if (corrospondingObj && corrospondingObj.fileType === 'folder') {
166-
file.isFolderClosed = corrospondingObj.isFolderClosed;
165+
const isFolderClosed = corrospondingObj.isFolderClosed || false;
166+
return { ...file, isFolderClosed };
167167
}
168168
return file;
169169
});
170-
return setFilePaths(action.files);
171-
case ActionTypes.SET_PROJECT:
172-
action.files = action.files.map((file) => {
170+
return setFilePaths(newFiles);
171+
}
172+
case ActionTypes.SET_PROJECT: {
173+
const newFiles = action.files.map((file) => {
173174
const corrospondingObj = state.find((obj) => obj.id === file.id);
174175
if (corrospondingObj && corrospondingObj.fileType === 'folder') {
175-
file.isFolderClosed = corrospondingObj.isFolderClosed;
176+
const isFolderClosed = corrospondingObj.isFolderClosed || false;
177+
return { ...file, isFolderClosed };
176178
}
177179
return file;
178180
});
179-
return setFilePaths(action.files);
181+
return setFilePaths(newFiles);
182+
}
180183
case ActionTypes.RESET_PROJECT:
181184
return initialState();
182185
case ActionTypes.CREATE_FILE: {
@@ -190,52 +193,19 @@ const files = (state, action) => {
190193
parentFile.name === 'root'
191194
? ''
192195
: `${parentFile.filePath}/${parentFile.name}`;
193-
// const newState = [
194-
// ...updateParent(state, action),
195-
// {
196-
// name: action.name,
197-
// id: action.id,
198-
// _id: action._id,
199-
// content: action.content,
200-
// url: action.url,
201-
// children: action.children,
202-
// fileType: action.fileType || 'file',
203-
// filePath,
204-
// isExpanded: action.isExpanded
205-
// }
206-
// ];
207-
208-
let newState = null;
209-
if (action.fileType === 'folder') {
210-
newState = [
211-
...updateParent(state, action),
212-
{
213-
name: action.name,
214-
id: action.id,
215-
_id: action._id,
216-
content: action.content,
217-
url: action.url,
218-
children: action.children,
219-
fileType: 'folder',
220-
filePath,
221-
isFolderClosed: false
222-
}
223-
];
224-
} else {
225-
newState = [
226-
...updateParent(state, action),
227-
{
228-
name: action.name,
229-
id: action.id,
230-
_id: action._id,
231-
content: action.content,
232-
url: action.url,
233-
children: action.children,
234-
fileType: 'file',
235-
filePath
236-
}
237-
];
238-
}
196+
const newState = [
197+
...updateParent(state, action),
198+
{
199+
name: action.name,
200+
id: action.id,
201+
_id: action._id,
202+
content: action.content,
203+
url: action.url,
204+
children: action.children,
205+
fileType: action.fileType || 'file',
206+
filePath
207+
}
208+
];
239209

240210
return newState.map((file) => {
241211
if (file.id === action.parentId) {
@@ -285,18 +255,14 @@ const files = (state, action) => {
285255
case ActionTypes.SHOW_FOLDER_CHILDREN:
286256
return state.map((file) => {
287257
if (file.id === action.id) {
288-
return Object.assign({}, file, {
289-
isFolderClosed: false
290-
});
258+
return Object.assign({}, file, { isFolderClosed: false });
291259
}
292260
return file;
293261
});
294262
case ActionTypes.HIDE_FOLDER_CHILDREN:
295263
return state.map((file) => {
296264
if (file.id === action.id) {
297-
return Object.assign({}, file, {
298-
isFolderClosed: true
299-
});
265+
return Object.assign({}, file, { isFolderClosed: true });
300266
}
301267
return file;
302268
});

client/modules/IDE/reducers/project.js

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -33,8 +33,7 @@ const project = (state, action) => {
3333
name: action.project.name,
3434
updatedAt: action.project.updatedAt,
3535
owner: action.owner,
36-
isSaving: false,
37-
files: action.project.files
36+
isSaving: false
3837
};
3938
case ActionTypes.RESET_PROJECT:
4039
return initialState();

0 commit comments

Comments
 (0)