1
0
mirror of https://github.com/haiwen/seahub.git synced 2025-09-05 17:02:47 +00:00

optimization code

This commit is contained in:
zxj96
2019-06-12 17:50:55 +08:00
parent 8e5a01feea
commit 5f7c16b868

View File

@@ -538,20 +538,25 @@ class LibContentView extends React.Component {
getThumbnail(0); getThumbnail(0);
} }
getListDir = (temporaryData, path) => {
let repoID = this.props.repoID;
seafileAPI.listDir(repoID, path).then(res => {
let name = res.data.dirent_list;
let names = this.getTreeNodeNames(temporaryData, name);
names.map(item => {
this.addNodeToTree(item.name, path, item.type);
})
});
}
// toolbar operations // toolbar operations
onMoveItems = (destRepo, destDirentPath) => { onMoveItems = (destRepo, destDirentPath) => {
let repoID = this.props.repoID; let repoID = this.props.repoID;
let direntPaths = this.getSelectedDirentPaths(); let direntPaths = this.getSelectedDirentPaths();
let dirNames = this.getSelectedDirentNames(); let dirNames = this.getSelectedDirentNames();
let temporaryData = [];
if (repoID === destRepo.repo_id) {
seafileAPI.listDir(repoID, destDirentPath).then(res => {
temporaryData = res.data.dirent_list;
});
}
seafileAPI.moveDir(repoID, destRepo.repo_id, destDirentPath, this.state.path, dirNames).then(res => { seafileAPI.moveDir(repoID, destRepo.repo_id, destDirentPath, this.state.path, dirNames).then(res => {
direntPaths.forEach((direntPath, index) => { direntPaths.forEach((direntPath, index) => {
if (this.state.currentMode === 'column') { if (this.state.currentMode === 'column') {
@@ -564,13 +569,8 @@ class LibContentView extends React.Component {
if (this.state.currentMode === 'column') { if (this.state.currentMode === 'column') {
let tree = this.state.treeData.clone(); let tree = this.state.treeData.clone();
let node = tree.getNodeByPath(destDirentPath); let node = tree.getNodeByPath(destDirentPath);
seafileAPI.listDir(repoID, node.path).then(res => { let temporaryData = node.children.map(item => item.object);
let name = res.data.dirent_list; this.getListDir(temporaryData, node.path);
let names = this.getTreeNodeNames(temporaryData, name);
names.map(item => {
this.addNodeToTree(item.name, destDirentPath, item.type);
})
});
} }
} }
let message = Utils.getMoveSuccessMessage(dirNames); let message = Utils.getMoveSuccessMessage(dirNames);
@@ -586,24 +586,13 @@ class LibContentView extends React.Component {
let direntPaths = this.getSelectedDirentPaths(); let direntPaths = this.getSelectedDirentPaths();
let dirNames = this.getSelectedDirentNames(); let dirNames = this.getSelectedDirentNames();
let temporaryData = [];
if (repoID === destRepo.repo_id) {
seafileAPI.listDir(repoID, destDirentPath).then(res => {
temporaryData = res.data.dirent_list;
});
}
seafileAPI.copyDir(repoID, destRepo.repo_id, destDirentPath, this.state.path, dirNames).then(res => { seafileAPI.copyDir(repoID, destRepo.repo_id, destDirentPath, this.state.path, dirNames).then(res => {
if (repoID === destRepo.repo_id) { if (repoID === destRepo.repo_id) {
if (this.state.currentMode === 'column') { if (this.state.currentMode === 'column') {
let tree = this.state.treeData.clone(); let tree = this.state.treeData.clone();
let node = tree.getNodeByPath(destDirentPath); let node = tree.getNodeByPath(destDirentPath);
seafileAPI.listDir(repoID, node.path).then(res => { let temporaryData = node.children.map(item => item.object);
let name = res.data.dirent_list; this.getListDir(temporaryData, node.path);
let names = this.getTreeNodeNames(temporaryData, name);
names.map(item => {
this.addNodeToTree(item.name, destDirentPath, item.type);
})
});
} }
} }
@@ -896,23 +885,14 @@ class LibContentView extends React.Component {
nodeParentPath = this.state.path; nodeParentPath = this.state.path;
} }
let direntPath = Utils.joinPath(nodeParentPath, dirName); let direntPath = Utils.joinPath(nodeParentPath, dirName);
let temporaryData = [];
if (repoID === destRepo.repo_id) {
seafileAPI.listDir(repoID, moveToDirentPath).then(res => {
temporaryData = res.data.dirent_list;
});
}
seafileAPI.moveDir(repoID, destRepo.repo_id, moveToDirentPath, nodeParentPath, dirName).then(res => { seafileAPI.moveDir(repoID, destRepo.repo_id, moveToDirentPath, nodeParentPath, dirName).then(res => {
if (this.state.currentMode === 'column') { if (this.state.currentMode === 'column') {
this.deleteTreeNode(direntPath); this.deleteTreeNode(direntPath);
if (repoID === destRepo.repo_id) { if (repoID === destRepo.repo_id) {
let tree = this.state.treeData.clone(); let tree = this.state.treeData.clone();
let node = tree.getNodeByPath(moveToDirentPath); let node = tree.getNodeByPath(moveToDirentPath);
seafileAPI.listDir(repoID, node.path).then(res => { let temporaryData = node.children.map(item => item.object);
let name = res.data.dirent_list; this.getListDir(temporaryData, node.path);
let names = this.getTreeNodeNames(temporaryData, name);
this.addNodeToTree(names[0].name, moveToDirentPath, dirent.type);
});
} }
} }
this.moveDirent(direntPath, moveToDirentPath); this.moveDirent(direntPath, moveToDirentPath);
@@ -936,22 +916,13 @@ class LibContentView extends React.Component {
} }
let direntPath = Utils.joinPath(nodeParentPath, dirName); let direntPath = Utils.joinPath(nodeParentPath, dirName);
let temporaryData = [];
seafileAPI.listDir(repoID, copyToDirentPath).then(res => {
temporaryData = res.data.dirent_list;
});
seafileAPI.copyDir(repoID, destRepo.repo_id, copyToDirentPath, nodeParentPath, dirName).then(res => { seafileAPI.copyDir(repoID, destRepo.repo_id, copyToDirentPath, nodeParentPath, dirName).then(res => {
if (this.state.currentMode === 'column') { if (this.state.currentMode === 'column') {
if (repoID === destRepo.repo_id) { if (repoID === destRepo.repo_id) {
let tree = this.state.treeData.clone(); let tree = this.state.treeData.clone();
let node = tree.getNodeByPath(copyToDirentPath); let node = tree.getNodeByPath(copyToDirentPath);
seafileAPI.listDir(repoID, node.path).then(res => { let temporaryData = node.children.map(item => item.object);
let name = res.data.dirent_list; this.getListDir(temporaryData, node.path);
let names = this.getTreeNodeNames(temporaryData, name);
this.addNodeToTree(names[0].name, copyToDirentPath, dirent.type);
});
} }
} }