This commit is contained in:
Cassie Tarakajian 2017-02-17 14:53:48 -05:00
parent 89972bf2ae
commit f344e01003

View file

@ -1,7 +1,7 @@
import * as ActionTypes from '../../../constants'; import * as ActionTypes from '../../../constants';
import { browserHistory } from 'react-router'; import { browserHistory } from 'react-router';
import axios from 'axios'; import axios from 'axios';
// import objectID from 'bson-objectid'; import objectID from 'bson-objectid';
import { showToast, setToastText } from './toast'; import { showToast, setToastText } from './toast';
import { setUnsavedChanges, import { setUnsavedChanges,
justOpenedProject, justOpenedProject,
@ -166,17 +166,30 @@ export function newProject() {
return resetProject(); return resetProject();
} }
function generateNewIdsForChildren(file, files) {
const newChildren = [];
file.children.forEach((childId) => {
const child = files.find(childFile => childFile.id === childId);
const newId = objectID().toHexString();
child.id = newId;
child._id = newId;
newChildren.push(newId);
generateNewIdsForChildren(child, files);
});
file.children = newChildren; // eslint-disable-line
}
export function cloneProject() { export function cloneProject() {
return (dispatch, getState) => { return (dispatch, getState) => {
dispatch(setUnsavedChanges(false)); dispatch(setUnsavedChanges(false));
const state = getState(); const state = getState();
// const newFiles = state.files.map(file => { const newFiles = [...state.files];
// const newFile = Object.assign({}, file); const rootFile = newFiles.find(file => file.name === 'root');
// newFile._id = objectID().toHexString(); const newRootFileId = objectID().toHexString();
// newFile.id = newFile._id; rootFile.id = newRootFileId;
// return newFile; rootFile._id = newRootFileId;
// }); generateNewIdsForChildren(rootFile, newFiles);
const newFiles = state.files; // const newFiles = state.files;
const formParams = Object.assign({}, { name: `${state.project.name} copy` }, { files: newFiles }); const formParams = Object.assign({}, { name: `${state.project.name} copy` }, { files: newFiles });
axios.post(`${ROOT_URL}/projects`, formParams, { withCredentials: true }) axios.post(`${ROOT_URL}/projects`, formParams, { withCredentials: true })
.then(response => { .then(response => {