file tree renders, select file works and editor changes content, rename works
This commit is contained in:
parent
40b70d6c69
commit
cbb272ec14
7 changed files with 88 additions and 67 deletions
|
@ -130,7 +130,6 @@ export function hideFileOptions(fileId) {
|
||||||
}
|
}
|
||||||
|
|
||||||
export function showEditFileName(id) {
|
export function showEditFileName(id) {
|
||||||
console.log('in show edit file name');
|
|
||||||
return {
|
return {
|
||||||
type: ActionTypes.SHOW_EDIT_FILE_NAME,
|
type: ActionTypes.SHOW_EDIT_FILE_NAME,
|
||||||
id
|
id
|
||||||
|
|
|
@ -37,6 +37,13 @@ export function setSelectedFile(fileId) {
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
|
export function resetSelectedFile() {
|
||||||
|
return (dispatch, getState) => {
|
||||||
|
const state = getState();
|
||||||
|
setSelectedFile(state.files[1].id);
|
||||||
|
};
|
||||||
|
}
|
||||||
|
|
||||||
export function dispatchConsoleEvent(...args) {
|
export function dispatchConsoleEvent(...args) {
|
||||||
return {
|
return {
|
||||||
type: ActionTypes.CONSOLE_EVENT,
|
type: ActionTypes.CONSOLE_EVENT,
|
||||||
|
|
|
@ -121,7 +121,6 @@ export function exportProjectAsZip() {
|
||||||
const state = getState();
|
const state = getState();
|
||||||
const zip = new JSZip();
|
const zip = new JSZip();
|
||||||
async.each(state.files, (file, cb) => {
|
async.each(state.files, (file, cb) => {
|
||||||
console.log(file);
|
|
||||||
if (file.url) {
|
if (file.url) {
|
||||||
JSZipUtils.getBinaryContent(file.url, (err, data) => {
|
JSZipUtils.getBinaryContent(file.url, (err, data) => {
|
||||||
zip.file(file.name, data, { binary: true });
|
zip.file(file.name, data, { binary: true });
|
||||||
|
|
|
@ -1,10 +1,12 @@
|
||||||
import React, { PropTypes } from 'react';
|
import React, { PropTypes } from 'react';
|
||||||
import * as FileActions from '../actions/files';
|
import * as FileActions from '../actions/files';
|
||||||
|
import * as IDEActions from '../actions/ide';
|
||||||
import { bindActionCreators } from 'redux';
|
import { bindActionCreators } from 'redux';
|
||||||
import { connect } from 'react-redux';
|
import { connect } from 'react-redux';
|
||||||
import InlineSVG from 'react-inlinesvg';
|
import InlineSVG from 'react-inlinesvg';
|
||||||
const downArrowUrl = require('../../../images/down-arrow.svg');
|
const downArrowUrl = require('../../../images/down-arrow.svg');
|
||||||
import classNames from 'classnames';
|
import classNames from 'classnames';
|
||||||
|
import { setSelectedFile } from '../reducers/files';
|
||||||
|
|
||||||
export class FileNode extends React.Component {
|
export class FileNode extends React.Component {
|
||||||
constructor(props) {
|
constructor(props) {
|
||||||
|
@ -13,6 +15,12 @@ export class FileNode extends React.Component {
|
||||||
this.handleKeyPress = this.handleKeyPress.bind(this);
|
this.handleKeyPress = this.handleKeyPress.bind(this);
|
||||||
this.handleFileNameChange = this.handleFileNameChange.bind(this);
|
this.handleFileNameChange = this.handleFileNameChange.bind(this);
|
||||||
this.validateFileName = this.validateFileName.bind(this);
|
this.validateFileName = this.validateFileName.bind(this);
|
||||||
|
this.handleFileClick = this.handleFileClick.bind(this);
|
||||||
|
}
|
||||||
|
|
||||||
|
handleFileClick(e) {
|
||||||
|
e.stopPropagation();
|
||||||
|
this.props.setSelectedFile(this.props.id);
|
||||||
}
|
}
|
||||||
|
|
||||||
handleFileNameChange(event) {
|
handleFileNameChange(event) {
|
||||||
|
@ -46,13 +54,21 @@ export class FileNode extends React.Component {
|
||||||
|
|
||||||
render() {
|
render() {
|
||||||
let itemClass = classNames({
|
let itemClass = classNames({
|
||||||
'sidebar__file-item': true,
|
'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,
|
||||||
'sidebar__file-item--editing': this.props.isEditingName
|
'sidebar__file-item--editing': this.props.isEditingName
|
||||||
});
|
});
|
||||||
return (
|
return (
|
||||||
<div className={itemClass}>
|
<div
|
||||||
|
className={itemClass}
|
||||||
|
onClick={this.handleFileClick}
|
||||||
|
onBlur={() => setTimeout(() => this.props.hideFileOptions(this.props.id), 100)}
|
||||||
|
>
|
||||||
|
{(() => { // eslint-disable-line
|
||||||
|
if (this.props.name !== 'root') {
|
||||||
|
return (
|
||||||
|
<div className="file-item__content">
|
||||||
<a className="sidebar__file-item-name">{this.props.name}</a>
|
<a className="sidebar__file-item-name">{this.props.name}</a>
|
||||||
<input
|
<input
|
||||||
type="text"
|
type="text"
|
||||||
|
@ -78,7 +94,6 @@ export class FileNode extends React.Component {
|
||||||
<li>
|
<li>
|
||||||
<a
|
<a
|
||||||
onClick={() => {
|
onClick={() => {
|
||||||
console.log('before show edit file name');
|
|
||||||
this.originalFileName = this.props.name;
|
this.originalFileName = this.props.name;
|
||||||
this.props.showEditFileName(this.props.id);
|
this.props.showEditFileName(this.props.id);
|
||||||
setTimeout(() => this.refs.fileNameInput.focus(), 0);
|
setTimeout(() => this.refs.fileNameInput.focus(), 0);
|
||||||
|
@ -101,8 +116,11 @@ export class FileNode extends React.Component {
|
||||||
</li>
|
</li>
|
||||||
</ul>
|
</ul>
|
||||||
</div>
|
</div>
|
||||||
|
</div>
|
||||||
|
);
|
||||||
|
}
|
||||||
|
})()}
|
||||||
{(() => { // eslint-disable-line
|
{(() => { // eslint-disable-line
|
||||||
console.log(this.props.children);
|
|
||||||
if (this.props.children) {
|
if (this.props.children) {
|
||||||
return (
|
return (
|
||||||
<ul>
|
<ul>
|
||||||
|
@ -124,22 +142,21 @@ FileNode.propTypes = {
|
||||||
isOptionsOpen: PropTypes.bool,
|
isOptionsOpen: PropTypes.bool,
|
||||||
isEditingName: PropTypes.bool,
|
isEditingName: PropTypes.bool,
|
||||||
setSelectedFile: PropTypes.func.isRequired,
|
setSelectedFile: PropTypes.func.isRequired,
|
||||||
fileIndex: PropTypes.number.isRequired,
|
|
||||||
showFileOptions: PropTypes.func.isRequired,
|
showFileOptions: PropTypes.func.isRequired,
|
||||||
hideFileOptions: PropTypes.func.isRequired,
|
hideFileOptions: PropTypes.func.isRequired,
|
||||||
deleteFile: PropTypes.func.isRequired,
|
deleteFile: PropTypes.func.isRequired,
|
||||||
resetSelectedFile: PropTypes.func.isRequired,
|
|
||||||
showEditFileName: PropTypes.func.isRequired,
|
showEditFileName: PropTypes.func.isRequired,
|
||||||
hideEditFileName: PropTypes.func.isRequired,
|
hideEditFileName: PropTypes.func.isRequired,
|
||||||
updateFileName: PropTypes.func.isRequired
|
updateFileName: PropTypes.func.isRequired,
|
||||||
|
resetSelectedFile: PropTypes.func.isRequired
|
||||||
};
|
};
|
||||||
|
|
||||||
function mapStateToProps(state, ownProps) {
|
function mapStateToProps(state, ownProps) {
|
||||||
return state.files.find((file) => file.id === ownProps.id);
|
return setSelectedFile(state.files, state.ide.selectedFile).find((file) => file.id === ownProps.id);
|
||||||
}
|
}
|
||||||
|
|
||||||
function mapDispatchToProps(dispatch) {
|
function mapDispatchToProps(dispatch) {
|
||||||
return bindActionCreators(FileActions, dispatch);
|
return bindActionCreators(Object.assign(FileActions, IDEActions), dispatch);
|
||||||
}
|
}
|
||||||
|
|
||||||
const ConnectedFileNode = connect(mapStateToProps, mapDispatchToProps)(FileNode);
|
const ConnectedFileNode = connect(mapStateToProps, mapDispatchToProps)(FileNode);
|
||||||
|
|
|
@ -13,7 +13,7 @@ class Sidebar extends React.Component {
|
||||||
}
|
}
|
||||||
|
|
||||||
resetSelectedFile() {
|
resetSelectedFile() {
|
||||||
this.props.setSelectedFile(this.props.files[0].id);
|
this.props.setSelectedFile(this.props.files[1].id);
|
||||||
}
|
}
|
||||||
|
|
||||||
render() {
|
render() {
|
||||||
|
@ -50,7 +50,7 @@ class Sidebar extends React.Component {
|
||||||
</button>
|
</button>
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
<ul className="sidebar__file-list" title="project files">
|
{ /* <ul className="sidebar__file-list" title="project files">
|
||||||
{this.props.files.map((file, fileIndex) =>
|
{this.props.files.map((file, fileIndex) =>
|
||||||
<SidebarItem
|
<SidebarItem
|
||||||
key={file.id}
|
key={file.id}
|
||||||
|
@ -66,7 +66,7 @@ class Sidebar extends React.Component {
|
||||||
updateFileName={this.props.updateFileName}
|
updateFileName={this.props.updateFileName}
|
||||||
/>
|
/>
|
||||||
)}
|
)}
|
||||||
</ul>
|
</ul> */ }
|
||||||
<ConnectedFileNode id={'0'} />
|
<ConnectedFileNode id={'0'} />
|
||||||
</nav>
|
</nav>
|
||||||
);
|
);
|
||||||
|
|
|
@ -24,7 +24,6 @@ import About from '../components/About';
|
||||||
|
|
||||||
class IDEView extends React.Component {
|
class IDEView extends React.Component {
|
||||||
constructor(props) {
|
constructor(props) {
|
||||||
console.log(props);
|
|
||||||
super(props);
|
super(props);
|
||||||
this._handleConsolePaneOnDragFinished = this._handleConsolePaneOnDragFinished.bind(this);
|
this._handleConsolePaneOnDragFinished = this._handleConsolePaneOnDragFinished.bind(this);
|
||||||
this._handleSidebarPaneOnDragFinished = this._handleSidebarPaneOnDragFinished.bind(this);
|
this._handleSidebarPaneOnDragFinished = this._handleSidebarPaneOnDragFinished.bind(this);
|
||||||
|
|
|
@ -33,6 +33,11 @@ const defaultCSS =
|
||||||
|
|
||||||
// if the project has never been saved,
|
// if the project has never been saved,
|
||||||
const initialState = [
|
const initialState = [
|
||||||
|
{
|
||||||
|
name: 'root',
|
||||||
|
id: '0',
|
||||||
|
children: ['1', '2', '3']
|
||||||
|
},
|
||||||
{
|
{
|
||||||
name: 'sketch.js',
|
name: 'sketch.js',
|
||||||
content: defaultSketch,
|
content: defaultSketch,
|
||||||
|
@ -47,11 +52,6 @@ const initialState = [
|
||||||
name: 'style.css',
|
name: 'style.css',
|
||||||
content: defaultCSS,
|
content: defaultCSS,
|
||||||
id: '3'
|
id: '3'
|
||||||
},
|
|
||||||
{
|
|
||||||
name: 'root',
|
|
||||||
id: '0',
|
|
||||||
children: ['1', '2', '3']
|
|
||||||
}];
|
}];
|
||||||
|
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue