mirror of
https://github.com/oceanprotocol/docs.git
synced 2024-11-26 19:49:26 +01:00
Improvement: Set default selected node in sidebar
This commit is contained in:
parent
01df71c654
commit
58c3dd7127
@ -11,19 +11,6 @@ export default function MarkdownList({ pageContext }) {
|
|||||||
const modules = {}
|
const modules = {}
|
||||||
|
|
||||||
const nested = {}
|
const nested = {}
|
||||||
const [selectedNodeId, setSelectedNodeId] = useState(0)
|
|
||||||
|
|
||||||
const changeNodeid = (id) => {
|
|
||||||
setSelectedNodeId(id)
|
|
||||||
|
|
||||||
for (let i = 0; i < pageContext.markdownList.length; i++) {
|
|
||||||
var node = pageContext.markdownList[i]['node']
|
|
||||||
if (node.id == id) {
|
|
||||||
setElem(node)
|
|
||||||
break
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
function generatedNested(obj, keyPath, value) {
|
function generatedNested(obj, keyPath, value) {
|
||||||
var lastKeyIndex = keyPath.length - 1
|
var lastKeyIndex = keyPath.length - 1
|
||||||
@ -56,6 +43,24 @@ export default function MarkdownList({ pageContext }) {
|
|||||||
generatedNested(nested, modulePath, node)
|
generatedNested(nested, modulePath, node)
|
||||||
})
|
})
|
||||||
|
|
||||||
|
const moduleKeys = Object.keys(modules).sort()
|
||||||
|
const [selectedNodeId, setSelectedNodeId] = useState(
|
||||||
|
modules[moduleKeys[0]][0].id
|
||||||
|
)
|
||||||
|
const [elem, setElem] = useState(modules[moduleKeys[0]][0])
|
||||||
|
|
||||||
|
const changeNodeid = (id) => {
|
||||||
|
setSelectedNodeId(id)
|
||||||
|
|
||||||
|
for (let i = 0; i < pageContext.markdownList.length; i++) {
|
||||||
|
var node = pageContext.markdownList[i]['node']
|
||||||
|
if (node.id == id) {
|
||||||
|
setElem(node)
|
||||||
|
break
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
const g = (title, nested) => {
|
const g = (title, nested) => {
|
||||||
if (nested.id) {
|
if (nested.id) {
|
||||||
return (
|
return (
|
||||||
@ -95,21 +100,6 @@ export default function MarkdownList({ pageContext }) {
|
|||||||
|
|
||||||
const n2 = g(null, nested)
|
const n2 = g(null, nested)
|
||||||
|
|
||||||
const moduleKeys = Object.keys(modules).sort()
|
|
||||||
|
|
||||||
const [selectedSubSection, setSelectedSubSection] = useState(0)
|
|
||||||
const [elem, setElem] = useState(modules[moduleKeys[selectedSubSection]][0])
|
|
||||||
|
|
||||||
const changePage = (subSectionIndex, node) => {
|
|
||||||
setElem(node)
|
|
||||||
setSelectedSubSection(subSectionIndex)
|
|
||||||
}
|
|
||||||
|
|
||||||
const changeSubsection = (index) => {
|
|
||||||
setSelectedSubSection(index)
|
|
||||||
setElem(modules[moduleKeys[index]][0])
|
|
||||||
}
|
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<Layout>
|
<Layout>
|
||||||
<HeaderSection title={pageContext.name} />
|
<HeaderSection title={pageContext.name} />
|
||||||
|
Loading…
Reference in New Issue
Block a user