add cloning of projects

This commit is contained in:
catarak 2016-07-15 13:36:33 -04:00
parent 78ed7b4b5f
commit 8d8e399aac
4 changed files with 30 additions and 5 deletions

View file

@ -33,7 +33,7 @@ function Nav(props) {
Export (zip) Export (zip)
</a> </a>
</li> </li>
<li className="nav__item"> <li className="nav__item" onClick={props.cloneProject}>
<a className="nav__clone"> <a className="nav__clone">
Clone Clone
</a> </a>
@ -53,6 +53,7 @@ Nav.propTypes = {
createProject: PropTypes.func.isRequired, createProject: PropTypes.func.isRequired,
saveProject: PropTypes.func.isRequired, saveProject: PropTypes.func.isRequired,
exportProjectAsZip: PropTypes.func.isRequired, exportProjectAsZip: PropTypes.func.isRequired,
cloneProject: PropTypes.func.isRequired,
user: PropTypes.shape({ user: PropTypes.shape({
authenticated: PropTypes.bool.isRequired, authenticated: PropTypes.bool.isRequired,
username: PropTypes.string username: PropTypes.string

View file

@ -83,7 +83,6 @@ export function createProject() {
return (dispatch) => { return (dispatch) => {
axios.post(`${ROOT_URL}/projects`, {}, { withCredentials: true }) axios.post(`${ROOT_URL}/projects`, {}, { withCredentials: true })
.then(response => { .then(response => {
console.log(response.data);
browserHistory.push(`/projects/${response.data.id}`); browserHistory.push(`/projects/${response.data.id}`);
dispatch({ dispatch({
type: ActionTypes.NEW_PROJECT, type: ActionTypes.NEW_PROJECT,
@ -116,3 +115,26 @@ export function exportProjectAsZip() {
}; };
} }
export function cloneProject() {
return (dispatch, getState) => {
const state = getState();
const formParams = Object.assign({}, { name: state.project.name }, { files: state.files });
axios.post(`${ROOT_URL}/projects`, formParams, { withCredentials: true })
.then(response => {
browserHistory.push(`/projects/${response.data.id}`);
dispatch({
type: ActionTypes.NEW_PROJECT,
name: response.data.name,
id: response.data.id,
owner: response.data.user,
selectedFile: response.data.selectedFile,
files: response.data.files
});
})
.catch(response => dispatch({
type: ActionTypes.PROJECT_SAVE_FAIL,
error: response.data
}));
};
}

View file

@ -30,6 +30,7 @@ class IDEView extends React.Component {
createProject={this.props.createProject} createProject={this.props.createProject}
saveProject={this.props.saveProject} saveProject={this.props.saveProject}
exportProjectAsZip={this.props.exportProjectAsZip} exportProjectAsZip={this.props.exportProjectAsZip}
cloneProject={this.props.cloneProject}
/> />
<Toolbar <Toolbar
className="Toolbar" className="Toolbar"
@ -146,7 +147,8 @@ IDEView.propTypes = {
closeNewFileModal: PropTypes.func.isRequired, closeNewFileModal: PropTypes.func.isRequired,
expandSidebar: PropTypes.func.isRequired, expandSidebar: PropTypes.func.isRequired,
collapseSidebar: PropTypes.func.isRequired, collapseSidebar: PropTypes.func.isRequired,
exportProjectAsZip: PropTypes.func.isRequired exportProjectAsZip: PropTypes.func.isRequired,
cloneProject: PropTypes.func.isRequired
}; };
function mapStateToProps(state) { function mapStateToProps(state) {

View file

@ -1,11 +1,11 @@
import Project from '../models/project'; import Project from '../models/project';
export function createProject(req, res) { export function createProject(req, res) {
const projectValues = { let projectValues = {
user: req.user ? req.user._id : undefined // eslint-disable-line no-underscore-dangle user: req.user ? req.user._id : undefined // eslint-disable-line no-underscore-dangle
}; };
Object.assign(projectValues, req.body); projectValues = Object.assign(projectValues, req.body);
Project.create(projectValues, (err, newProject) => { Project.create(projectValues, (err, newProject) => {
if (err) { return res.json({ success: false }); } if (err) { return res.json({ success: false }); }