1
0
mirror of https://github.com/haiwen/seahub.git synced 2025-09-06 17:33:18 +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) => { loadSidePanel = (initialPath) => {
if (initialPath === this.homePath || isDir === 'None') {
seafileAPI.listWikiDir(slug, '/').then(res => { if (initialPath === this.homePath) {
let tree = this.state.treeData; if (hasIndex) {
this.addFirstResponseListToNode(res.data.dirent_list, tree.root); this.loadIndexNode();
let indexNode = tree.getNodeByPath(this.indexPath); } else {
let homeNode = tree.getNodeByPath(this.homePath); initialPath = '/';
if (homeNode && indexNode) { this.loadNodeAndParentsByPath(initialPath);
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 (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) => { showDir = (dirPath) => {