nested css styling fixes

This commit is contained in:
catarak 2016-08-30 14:39:37 -04:00
parent 245ca63a5d
commit bf61fdd992
6 changed files with 65 additions and 30 deletions

View file

@ -69,14 +69,21 @@ export function getBlobUrl(file) {
export function createFile(formProps) { export function createFile(formProps) {
return (dispatch, getState) => { return (dispatch, getState) => {
const state = 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) { if (state.project.id) {
const postParams = { const postParams = {
name: createUniqueName(formProps.name, state.files), name: createUniqueName(formProps.name, state.files),
url: formProps.url, url: formProps.url,
content: formProps.content || '', content: formProps.content || '',
// TODO pass parent id to API, once there are folders // 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 }) axios.post(`${ROOT_URL}/projects/${state.project.id}/files`, postParams, { withCredentials: true })
.then(response => { .then(response => {
@ -86,7 +93,7 @@ export function createFile(formProps) {
dispatch({ dispatch({
type: ActionTypes.CREATE_FILE, type: ActionTypes.CREATE_FILE,
...response.data, ...response.data,
parentId: rootFile.id parentId
}); });
dispatch({ dispatch({
type: ActionTypes.HIDE_MODAL type: ActionTypes.HIDE_MODAL
@ -109,7 +116,7 @@ export function createFile(formProps) {
url: formProps.url, url: formProps.url,
content: formProps.content || '', content: formProps.content || '',
// TODO pass parent id from File Tree // TODO pass parent id from File Tree
parentId: rootFile.id parentId
}); });
dispatch({ dispatch({
type: ActionTypes.HIDE_MODAL type: ActionTypes.HIDE_MODAL
@ -121,12 +128,20 @@ 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 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) { if (state.project.id) {
const postParams = { const postParams = {
name: createUniqueName(formProps.name, state.files), name: createUniqueName(formProps.name, state.files),
content: '', content: '',
parentId: rootFile.id, children: [],
parentId,
fileType: 'folder' fileType: 'folder'
}; };
axios.post(`${ROOT_URL}/projects/${state.project.id}/files`, postParams, { withCredentials: true }) axios.post(`${ROOT_URL}/projects/${state.project.id}/files`, postParams, { withCredentials: true })
@ -134,7 +149,7 @@ export function createFolder(formProps) {
dispatch({ dispatch({
type: ActionTypes.CREATE_FILE, type: ActionTypes.CREATE_FILE,
...response.data, ...response.data,
parentId: rootFile.id parentId
}); });
dispatch({ dispatch({
type: ActionTypes.CLOSE_NEW_FOLDER_MODAL type: ActionTypes.CLOSE_NEW_FOLDER_MODAL
@ -153,8 +168,9 @@ export function createFolder(formProps) {
_id: id, _id: id,
content: '', content: '',
// TODO pass parent id from File Tree // TODO pass parent id from File Tree
parentId: rootFile.id, parentId,
fileType: 'folder' fileType: 'folder',
children: []
}); });
dispatch({ dispatch({
type: ActionTypes.CLOSE_NEW_FOLDER_MODAL type: ActionTypes.CLOSE_NEW_FOLDER_MODAL

View file

@ -56,6 +56,7 @@ export class FileNode extends React.Component {
render() { render() {
let itemClass = classNames({ let itemClass = classNames({
'sidebar__root-item': this.props.name === 'root',
'sidebar__file-item': this.props.name !== 'root', 'sidebar__file-item': this.props.name !== 'root',
'sidebar__file-item--selected': this.props.isSelected, 'sidebar__file-item--selected': this.props.isSelected,
'sidebar__file-item--open': this.props.isOptionsOpen, 'sidebar__file-item--open': this.props.isOptionsOpen,
@ -71,6 +72,7 @@ export class FileNode extends React.Component {
if (this.props.name !== 'root') { if (this.props.name !== 'root') {
return ( return (
<div className="file-item__content"> <div className="file-item__content">
<span className="file-item__spacer"></span>
{(() => { // eslint-disable-line {(() => { // eslint-disable-line
if (this.props.fileType === 'file') { if (this.props.fileType === 'file') {
return ( return (
@ -157,7 +159,7 @@ export class FileNode extends React.Component {
{(() => { // eslint-disable-line {(() => { // eslint-disable-line
if (this.props.children) { if (this.props.children) {
return ( return (
<ul> <ul className="file-item__children">
{this.props.children.map(this.renderChild)} {this.props.children.map(this.renderChild)}
</ul> </ul>
); );

View file

@ -1,8 +1,6 @@
import React, { PropTypes } from 'react'; import React, { PropTypes } from 'react';
import { bindActionCreators } from 'redux';
import { reduxForm } from 'redux-form'; import { reduxForm } from 'redux-form';
import NewFileForm from './NewFileForm'; import NewFileForm from './NewFileForm';
import * as FileActions from '../actions/files';
import classNames from 'classnames'; import classNames from 'classnames';
import InlineSVG from 'react-inlinesvg'; import InlineSVG from 'react-inlinesvg';
const exitUrl = require('../../../images/exit.svg'); const exitUrl = require('../../../images/exit.svg');
@ -48,14 +46,6 @@ NewFileModal.propTypes = {
canUploadMedia: PropTypes.bool.isRequired canUploadMedia: PropTypes.bool.isRequired
}; };
function mapStateToProps() {
return {};
}
function mapDispatchToProps(dispatch) {
return bindActionCreators(FileActions, dispatch);
}
function validate(formProps) { function validate(formProps) {
const errors = {}; const errors = {};
@ -73,4 +63,4 @@ export default reduxForm({
form: 'new-file', form: 'new-file',
fields: ['name'], fields: ['name'],
validate validate
}, mapStateToProps, mapDispatchToProps)(NewFileModal); })(NewFileModal);

View file

@ -258,6 +258,7 @@ class IDEView extends React.Component {
<NewFileModal <NewFileModal
canUploadMedia={this.props.user.authenticated} canUploadMedia={this.props.user.authenticated}
closeModal={this.props.closeNewFileModal} closeModal={this.props.closeNewFileModal}
createFile={this.props.createFile}
/> />
); );
} }
@ -393,7 +394,8 @@ IDEView.propTypes = {
closeProjectOptions: PropTypes.func.isRequired, closeProjectOptions: PropTypes.func.isRequired,
newFolder: PropTypes.func.isRequired, newFolder: PropTypes.func.isRequired,
closeNewFolderModal: PropTypes.func.isRequired, closeNewFolderModal: PropTypes.func.isRequired,
createFolder: PropTypes.func.isRequired createFolder: PropTypes.func.isRequired,
createFile: PropTypes.func.isRequired,
}; };
function mapStateToProps(state) { function mapStateToProps(state) {

View file

@ -111,6 +111,7 @@ const files = (state, action) => {
_id: action._id, _id: action._id,
content: action.content, content: action.content,
url: action.url, url: action.url,
children: action.children,
fileType: action.fileType || 'file' }]; fileType: action.fileType || 'file' }];
} }
case ActionTypes.SHOW_FILE_OPTIONS: case ActionTypes.SHOW_FILE_OPTIONS:

View file

@ -35,25 +35,49 @@
} }
} }
.sidebar__root-item {
position: relative;
}
.sidebar__file-item { .sidebar__file-item {
font-size: #{16 / $base-font-size}rem; font-size: #{16 / $base-font-size}rem;
padding: #{8 / $base-font-size}rem #{20 / $base-font-size}rem; padding: #{8 / $base-font-size}rem 0;
color: $light-inactive-text-color; color: $light-inactive-text-color;
cursor: pointer; cursor: pointer;
&--selected { &--selected {
background-color: $ide-border-color; background-color: $ide-border-color;
} }
&:hover .sidebar__file-item-name { &:hover > .file-item__content .sidebar__file-item-name {
color: $light-primary-text-color; color: $light-primary-text-color;
} }
&:hover .sidebar__file-item-icon g { &:hover > .file-item__content .sidebar__file-item-icon g {
fill: $light-primary-text-color; fill: $light-primary-text-color;
} }
} }
// to indent each row in the file tree
// not sure how to do this in a better way
// it won't work if the file tree is too nested
.file-item__spacer {
.sidebar__file-item & {
width: #{20 / $base-font-size}rem;
.sidebar__file-item & {
width: #{40 / $base-font-size}rem;
.sidebar__file-item & {
width: #{60 / $base-font-size}rem;
.sidebar__file-item & {
width: #{80 / $base-font-size}rem;
.sidebar__file-item & {
width: #{100 / $base-font-size}rem;
}
}
}
}
}
}
.file-item__content { .file-item__content {
display: flex; display: flex;
// justify-content: space-between;
position: relative; position: relative;
} }
@ -66,9 +90,9 @@
.sidebar__file-item-show-options { .sidebar__file-item-show-options {
@extend %icon; @extend %icon;
display: none; display: none;
margin-left: auto; position: absolute;
margin-right: 0; right: #{20 / $base-font-size}rem;
.sidebar__file-item--selected & { .sidebar__file-item--selected > .file-item__content & {
display: inline-block; display: inline-block;
} }
} }
@ -84,7 +108,7 @@
padding: #{8 / $base-font-size}rem #{16 / $base-font-size}rem; padding: #{8 / $base-font-size}rem #{16 / $base-font-size}rem;
background-color: $light-modal-background-color; background-color: $light-modal-background-color;
z-index: 100; z-index: 100;
.sidebar__file-item--open & { .sidebar__file-item--open > .file-item__content & {
display: block; display: block;
} }
} }