diff --git a/client/modules/App/App.jsx b/client/modules/App/App.jsx
index 089d80f76d..3b74e1fca6 100644
--- a/client/modules/App/App.jsx
+++ b/client/modules/App/App.jsx
@@ -41,7 +41,7 @@ class App extends React.Component {
render() {
return (
- {false && this.state.isMounted && !window.devToolsExtension && getConfig('NODE_ENV') === 'development' && }
+ {this.state.isMounted && !window.devToolsExtension && getConfig('NODE_ENV') === 'development' && }
{this.props.children}
);
diff --git a/client/modules/IDE/actions/project.js b/client/modules/IDE/actions/project.js
index 05215579bb..eacb4194b7 100644
--- a/client/modules/IDE/actions/project.js
+++ b/client/modules/IDE/actions/project.js
@@ -258,64 +258,50 @@ function generateNewIdsForChildren(file, files) {
file.children = newChildren; // eslint-disable-line
}
-export function cloneProject(id) {
+export function cloneProject(project) {
return (dispatch, getState) => {
dispatch(setUnsavedChanges(false));
- new Promise((resolve, reject) => {
- if (!id) {
- resolve(getState());
- } else {
- apiClient.get(`/projects/${id}`)
- .then(res => res.json())
- .then(data => resolve({
- files: data.files,
- project: {
- name: data.name
- }
- }));
- }
- }).then((state) => {
- const newFiles = state.files.map((file) => { // eslint-disable-line
- return { ...file };
- });
+ const state = getState();
+ const files = project ? project.files : state.files;
+ const projectName = project ? project.name : state.project.name;
+ const newFiles = files.map(file => ({ ...file }));
- // generate new IDS for all files
- const rootFile = newFiles.find(file => file.name === 'root');
- const newRootFileId = objectID().toHexString();
- rootFile.id = newRootFileId;
- rootFile._id = newRootFileId;
- generateNewIdsForChildren(rootFile, newFiles);
+ // generate new IDS for all files
+ const rootFile = newFiles.find(file => file.name === 'root');
+ const newRootFileId = objectID().toHexString();
+ rootFile.id = newRootFileId;
+ rootFile._id = newRootFileId;
+ generateNewIdsForChildren(rootFile, newFiles);
- // duplicate all files hosted on S3
- each(newFiles, (file, callback) => {
- if (file.url && (file.url.includes(S3_BUCKET_URL_BASE) || file.url.includes(S3_BUCKET))) {
- const formParams = {
- url: file.url
- };
- apiClient.post('/S3/copy', formParams)
- .then((response) => {
- file.url = response.data.url;
- callback(null);
- });
- } else {
- callback(null);
- }
- }, (err) => {
- // if not errors in duplicating the files on S3, then duplicate it
- const formParams = Object.assign({}, { name: `${state.project.name} copy` }, { files: newFiles });
- apiClient.post('/projects', formParams)
+ // duplicate all files hosted on S3
+ each(newFiles, (file, callback) => {
+ if (file.url && (file.url.includes(S3_BUCKET_URL_BASE) || file.url.includes(S3_BUCKET))) {
+ const formParams = {
+ url: file.url
+ };
+ apiClient.post('/S3/copy', formParams)
.then((response) => {
- browserHistory.push(`/${response.data.user.username}/sketches/${response.data.id}`);
- dispatch(setNewProject(response.data));
- })
- .catch((error) => {
- const { response } = error;
- dispatch({
- type: ActionTypes.PROJECT_SAVE_FAIL,
- error: response.data
- });
+ file.url = response.data.url;
+ callback(null);
});
- });
+ } else {
+ callback(null);
+ }
+ }, (err) => {
+ // if not errors in duplicating the files on S3, then duplicate it
+ const formParams = Object.assign({}, { name: `${projectName} copy` }, { files: newFiles });
+ apiClient.post('/projects', formParams)
+ .then((response) => {
+ browserHistory.push(`/${response.data.user.username}/sketches/${response.data.id}`);
+ dispatch(setNewProject(response.data));
+ })
+ .catch((error) => {
+ const { response } = error;
+ dispatch({
+ type: ActionTypes.PROJECT_SAVE_FAIL,
+ error: response.data
+ });
+ });
});
};
}
diff --git a/client/modules/IDE/components/SketchList.jsx b/client/modules/IDE/components/SketchList.jsx
index 3db41ec963..6abdd79020 100644
--- a/client/modules/IDE/components/SketchList.jsx
+++ b/client/modules/IDE/components/SketchList.jsx
@@ -139,7 +139,7 @@ class SketchListRowBase extends React.Component {
handleSketchDuplicate = () => {
this.closeAll();
- this.props.cloneProject(this.props.sketch.id);
+ this.props.cloneProject(this.props.sketch);
}
handleSketchShare = () => {