From 3360c7c799a98f7a9fac7421b649309dd7807a3c Mon Sep 17 00:00:00 2001 From: Cassie Tarakajian Date: Thu, 3 Oct 2019 15:51:34 -0400 Subject: [PATCH] fixes #963: fixes bug in which files/folders would get added to selected file (or root), rather than the file that you opened the popover from --- client/modules/IDE/actions/files.js | 18 ++---------------- client/modules/IDE/actions/ide.js | 10 ++++++---- client/modules/IDE/components/FileNode.jsx | 4 ++-- client/modules/IDE/components/Sidebar.jsx | 7 ++++--- client/modules/IDE/reducers/ide.js | 5 +++-- 5 files changed, 17 insertions(+), 27 deletions(-) diff --git a/client/modules/IDE/actions/files.js b/client/modules/IDE/actions/files.js index ff56454a..0bbf292d 100644 --- a/client/modules/IDE/actions/files.js +++ b/client/modules/IDE/actions/files.js @@ -41,14 +41,7 @@ export function updateFileContent(id, content) { export function createFile(formProps) { return (dispatch, getState) => { const state = getState(); - const selectedFile = state.files.find(file => file.isSelectedFile); - const rootFile = state.files.find(file => file.name === 'root'); - let parentId; - if (selectedFile.fileType === 'folder') { - parentId = selectedFile.id; - } else { - parentId = rootFile.id; - } + const { parentId } = state.ide; if (state.project.id) { const postParams = { name: createUniqueName(formProps.name, parentId, state.files), @@ -99,14 +92,7 @@ export function createFile(formProps) { export function createFolder(formProps) { return (dispatch, getState) => { const state = getState(); - const selectedFile = state.files.find(file => file.isSelectedFile); - const rootFile = state.files.find(file => file.name === 'root'); - let parentId; - if (selectedFile.fileType === 'folder') { - parentId = selectedFile.id; - } else { - parentId = rootFile.id; - } + const { parentId } = state.ide; if (state.project.id) { const postParams = { name: createUniqueName(formProps.name, parentId, state.files), diff --git a/client/modules/IDE/actions/ide.js b/client/modules/IDE/actions/ide.js index 1d7c2998..b6351a7d 100644 --- a/client/modules/IDE/actions/ide.js +++ b/client/modules/IDE/actions/ide.js @@ -62,9 +62,10 @@ export function resetSelectedFile(previousId) { }; } -export function newFile() { +export function newFile(parentId) { return { - type: ActionTypes.SHOW_MODAL + type: ActionTypes.SHOW_MODAL, + parentId }; } @@ -122,9 +123,10 @@ export function closeProjectOptions() { }; } -export function newFolder() { +export function newFolder(parentId) { return { - type: ActionTypes.SHOW_NEW_FOLDER_MODAL + type: ActionTypes.SHOW_NEW_FOLDER_MODAL, + parentId }; } diff --git a/client/modules/IDE/components/FileNode.jsx b/client/modules/IDE/components/FileNode.jsx index 1b28bd4e..12496b38 100644 --- a/client/modules/IDE/components/FileNode.jsx +++ b/client/modules/IDE/components/FileNode.jsx @@ -188,7 +188,7 @@ export class FileNode extends React.Component {