Revert "Revert "fixes #963: fixes bug in which files/folders would get added to""
This commit is contained in:
parent
25e89b1172
commit
9d8be89df7
5 changed files with 17 additions and 27 deletions
|
@ -41,14 +41,7 @@ export function updateFileContent(id, content) {
|
||||||
export function createFile(formProps) {
|
export function createFile(formProps) {
|
||||||
return (dispatch, getState) => {
|
return (dispatch, getState) => {
|
||||||
const state = getState();
|
const state = getState();
|
||||||
const selectedFile = state.files.find(file => file.isSelectedFile);
|
const { parentId } = state.ide;
|
||||||
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) {
|
if (state.project.id) {
|
||||||
const postParams = {
|
const postParams = {
|
||||||
name: createUniqueName(formProps.name, parentId, state.files),
|
name: createUniqueName(formProps.name, parentId, state.files),
|
||||||
|
@ -99,14 +92,7 @@ export function createFile(formProps) {
|
||||||
export function createFolder(formProps) {
|
export function createFolder(formProps) {
|
||||||
return (dispatch, getState) => {
|
return (dispatch, getState) => {
|
||||||
const state = getState();
|
const state = getState();
|
||||||
const selectedFile = state.files.find(file => file.isSelectedFile);
|
const { parentId } = state.ide;
|
||||||
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) {
|
if (state.project.id) {
|
||||||
const postParams = {
|
const postParams = {
|
||||||
name: createUniqueName(formProps.name, parentId, state.files),
|
name: createUniqueName(formProps.name, parentId, state.files),
|
||||||
|
|
|
@ -62,9 +62,10 @@ export function resetSelectedFile(previousId) {
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
export function newFile() {
|
export function newFile(parentId) {
|
||||||
return {
|
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 {
|
return {
|
||||||
type: ActionTypes.SHOW_NEW_FOLDER_MODAL
|
type: ActionTypes.SHOW_NEW_FOLDER_MODAL,
|
||||||
|
parentId
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -188,7 +188,7 @@ export class FileNode extends React.Component {
|
||||||
<button
|
<button
|
||||||
aria-label="add file"
|
aria-label="add file"
|
||||||
onClick={() => {
|
onClick={() => {
|
||||||
this.props.newFile();
|
this.props.newFile(this.props.id);
|
||||||
setTimeout(() => this.hideFileOptions(), 0);
|
setTimeout(() => this.hideFileOptions(), 0);
|
||||||
}}
|
}}
|
||||||
onBlur={this.onBlurComponent}
|
onBlur={this.onBlurComponent}
|
||||||
|
@ -208,7 +208,7 @@ export class FileNode extends React.Component {
|
||||||
<button
|
<button
|
||||||
aria-label="add folder"
|
aria-label="add folder"
|
||||||
onClick={() => {
|
onClick={() => {
|
||||||
this.props.newFolder();
|
this.props.newFolder(this.props.id);
|
||||||
setTimeout(() => this.hideFileOptions(), 0);
|
setTimeout(() => this.hideFileOptions(), 0);
|
||||||
}}
|
}}
|
||||||
onBlur={this.onBlurComponent}
|
onBlur={this.onBlurComponent}
|
||||||
|
|
|
@ -66,6 +66,7 @@ class Sidebar extends React.Component {
|
||||||
'sidebar--project-options': this.props.projectOptionsVisible,
|
'sidebar--project-options': this.props.projectOptionsVisible,
|
||||||
'sidebar--cant-edit': !canEditProject
|
'sidebar--cant-edit': !canEditProject
|
||||||
});
|
});
|
||||||
|
const rootFile = this.props.files.filter(file => file.name === 'root')[0];
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<nav className={sidebarClass} title="file-navigation" >
|
<nav className={sidebarClass} title="file-navigation" >
|
||||||
|
@ -90,7 +91,7 @@ class Sidebar extends React.Component {
|
||||||
<button
|
<button
|
||||||
aria-label="add folder"
|
aria-label="add folder"
|
||||||
onClick={() => {
|
onClick={() => {
|
||||||
this.props.newFolder();
|
this.props.newFolder(rootFile.id);
|
||||||
setTimeout(this.props.closeProjectOptions, 0);
|
setTimeout(this.props.closeProjectOptions, 0);
|
||||||
}}
|
}}
|
||||||
onBlur={this.onBlurComponent}
|
onBlur={this.onBlurComponent}
|
||||||
|
@ -103,7 +104,7 @@ class Sidebar extends React.Component {
|
||||||
<button
|
<button
|
||||||
aria-label="add file"
|
aria-label="add file"
|
||||||
onClick={() => {
|
onClick={() => {
|
||||||
this.props.newFile();
|
this.props.newFile(rootFile.id);
|
||||||
setTimeout(this.props.closeProjectOptions, 0);
|
setTimeout(this.props.closeProjectOptions, 0);
|
||||||
}}
|
}}
|
||||||
onBlur={this.onBlurComponent}
|
onBlur={this.onBlurComponent}
|
||||||
|
@ -116,7 +117,7 @@ class Sidebar extends React.Component {
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
<ConnectedFileNode
|
<ConnectedFileNode
|
||||||
id={this.props.files.filter(file => file.name === 'root')[0].id}
|
id={rootFile.id}
|
||||||
canEdit={canEditProject}
|
canEdit={canEditProject}
|
||||||
/>
|
/>
|
||||||
</nav>
|
</nav>
|
||||||
|
|
|
@ -24,6 +24,7 @@ const initialState = {
|
||||||
previousPath: '/',
|
previousPath: '/',
|
||||||
errorType: undefined,
|
errorType: undefined,
|
||||||
runtimeErrorWarningVisible: true,
|
runtimeErrorWarningVisible: true,
|
||||||
|
parentId: undefined
|
||||||
};
|
};
|
||||||
|
|
||||||
const ide = (state = initialState, action) => {
|
const ide = (state = initialState, action) => {
|
||||||
|
@ -39,7 +40,7 @@ const ide = (state = initialState, action) => {
|
||||||
case ActionTypes.CONSOLE_EVENT:
|
case ActionTypes.CONSOLE_EVENT:
|
||||||
return Object.assign({}, state, { consoleEvent: action.event });
|
return Object.assign({}, state, { consoleEvent: action.event });
|
||||||
case ActionTypes.SHOW_MODAL:
|
case ActionTypes.SHOW_MODAL:
|
||||||
return Object.assign({}, state, { modalIsVisible: true });
|
return Object.assign({}, state, { modalIsVisible: true, parentId: action.parentId });
|
||||||
case ActionTypes.HIDE_MODAL:
|
case ActionTypes.HIDE_MODAL:
|
||||||
return Object.assign({}, state, { modalIsVisible: false });
|
return Object.assign({}, state, { modalIsVisible: false });
|
||||||
case ActionTypes.COLLAPSE_SIDEBAR:
|
case ActionTypes.COLLAPSE_SIDEBAR:
|
||||||
|
@ -61,7 +62,7 @@ const ide = (state = initialState, action) => {
|
||||||
case ActionTypes.CLOSE_PROJECT_OPTIONS:
|
case ActionTypes.CLOSE_PROJECT_OPTIONS:
|
||||||
return Object.assign({}, state, { projectOptionsVisible: false });
|
return Object.assign({}, state, { projectOptionsVisible: false });
|
||||||
case ActionTypes.SHOW_NEW_FOLDER_MODAL:
|
case ActionTypes.SHOW_NEW_FOLDER_MODAL:
|
||||||
return Object.assign({}, state, { newFolderModalVisible: true });
|
return Object.assign({}, state, { newFolderModalVisible: true, parentId: action.parentId });
|
||||||
case ActionTypes.CLOSE_NEW_FOLDER_MODAL:
|
case ActionTypes.CLOSE_NEW_FOLDER_MODAL:
|
||||||
return Object.assign({}, state, { newFolderModalVisible: false });
|
return Object.assign({}, state, { newFolderModalVisible: false });
|
||||||
case ActionTypes.SHOW_SHARE_MODAL:
|
case ActionTypes.SHOW_SHARE_MODAL:
|
||||||
|
|
Loading…
Reference in a new issue