From bf61fdd992dec441208a6ec3dd1892c625810801 Mon Sep 17 00:00:00 2001 From: catarak Date: Tue, 30 Aug 2016 14:39:37 -0400 Subject: [PATCH] nested css styling fixes --- client/modules/IDE/actions/files.js | 34 +++++++++++----- client/modules/IDE/components/FileNode.js | 4 +- client/modules/IDE/components/NewFileModal.js | 12 +----- client/modules/IDE/pages/IDEView.js | 4 +- client/modules/IDE/reducers/files.js | 1 + client/styles/components/_sidebar.scss | 40 +++++++++++++++---- 6 files changed, 65 insertions(+), 30 deletions(-) diff --git a/client/modules/IDE/actions/files.js b/client/modules/IDE/actions/files.js index 5d839465..17b5cf1c 100644 --- a/client/modules/IDE/actions/files.js +++ b/client/modules/IDE/actions/files.js @@ -69,14 +69,21 @@ export function getBlobUrl(file) { export function createFile(formProps) { return (dispatch, getState) => { const state = getState(); - const rootFile = state.files.filter(file => file.name === 'root')[0]; + const selectedFile = state.files.find(file => file.isSelected); + 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, state.files), url: formProps.url, content: formProps.content || '', // TODO pass parent id to API, once there are folders - parentId: rootFile.id + parentId }; axios.post(`${ROOT_URL}/projects/${state.project.id}/files`, postParams, { withCredentials: true }) .then(response => { @@ -86,7 +93,7 @@ export function createFile(formProps) { dispatch({ type: ActionTypes.CREATE_FILE, ...response.data, - parentId: rootFile.id + parentId }); dispatch({ type: ActionTypes.HIDE_MODAL @@ -109,7 +116,7 @@ export function createFile(formProps) { url: formProps.url, content: formProps.content || '', // TODO pass parent id from File Tree - parentId: rootFile.id + parentId }); dispatch({ type: ActionTypes.HIDE_MODAL @@ -121,12 +128,20 @@ export function createFile(formProps) { export function createFolder(formProps) { return (dispatch, getState) => { const state = getState(); - const rootFile = state.files.filter(file => file.name === 'root')[0]; + const selectedFile = state.files.find(file => file.isSelected); + 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, state.files), content: '', - parentId: rootFile.id, + children: [], + parentId, fileType: 'folder' }; axios.post(`${ROOT_URL}/projects/${state.project.id}/files`, postParams, { withCredentials: true }) @@ -134,7 +149,7 @@ export function createFolder(formProps) { dispatch({ type: ActionTypes.CREATE_FILE, ...response.data, - parentId: rootFile.id + parentId }); dispatch({ type: ActionTypes.CLOSE_NEW_FOLDER_MODAL @@ -153,8 +168,9 @@ export function createFolder(formProps) { _id: id, content: '', // TODO pass parent id from File Tree - parentId: rootFile.id, - fileType: 'folder' + parentId, + fileType: 'folder', + children: [] }); dispatch({ type: ActionTypes.CLOSE_NEW_FOLDER_MODAL diff --git a/client/modules/IDE/components/FileNode.js b/client/modules/IDE/components/FileNode.js index 0ddf21f9..c68dda89 100644 --- a/client/modules/IDE/components/FileNode.js +++ b/client/modules/IDE/components/FileNode.js @@ -56,6 +56,7 @@ export class FileNode extends React.Component { render() { let itemClass = classNames({ + 'sidebar__root-item': this.props.name === 'root', 'sidebar__file-item': this.props.name !== 'root', 'sidebar__file-item--selected': this.props.isSelected, 'sidebar__file-item--open': this.props.isOptionsOpen, @@ -71,6 +72,7 @@ export class FileNode extends React.Component { if (this.props.name !== 'root') { return (
+ {(() => { // eslint-disable-line if (this.props.fileType === 'file') { return ( @@ -157,7 +159,7 @@ export class FileNode extends React.Component { {(() => { // eslint-disable-line if (this.props.children) { return ( -