1
0
mirror of https://github.com/haiwen/seahub.git synced 2025-09-08 02:10:24 +00:00

optimize code

This commit is contained in:
shanshuirenjia
2022-05-27 15:08:50 +08:00
parent c78dfd7c09
commit 507e318a5f

View File

@@ -39,6 +39,8 @@ class WikiMarkdownViewer extends React.Component {
this.links.forEach(link => {
link.addEventListener('click', this.onLinkClick);
});
this.getTitlesInfo();
}
componentWillReceiveProps(nextProps) {
@@ -57,6 +59,9 @@ class WikiMarkdownViewer extends React.Component {
this.links.forEach(link => {
link.addEventListener('click', this.onLinkClick);
});
if (this.titlesInfo.length === 0) {
this.getTitlesInfo();
}
}
componentWillUnmount() {
@@ -66,10 +71,6 @@ class WikiMarkdownViewer extends React.Component {
});
}
onContentRendered = (markdownViewer) => {
this.titlesInfo = markdownViewer.titlesInfo;
}
getTitlesInfo = () => {
let titlesInfo = [];
let headingList = document.querySelectorAll('h2[id^="user-content"], h3[id^="user-content"]');
@@ -98,10 +99,6 @@ class WikiMarkdownViewer extends React.Component {
onScrollHandler = () => {
const contentScrollTop = this.markdownContainer.current.scrollTop + 180;
let titlesLength = this.titlesInfo.length;
if (titlesLength === 0) {
this.getTitlesInfo();
titlesLength = this.titlesInfo.length;
}
let activeTitleIndex;
if (contentScrollTop <= this.titlesInfo[0]) {
activeTitleIndex = 0;
@@ -183,7 +180,6 @@ class WikiMarkdownViewer extends React.Component {
scriptSource={mediaUrl + 'js/mathjax/tex-svg.js'}
markdownContent={this.props.markdownContent}
activeTitleIndex={this.state.activeTitleIndex}
onContentRendered={this.onContentRendered}
modifyValueBeforeRender={this.modifyValueBeforeRender}
/>
);
@@ -195,7 +191,6 @@ class WikiMarkdownViewer extends React.Component {
scriptSource={mediaUrl + 'js/mathjax/tex-svg.js'}
markdownContent={this.props.markdownContent}
activeTitleIndex={this.state.activeTitleIndex}
onContentRendered={this.onContentRendered}
/>
);
}