1
0
mirror of https://github.com/haiwen/seahub.git synced 2025-09-03 07:55:36 +00:00

optimized wiki page refresh code

This commit is contained in:
shanshuirenjia
2019-05-29 15:30:21 +08:00
parent eed0a5bf73
commit b83a4fd583

View File

@@ -77,33 +77,50 @@ class Wiki extends Component {
}
loadSidePanel = (initialPath) => {
if (initialPath === this.homePath || isDir === 'None') {
seafileAPI.listWikiDir(slug, '/').then(res => {
let tree = this.state.treeData;
this.addFirstResponseListToNode(res.data.dirent_list, tree.root);
let indexNode = tree.getNodeByPath(this.indexPath);
let homeNode = tree.getNodeByPath(this.homePath);
if (homeNode && indexNode) {
seafileAPI.getWikiFileContent(slug, indexNode.path).then(res => {
this.setState({
treeData: tree,
indexNode: indexNode,
indexContent: res.data.content,
isTreeDataLoading: false,
});
});
} else {
this.setState({
treeData: tree,
isTreeDataLoading: false,
});
}
}).catch(() => {
this.setState({isLoadFailed: true});
});
} else {
this.loadNodeAndParentsByPath(initialPath);
if (initialPath === this.homePath) {
if (hasIndex) {
this.loadIndexNode();
} else {
initialPath = '/';
this.loadNodeAndParentsByPath(initialPath);
}
}
if (initialPath !== this.homePath) {
if (isDir === 'None') {
if (hasIndex) {
this.loadIndexNode();
} else {
initialPath = '/';
this.loadNodeAndParentsByPath(initialPath);
}
} else {
if (hasIndex) {
this.loadIndexNode();
} else {
this.loadNodeAndParentsByPath(initialPath);
}
}
}
}
loadIndexNode = () => {
seafileAPI.listWikiDir(slug, '/').then(res => {
let tree = this.state.treeData;
this.addFirstResponseListToNode(res.data.dirent_list, tree.root);
let indexNode = tree.getNodeByPath(this.indexPath);
seafileAPI.getWikiFileContent(slug, indexNode.path).then(res => {
this.setState({
treeData: tree,
indexNode: indexNode,
indexContent: res.data.content,
isTreeDataLoading: false,
});
});
}).catch(() => {
this.setState({isLoadFailed: true});
});
}
showDir = (dirPath) => {