From 509bb6bd8eb95793b2b8c9f09a625721d96e4483 Mon Sep 17 00:00:00 2001 From: Cassie Tarakajian Date: Tue, 31 Jan 2017 15:18:40 -0500 Subject: [PATCH] #285 fix project duplication error where project copies would alter the project original --- client/modules/IDE/actions/project.js | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) diff --git a/client/modules/IDE/actions/project.js b/client/modules/IDE/actions/project.js index 0ced170a..fcb77f35 100644 --- a/client/modules/IDE/actions/project.js +++ b/client/modules/IDE/actions/project.js @@ -1,6 +1,7 @@ import * as ActionTypes from '../../../constants'; import { browserHistory } from 'react-router'; import axios from 'axios'; +import objectID from 'bson-objectid'; import { showToast, setToastText } from './toast'; import { setUnsavedChanges, justOpenedProject, @@ -169,7 +170,13 @@ export function cloneProject() { return (dispatch, getState) => { dispatch(setUnsavedChanges(false)); const state = getState(); - const formParams = Object.assign({}, { name: `${state.project.name} copy` }, { files: state.files }); + const newFiles = state.files.map(file => { + const newFile = Object.assign({}, file); + newFile._id = objectID().toHexString(); + newFile.id = newFile._id; + return newFile; + }); + const formParams = Object.assign({}, { name: `${state.project.name} copy` }, { files: newFiles }); axios.post(`${ROOT_URL}/projects`, formParams, { withCredentials: true }) .then(response => { browserHistory.push(`/${response.data.user.username}/sketches/${response.data.id}`);