mirror of
https://github.com/haiwen/seahub.git
synced 2025-09-04 00:20:07 +00:00
Optimize wiki module (#5213)
* optimize code * optimize code * python load wiki file_content * optimize style * improve code * optimize code * update code * optimize wiki style * format <h> label * add scroll interactive * optimize code * repair code bug * format datetime Co-authored-by: 王健辉 <40563566+mrwangjianhui@users.noreply.github.com>
This commit is contained in:
@@ -27,7 +27,7 @@ class Wiki extends Component {
|
||||
pathExist: true,
|
||||
closeSideBar: false,
|
||||
isViewFile: true,
|
||||
isDataLoading: true,
|
||||
isDataLoading: false,
|
||||
direntList: [],
|
||||
content: '',
|
||||
permission: '',
|
||||
@@ -43,6 +43,7 @@ class Wiki extends Component {
|
||||
window.onpopstate = this.onpopstate;
|
||||
this.indexPath = '/index.md';
|
||||
this.homePath = '/home.md';
|
||||
this.pythonWrapper = null;
|
||||
}
|
||||
|
||||
componentWillMount() {
|
||||
@@ -52,39 +53,54 @@ class Wiki extends Component {
|
||||
}
|
||||
|
||||
componentDidMount() {
|
||||
this.loadSidePanel(initialPath);
|
||||
this.loadWikiData(initialPath);
|
||||
|
||||
this.links = document.querySelectorAll(`#wiki-file-content a`);
|
||||
this.links.forEach(link => link.addEventListener('click', this.onConentLinkClick));
|
||||
}
|
||||
|
||||
loadWikiData = (initialPath) => {
|
||||
this.loadSidePanel(initialPath);
|
||||
|
||||
if (isDir === 'None') {
|
||||
if (initialPath === '/home.md') {
|
||||
this.showDir('/');
|
||||
} else {
|
||||
this.setState({pathExist: false});
|
||||
let fileUrl = siteRoot + 'published/' + slug + Utils.encodePath(initialPath);
|
||||
window.history.pushState({url: fileUrl, path: initialPath}, initialPath, fileUrl);
|
||||
}
|
||||
} else if (isDir === 'True') {
|
||||
this.showDir(initialPath);
|
||||
} else if (isDir === 'False') {
|
||||
this.showFile(initialPath);
|
||||
}
|
||||
componentWillUnmount() {
|
||||
this.links.forEach(link => link.removeEventListener('click', this.onConentLinkClick));
|
||||
}
|
||||
|
||||
loadSidePanel = (initialPath) => {
|
||||
if (hasIndex) {
|
||||
this.loadIndexNode();
|
||||
} else {
|
||||
if (isDir === 'None') {
|
||||
initialPath = '/';
|
||||
this.loadNodeAndParentsByPath('/');
|
||||
} else {
|
||||
this.loadNodeAndParentsByPath(initialPath);
|
||||
}
|
||||
return;
|
||||
}
|
||||
|
||||
// load dir list
|
||||
initialPath = isDir === 'None' ? '/' : initialPath;
|
||||
this.loadNodeAndParentsByPath(initialPath);
|
||||
}
|
||||
|
||||
loadWikiData = (initialPath) => {
|
||||
this.pythonWrapper = document.getElementById('wiki-file-content');
|
||||
if (isDir === 'False') {
|
||||
// this.showFile(initialPath);
|
||||
this.setState({path: initialPath});
|
||||
return;
|
||||
}
|
||||
|
||||
// if it is a file list, remove the template content provided by python
|
||||
this.removePythonWrapper();
|
||||
|
||||
if (isDir === 'True') {
|
||||
this.showDir(initialPath);
|
||||
return;
|
||||
}
|
||||
|
||||
if (isDir === 'None' && initialPath === '/home.md') {
|
||||
this.showDir('/');
|
||||
return;
|
||||
}
|
||||
|
||||
if (isDir === 'None') {
|
||||
this.setState({pathExist: false});
|
||||
let fileUrl = siteRoot + 'published/' + slug + Utils.encodePath(initialPath);
|
||||
window.history.pushState({url: fileUrl, path: initialPath}, initialPath, fileUrl);
|
||||
}
|
||||
}
|
||||
|
||||
loadIndexNode = () => {
|
||||
@@ -119,7 +135,8 @@ class Wiki extends Component {
|
||||
isViewFile: true,
|
||||
path: filePath,
|
||||
});
|
||||
|
||||
|
||||
this.removePythonWrapper();
|
||||
seafileAPI.getWikiFileContent(slug, filePath).then(res => {
|
||||
let data = res.data;
|
||||
this.setState({
|
||||
@@ -221,6 +238,29 @@ class Wiki extends Component {
|
||||
});
|
||||
}
|
||||
|
||||
removePythonWrapper = () => {
|
||||
if (this.pythonWrapper) {
|
||||
document.body.removeChild(this.pythonWrapper);
|
||||
this.pythonWrapper = null;
|
||||
}
|
||||
}
|
||||
|
||||
onConentLinkClick = (event) => {
|
||||
event.preventDefault();
|
||||
event.stopPropagation();
|
||||
let link = '';
|
||||
if (event.target.tagName !== 'A') {
|
||||
let target = event.target.parentNode;
|
||||
while (target.tagName !== 'A') {
|
||||
target = target.parentNode;
|
||||
}
|
||||
link = target.href;
|
||||
} else {
|
||||
link = event.target.href;
|
||||
}
|
||||
this.onLinkClick(link);
|
||||
}
|
||||
|
||||
onLinkClick = (link) => {
|
||||
const url = link;
|
||||
if (Utils.isWikiInternalMarkdownLink(url, slug)) {
|
||||
|
Reference in New Issue
Block a user