From 6a29bd4ce94af76e06048d2809a3c508647712a8 Mon Sep 17 00:00:00 2001 From: Cassie Tarakajian Date: Mon, 7 Oct 2019 18:23:58 -0400 Subject: [PATCH] Revert "fixes #963: fixes bug in which files/folders would get added to" --- 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, 27 insertions(+), 17 deletions(-) diff --git a/client/modules/IDE/actions/files.js b/client/modules/IDE/actions/files.js index 0bbf292d..ff56454a 100644 --- a/client/modules/IDE/actions/files.js +++ b/client/modules/IDE/actions/files.js @@ -41,7 +41,14 @@ export function updateFileContent(id, content) { export function createFile(formProps) { return (dispatch, getState) => { const state = getState(); - const { parentId } = state.ide; + 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; + } if (state.project.id) { const postParams = { name: createUniqueName(formProps.name, parentId, state.files), @@ -92,7 +99,14 @@ export function createFile(formProps) { export function createFolder(formProps) { return (dispatch, getState) => { const state = getState(); - const { parentId } = state.ide; + 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; + } 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 b6351a7d..1d7c2998 100644 --- a/client/modules/IDE/actions/ide.js +++ b/client/modules/IDE/actions/ide.js @@ -62,10 +62,9 @@ export function resetSelectedFile(previousId) { }; } -export function newFile(parentId) { +export function newFile() { return { - type: ActionTypes.SHOW_MODAL, - parentId + type: ActionTypes.SHOW_MODAL }; } @@ -123,10 +122,9 @@ export function closeProjectOptions() { }; } -export function newFolder(parentId) { +export function newFolder() { return { - type: ActionTypes.SHOW_NEW_FOLDER_MODAL, - parentId + type: ActionTypes.SHOW_NEW_FOLDER_MODAL }; } diff --git a/client/modules/IDE/components/FileNode.jsx b/client/modules/IDE/components/FileNode.jsx index 12496b38..1b28bd4e 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 {