From ea38451386eb3b3e5a63e4fa5d0b24db706cd6a0 Mon Sep 17 00:00:00 2001 From: shreyash Date: Mon, 30 Oct 2023 02:26:33 +0530 Subject: [PATCH 1/5] fix folder auto-expand on save --- client/modules/IDE/actions/files.js | 4 +- client/modules/IDE/reducers/files.js | 85 +++++++++++++++++++++----- client/modules/IDE/reducers/project.js | 3 +- 3 files changed, 74 insertions(+), 18 deletions(-) diff --git a/client/modules/IDE/actions/files.js b/client/modules/IDE/actions/files.js index f87f5d1c6d..ffac4ad9e5 100644 --- a/client/modules/IDE/actions/files.js +++ b/client/modules/IDE/actions/files.js @@ -63,7 +63,7 @@ export function submitFile(formProps, files, parentId, projectId) { children: [] }; return apiClient - .post(`/projects/${projectId}/files`, postParams) + .post(`/projects/${projectId}/files`, postParams) // .then((response) => ({ file: response.data.updatedFile, updatedAt: response.data.project.updatedAt @@ -93,6 +93,7 @@ export function handleCreateFile(formProps, setSelected = true) { submitFile(formProps, files, parentId, projectId) .then((response) => { const { file, updatedAt } = response; + file.fileType = 'file'; dispatch(createFile(file, parentId)); if (updatedAt) dispatch(setProjectSavedTime(updatedAt)); dispatch(closeNewFileModal()); @@ -153,6 +154,7 @@ export function handleCreateFolder(formProps) { submitFolder(formProps, files, parentId, projectId) .then((response) => { const { file, updatedAt } = response; + file.isFolderClosed = false; dispatch(createFile(file, parentId)); if (updatedAt) dispatch(setProjectSavedTime(updatedAt)); dispatch(closeNewFolderModal()); diff --git a/client/modules/IDE/reducers/files.js b/client/modules/IDE/reducers/files.js index 42635fe3e4..16cd73e409 100644 --- a/client/modules/IDE/reducers/files.js +++ b/client/modules/IDE/reducers/files.js @@ -18,7 +18,8 @@ export const initialState = () => { _id: r, children: [b, a, c], fileType: 'folder', - content: '' + content: '', + isFolderClosed: false // }, { name: 'sketch.js', @@ -159,8 +160,22 @@ const files = (state, action) => { return Object.assign({}, file, { blobURL: action.blobURL }); }); case ActionTypes.NEW_PROJECT: + action.files = action.files.map((file) => { + const corrospondingObj = state.find((obj) => obj.id === file.id); + if (corrospondingObj && corrospondingObj.fileType === 'folder') { + file.isFolderClosed = corrospondingObj.isFolderClosed; + } + return file; + }); return setFilePaths(action.files); case ActionTypes.SET_PROJECT: + action.files = action.files.map((file) => { + const corrospondingObj = state.find((obj) => obj.id === file.id); + if (corrospondingObj && corrospondingObj.fileType === 'folder') { + file.isFolderClosed = corrospondingObj.isFolderClosed; + } + return file; + }); return setFilePaths(action.files); case ActionTypes.RESET_PROJECT: return initialState(); @@ -175,19 +190,53 @@ const files = (state, action) => { parentFile.name === 'root' ? '' : `${parentFile.filePath}/${parentFile.name}`; - const newState = [ - ...updateParent(state, action), - { - name: action.name, - id: action.id, - _id: action._id, - content: action.content, - url: action.url, - children: action.children, - fileType: action.fileType || 'file', - filePath - } - ]; + // const newState = [ + // ...updateParent(state, action), + // { + // name: action.name, + // id: action.id, + // _id: action._id, + // content: action.content, + // url: action.url, + // children: action.children, + // fileType: action.fileType || 'file', + // filePath, + // isExpanded: action.isExpanded + // } + // ]; + + let newState = null; + if (action.fileType === 'folder') { + newState = [ + ...updateParent(state, action), + { + name: action.name, + id: action.id, + _id: action._id, + content: action.content, + url: action.url, + children: action.children, + fileType: 'folder', + filePath, + isFolderClosed: false + } + ]; + } else { + newState = [ + ...updateParent(state, action), + { + name: action.name, + id: action.id, + _id: action._id, + content: action.content, + url: action.url, + children: action.children, + fileType: 'file', + filePath + } + ]; + } + return newState.map((file) => { if (file.id === action.parentId) { file.children = sortedChildrenId(newState, file.children); @@ -236,14 +285,18 @@ const files = (state, action) => { case ActionTypes.SHOW_FOLDER_CHILDREN: return state.map((file) => { if (file.id === action.id) { - return Object.assign({}, file, { isFolderClosed: false }); + return Object.assign({}, file, { + isFolderClosed: false + }); } return file; }); case ActionTypes.HIDE_FOLDER_CHILDREN: return state.map((file) => { if (file.id === action.id) { - return Object.assign({}, file, { isFolderClosed: true }); + return Object.assign({}, file, { + isFolderClosed: true + }); } return file; }); diff --git a/client/modules/IDE/reducers/project.js b/client/modules/IDE/reducers/project.js index 89a03529e6..93b3fd130e 100644 --- a/client/modules/IDE/reducers/project.js +++ b/client/modules/IDE/reducers/project.js @@ -33,7 +33,8 @@ const project = (state, action) => { name: action.project.name, updatedAt: action.project.updatedAt, owner: action.owner, - isSaving: false + isSaving: false, + files: action.project.files }; case ActionTypes.RESET_PROJECT: return initialState(); From 53bc274c8facfe53277e609b952624a36facdde9 Mon Sep 17 00:00:00 2001 From: shreyash Date: Mon, 30 Oct 2023 02:35:26 +0530 Subject: [PATCH 2/5] fix folder auto-expand on save --- client/modules/IDE/actions/files.js | 2 +- client/modules/IDE/reducers/files.js | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/client/modules/IDE/actions/files.js b/client/modules/IDE/actions/files.js index ffac4ad9e5..baacde6ec0 100644 --- a/client/modules/IDE/actions/files.js +++ b/client/modules/IDE/actions/files.js @@ -63,7 +63,7 @@ export function submitFile(formProps, files, parentId, projectId) { children: [] }; return apiClient - .post(`/projects/${projectId}/files`, postParams) // + .post(`/projects/${projectId}/files`, postParams) .then((response) => ({ file: response.data.updatedFile, updatedAt: response.data.project.updatedAt diff --git a/client/modules/IDE/reducers/files.js b/client/modules/IDE/reducers/files.js index 16cd73e409..730b0a4d57 100644 --- a/client/modules/IDE/reducers/files.js +++ b/client/modules/IDE/reducers/files.js @@ -19,7 +19,7 @@ export const initialState = () => { children: [b, a, c], fileType: 'folder', content: '', - isFolderClosed: false // + isFolderClosed: false }, { name: 'sketch.js', From beafc04260fab3831f1e74c1b2f55d6d3b5a85b5 Mon Sep 17 00:00:00 2001 From: rajatmohan22 Date: Sat, 23 Sep 2023 20:07:25 +0530 Subject: [PATCH 3/5] delete session after logout --- server/controllers/session.controller.js | 12 ++++++++++-- 1 file changed, 10 insertions(+), 2 deletions(-) diff --git a/server/controllers/session.controller.js b/server/controllers/session.controller.js index 29b7f1be3f..df014c460b 100644 --- a/server/controllers/session.controller.js +++ b/server/controllers/session.controller.js @@ -31,11 +31,19 @@ export function getSession(req, res) { } export function destroySession(req, res, next) { - req.logout((err) => { + req.session.destroy((err) => { if (err) { next(err); return; } - res.json({ success: true }); + req.logout((err) => { + if (err) { + next(err); + return; + } + + res.json({ success: true }); + res.redirect('/login'); + }); }); } From 4af0d77b877dc32e23077f57d50e5f096be09b62 Mon Sep 17 00:00:00 2001 From: rajatmohan22 Date: Sun, 24 Sep 2023 01:42:50 +0530 Subject: [PATCH 4/5] remove res.redirect && rename err --- server/controllers/session.controller.js | 8 +++----- 1 file changed, 3 insertions(+), 5 deletions(-) diff --git a/server/controllers/session.controller.js b/server/controllers/session.controller.js index df014c460b..458e17def1 100644 --- a/server/controllers/session.controller.js +++ b/server/controllers/session.controller.js @@ -36,14 +36,12 @@ export function destroySession(req, res, next) { next(err); return; } - req.logout((err) => { - if (err) { - next(err); + req.logout((error) => { + if (error) { + next(error); return; } - res.json({ success: true }); - res.redirect('/login'); }); }); } From 54744a587d5bd9d7bafabbadd3e74c3b374f6379 Mon Sep 17 00:00:00 2001 From: shreyash Date: Tue, 31 Oct 2023 20:16:57 +0530 Subject: [PATCH 5/5] fix : folders auto-expand on save --- client/modules/IDE/actions/files.js | 2 - client/modules/IDE/reducers/files.js | 90 ++++++++------------------ client/modules/IDE/reducers/project.js | 3 +- 3 files changed, 29 insertions(+), 66 deletions(-) diff --git a/client/modules/IDE/actions/files.js b/client/modules/IDE/actions/files.js index baacde6ec0..f87f5d1c6d 100644 --- a/client/modules/IDE/actions/files.js +++ b/client/modules/IDE/actions/files.js @@ -93,7 +93,6 @@ export function handleCreateFile(formProps, setSelected = true) { submitFile(formProps, files, parentId, projectId) .then((response) => { const { file, updatedAt } = response; - file.fileType = 'file'; dispatch(createFile(file, parentId)); if (updatedAt) dispatch(setProjectSavedTime(updatedAt)); dispatch(closeNewFileModal()); @@ -154,7 +153,6 @@ export function handleCreateFolder(formProps) { submitFolder(formProps, files, parentId, projectId) .then((response) => { const { file, updatedAt } = response; - file.isFolderClosed = false; dispatch(createFile(file, parentId)); if (updatedAt) dispatch(setProjectSavedTime(updatedAt)); dispatch(closeNewFolderModal()); diff --git a/client/modules/IDE/reducers/files.js b/client/modules/IDE/reducers/files.js index 730b0a4d57..de1b9b1aa7 100644 --- a/client/modules/IDE/reducers/files.js +++ b/client/modules/IDE/reducers/files.js @@ -18,8 +18,7 @@ export const initialState = () => { _id: r, children: [b, a, c], fileType: 'folder', - content: '', - isFolderClosed: false + content: '' }, { name: 'sketch.js', @@ -159,24 +158,28 @@ const files = (state, action) => { } return Object.assign({}, file, { blobURL: action.blobURL }); }); - case ActionTypes.NEW_PROJECT: - action.files = action.files.map((file) => { + case ActionTypes.NEW_PROJECT: { + const newFiles = action.files.map((file) => { const corrospondingObj = state.find((obj) => obj.id === file.id); if (corrospondingObj && corrospondingObj.fileType === 'folder') { - file.isFolderClosed = corrospondingObj.isFolderClosed; + const isFolderClosed = corrospondingObj.isFolderClosed || false; + return { ...file, isFolderClosed }; } return file; }); - return setFilePaths(action.files); - case ActionTypes.SET_PROJECT: - action.files = action.files.map((file) => { + return setFilePaths(newFiles); + } + case ActionTypes.SET_PROJECT: { + const newFiles = action.files.map((file) => { const corrospondingObj = state.find((obj) => obj.id === file.id); if (corrospondingObj && corrospondingObj.fileType === 'folder') { - file.isFolderClosed = corrospondingObj.isFolderClosed; + const isFolderClosed = corrospondingObj.isFolderClosed || false; + return { ...file, isFolderClosed }; } return file; }); - return setFilePaths(action.files); + return setFilePaths(newFiles); + } case ActionTypes.RESET_PROJECT: return initialState(); case ActionTypes.CREATE_FILE: { @@ -190,52 +193,19 @@ const files = (state, action) => { parentFile.name === 'root' ? '' : `${parentFile.filePath}/${parentFile.name}`; - // const newState = [ - // ...updateParent(state, action), - // { - // name: action.name, - // id: action.id, - // _id: action._id, - // content: action.content, - // url: action.url, - // children: action.children, - // fileType: action.fileType || 'file', - // filePath, - // isExpanded: action.isExpanded - // } - // ]; - - let newState = null; - if (action.fileType === 'folder') { - newState = [ - ...updateParent(state, action), - { - name: action.name, - id: action.id, - _id: action._id, - content: action.content, - url: action.url, - children: action.children, - fileType: 'folder', - filePath, - isFolderClosed: false - } - ]; - } else { - newState = [ - ...updateParent(state, action), - { - name: action.name, - id: action.id, - _id: action._id, - content: action.content, - url: action.url, - children: action.children, - fileType: 'file', - filePath - } - ]; - } + const newState = [ + ...updateParent(state, action), + { + name: action.name, + id: action.id, + _id: action._id, + content: action.content, + url: action.url, + children: action.children, + fileType: action.fileType || 'file', + filePath + } + ]; return newState.map((file) => { if (file.id === action.parentId) { @@ -285,18 +255,14 @@ const files = (state, action) => { case ActionTypes.SHOW_FOLDER_CHILDREN: return state.map((file) => { if (file.id === action.id) { - return Object.assign({}, file, { - isFolderClosed: false - }); + return Object.assign({}, file, { isFolderClosed: false }); } return file; }); case ActionTypes.HIDE_FOLDER_CHILDREN: return state.map((file) => { if (file.id === action.id) { - return Object.assign({}, file, { - isFolderClosed: true - }); + return Object.assign({}, file, { isFolderClosed: true }); } return file; }); diff --git a/client/modules/IDE/reducers/project.js b/client/modules/IDE/reducers/project.js index 93b3fd130e..89a03529e6 100644 --- a/client/modules/IDE/reducers/project.js +++ b/client/modules/IDE/reducers/project.js @@ -33,8 +33,7 @@ const project = (state, action) => { name: action.project.name, updatedAt: action.project.updatedAt, owner: action.owner, - isSaving: false, - files: action.project.files + isSaving: false }; case ActionTypes.RESET_PROJECT: return initialState();