1
0
mirror of https://github.com/oceanprotocol/docs.git synced 2024-11-26 19:49:26 +01:00

Improvement: Rename variables

This commit is contained in:
Akshay 2021-05-18 18:12:54 +02:00
parent d6f94e0b53
commit 4233a96ad8

View File

@ -10,9 +10,9 @@ import sidebarStyles from '../components/Sidebar.module.scss'
export default function MarkdownList({ pageContext }) { export default function MarkdownList({ pageContext }) {
const modules = {} const modules = {}
const nested = {} const nestedModules = {}
function generatedNested(obj, keyPath, value) { function generatedNested(obj, keyPath, node) {
var lastKeyIndex = keyPath.length - 1 var lastKeyIndex = keyPath.length - 1
for (var i = 0; i < lastKeyIndex; ++i) { for (var i = 0; i < lastKeyIndex; ++i) {
var key = keyPath[i] var key = keyPath[i]
@ -23,8 +23,8 @@ export default function MarkdownList({ pageContext }) {
} }
if (!obj[keyPath[lastKeyIndex]]) { if (!obj[keyPath[lastKeyIndex]]) {
obj[keyPath[lastKeyIndex]] = { obj[keyPath[lastKeyIndex]] = {
id: value.id, id: node.id,
label: value.frontmatter.title label: node.frontmatter.title
} }
} }
} }
@ -40,7 +40,7 @@ export default function MarkdownList({ pageContext }) {
} }
modules[key].push(node) modules[key].push(node)
generatedNested(nested, modulePath, node) generatedNested(nestedModules, modulePath, node)
}) })
const moduleKeys = Object.keys(modules).sort() const moduleKeys = Object.keys(modules).sort()
@ -61,28 +61,28 @@ export default function MarkdownList({ pageContext }) {
} }
} }
const g = (title, nested) => { const generateNestedSidebarList = (title, nestedModules) => {
if (nested.id) { if (nestedModules.id) {
return ( return (
<li key={nested.id} id={nested.id}> <li key={nestedModules.id} id={nestedModules.id}>
<a <a
className={ className={
selectedNodeId === nested.id selectedNodeId === nestedModules.id
? sidebarStyles.active ? sidebarStyles.active
: sidebarStyles.link : sidebarStyles.link
} }
onClick={() => changeNodeid(nested.id)} onClick={() => changeNodeid(nestedModules.id)}
style={{ style={{
cursor: 'pointer', cursor: 'pointer',
color: selectedNodeId === nested.id ? 'black' : '#8b98a9' color: selectedNodeId === nestedModules.id ? 'black' : '#8b98a9'
}} }}
> >
{nested.label} {nestedModules.label}
</a> </a>
</li> </li>
) )
} else { } else {
const keys = Object.keys(nested).sort() const keys = Object.keys(nestedModules).sort()
const children = [] const children = []
children.push( children.push(
<li key={title}> <li key={title}>
@ -91,14 +91,16 @@ export default function MarkdownList({ pageContext }) {
) )
keys.forEach((element) => { keys.forEach((element) => {
children.push( children.push(
<ul className={sidebarStyles.list}>{g(element, nested[element])}</ul> <ul className={sidebarStyles.list}>
{generateNestedSidebarList(element, nestedModules[element])}
</ul>
) )
}) })
return children return children
} }
} }
const n2 = g(null, nested) const nestedSidebarList = generateNestedSidebarList(null, nestedModules)
return ( return (
<Layout> <Layout>
@ -111,7 +113,7 @@ export default function MarkdownList({ pageContext }) {
</div> </div>
<main className={styles.wrapper}> <main className={styles.wrapper}>
<aside className={styles.sidebar}> <aside className={styles.sidebar}>
<div className={sidebarStyles.sidebar}>{n2}</div> <div className={sidebarStyles.sidebar}>{nestedSidebarList}</div>
</aside> </aside>
<article className={styles.main}> <article className={styles.main}>
<MarkdownTemplate data={elem} /> <MarkdownTemplate data={elem} />