fix #289
This commit is contained in:
parent
89972bf2ae
commit
f344e01003
1 changed files with 21 additions and 8 deletions
|
@ -1,7 +1,7 @@
|
|||
import * as ActionTypes from '../../../constants';
|
||||
import { browserHistory } from 'react-router';
|
||||
import axios from 'axios';
|
||||
// import objectID from 'bson-objectid';
|
||||
import objectID from 'bson-objectid';
|
||||
import { showToast, setToastText } from './toast';
|
||||
import { setUnsavedChanges,
|
||||
justOpenedProject,
|
||||
|
@ -166,17 +166,30 @@ export function newProject() {
|
|||
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() {
|
||||
return (dispatch, getState) => {
|
||||
dispatch(setUnsavedChanges(false));
|
||||
const state = getState();
|
||||
// const newFiles = state.files.map(file => {
|
||||
// const newFile = Object.assign({}, file);
|
||||
// newFile._id = objectID().toHexString();
|
||||
// newFile.id = newFile._id;
|
||||
// return newFile;
|
||||
// });
|
||||
const newFiles = state.files;
|
||||
const newFiles = [...state.files];
|
||||
const rootFile = newFiles.find(file => file.name === 'root');
|
||||
const newRootFileId = objectID().toHexString();
|
||||
rootFile.id = newRootFileId;
|
||||
rootFile._id = newRootFileId;
|
||||
generateNewIdsForChildren(rootFile, newFiles);
|
||||
// const newFiles = state.files;
|
||||
const formParams = Object.assign({}, { name: `${state.project.name} copy` }, { files: newFiles });
|
||||
axios.post(`${ROOT_URL}/projects`, formParams, { withCredentials: true })
|
||||
.then(response => {
|
||||
|
|
Loading…
Reference in a new issue