From 0815a90a907979a63d8987cc38dd87d0b4c09a0c Mon Sep 17 00:00:00 2001 From: C_Q Date: Tue, 28 Aug 2018 17:59:24 +0800 Subject: [PATCH] Chapter jump (#2307) --- frontend/src/components/markdown-viewer.js | 30 ++++++++++++---------- frontend/src/wiki.js | 5 ++-- 2 files changed, 20 insertions(+), 15 deletions(-) diff --git a/frontend/src/components/markdown-viewer.js b/frontend/src/components/markdown-viewer.js index 2fc4075ebf..0e64dbb4e4 100644 --- a/frontend/src/components/markdown-viewer.js +++ b/frontend/src/components/markdown-viewer.js @@ -44,19 +44,15 @@ class MarkdownViewerContent extends React.Component { class MarkdownViewer extends React.Component { - state = { - renderingContent: true, - renderingOutline: true, - html: '', - outlineTreeRoot: null, - navItems: [], - activeId: 0 - } - - scrollToNode(node) { - let url = new URL(window.location.href); - url.set('hash', 'user-content-' + node.data.id); - window.location.href = url.toString(); + constructor(props) { + super(props); + this.state = { + renderingContent: true, + html: '', + navItems: [], + activeId: 0, + }; + this.activeIdFromOutLine = null; } scrollHandler = (event) => { @@ -93,6 +89,14 @@ class MarkdownViewer extends React.Component { html: String(file), renderingContent: false }); + + setTimeout(() => { + // reset the href to jump to the section + var url = new URL(window.location.href); + if (url.hash) { + window.location.href = window.location.href; + } + }, 100); }) } diff --git a/frontend/src/wiki.js b/frontend/src/wiki.js index a738b9159f..d366a8077e 100644 --- a/frontend/src/wiki.js +++ b/frontend/src/wiki.js @@ -142,8 +142,9 @@ class Wiki extends Component { }) }) - let fileUrl = serviceUrl + '/wikis/' + slug + filePath; - window.history.pushState({urlPath: fileUrl, filePath: filePath}, filePath, fileUrl); + const hash = window.location.hash; + let fileUrl = serviceUrl + '/wikis/' + slug + filePath + hash; + window.history.pushState({urlPath: fileUrl, filePath: filePath}, filePath, fileUrl); } onpopstate = (event) => {