diff --git a/client/constants.js b/client/constants.js index 967df39b..6f5833fd 100644 --- a/client/constants.js +++ b/client/constants.js @@ -30,6 +30,9 @@ export const SET_PROJECT = 'SET_PROJECT'; export const SET_PROJECTS = 'SET_PROJECTS'; export const SET_SELECTED_FILE = 'SET_SELECTED_FILE'; +export const SHOW_MODAL = 'SHOW_MODAL'; +export const HIDE_MODAL = 'HIDE_MODAL'; +export const CREATE_FILE = 'CREATE_FILE'; // eventually, handle errors more specifically and better export const ERROR = 'ERROR'; diff --git a/client/modules/IDE/actions/files.js b/client/modules/IDE/actions/files.js index f7ebd8f3..8bc0c6c3 100644 --- a/client/modules/IDE/actions/files.js +++ b/client/modules/IDE/actions/files.js @@ -7,3 +7,11 @@ export function updateFileContent(name, content) { content }; } + +// TODO make req to server +export function createFile(name) { + return { + type: ActionTypes.CREATE_FILE, + name + }; +} diff --git a/client/modules/IDE/actions/ide.js b/client/modules/IDE/actions/ide.js index 0bcbc414..70363669 100644 --- a/client/modules/IDE/actions/ide.js +++ b/client/modules/IDE/actions/ide.js @@ -24,3 +24,15 @@ export function setSelectedFile(fileId) { selectedFile: fileId }; } + +export function newFile() { + return { + type: ActionTypes.SHOW_MODAL + }; +} + +export function closeNewFileModal() { + return { + type: ActionTypes.HIDE_MODAL + }; +} diff --git a/client/modules/IDE/components/NewFileForm.js b/client/modules/IDE/components/NewFileForm.js new file mode 100644 index 00000000..c46ca9e5 --- /dev/null +++ b/client/modules/IDE/components/NewFileForm.js @@ -0,0 +1,28 @@ +import React, { PropTypes } from 'react'; + +function NewFileForm(props) { + const { fields: { name }, handleSubmit } = props; + return ( +
+ + + +
+ ); +} + +NewFileForm.propTypes = { + fields: PropTypes.shape({ + name: PropTypes.string.isRequired + }).isRequired, + handleSubmit: PropTypes.func.isRequired, + createFile: PropTypes.func.isRequired +}; + +export default NewFileForm; diff --git a/client/modules/IDE/components/NewFileModal.js b/client/modules/IDE/components/NewFileModal.js new file mode 100644 index 00000000..1072348b --- /dev/null +++ b/client/modules/IDE/components/NewFileModal.js @@ -0,0 +1,68 @@ +import React, { PropTypes } from 'react'; +import { bindActionCreators } from 'redux'; +import { reduxForm } from 'redux-form'; +import NewFileForm from './NewFileForm'; +import * as FileActions from '../actions/files'; +import classNames from 'classnames'; +import InlineSVG from 'react-inlinesvg'; +const exitUrl = require('../../../images/exit.svg'); + +// At some point this will probably be generalized to a generic modal +// in which you can insert different content +// but for now, let's just make this work +function NewFileModal(props) { + const modalClass = classNames({ + modal: true, + 'modal--hidden': !props.isVisible + }); + + return ( +
+
+
+

Add File

+ +
+ +
+
+ ); +} + +NewFileModal.propTypes = { + isVisible: PropTypes.bool.isRequired, + closeModal: PropTypes.func.isRequired +}; + +function mapStateToProps(state) { + return { + file: state.files + }; +} + +function mapDispatchToProps(dispatch) { + return bindActionCreators(FileActions, dispatch); +} + +function validate(formProps) { + const errors = {}; + + if (!formProps.name) { + errors.name = 'Please enter a name'; + } + + // if (formProps.name.match(/(.+\.js$|.+\.css$)/)) { + // errors.name = 'File must be of type JavaScript or CSS.'; + // } + + return errors; +} + + +export default reduxForm({ + form: 'new-file', + fields: ['name'], + validate +}, mapStateToProps, mapDispatchToProps)(NewFileModal); diff --git a/client/modules/IDE/components/Sidebar.js b/client/modules/IDE/components/Sidebar.js index cb8c276f..ffeea432 100644 --- a/client/modules/IDE/components/Sidebar.js +++ b/client/modules/IDE/components/Sidebar.js @@ -4,6 +4,15 @@ import classNames from 'classnames'; function Sidebar(props) { return (
+
+

Sketch Files

+ + + + +