Skip to content

Commit b9417ad

Browse files
committed
feat: use new components?
1 parent 399f42f commit b9417ad

File tree

1 file changed

+9
-1
lines changed

1 file changed

+9
-1
lines changed

src/components/DocsNav.tsx

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,12 @@
11
import { useRouter } from "next/router"
22
import { useTranslation } from "next-i18next"
33
import { FaChevronLeft, FaChevronRight } from "react-icons/fa"
4+
import { Text } from "@chakra-ui/react"
45

56
import { TranslationKey } from "@/lib/types"
67
import type { DeveloperDocsLink } from "@/lib/interfaces"
78

89
import { BaseLink } from "@/components/Link"
9-
import Text from "@/components/OldText"
1010

1111
import { cn } from "@/lib/utils/cn"
1212
import { trackCustomEvent } from "@/lib/utils/matomo"
@@ -87,18 +87,25 @@ const DocsNav = ({ contentNotTranslated }: DocsNavProps) => {
8787
const { asPath } = useRouter()
8888
const docsArray: DocsArrayProps[] = []
8989
const getDocs = (links: Array<DeveloperDocsLink>): void => {
90+
// If object has 'items' key
9091
for (const item of links) {
92+
// And if item has a 'to' key
93+
// Add 'to' path and 'id' to docsArray
9194
if (item.items) {
9295
item.href && docsArray.push({ href: item.href, id: item.id })
96+
// Then recursively add sub-items
9397
getDocs(item.items)
9498
} else {
99+
// If object has no further 'items', add and continue
95100
docsArray.push({ href: item.href, id: item.id })
96101
}
97102
}
98103
}
99104

105+
// Initiate recursive loop with full docLinks yaml
100106
getDocs(docLinks)
101107

108+
// Find index that matches current page
102109
let currentIndex = 0
103110
for (let i = 0; i < docsArray.length; i++) {
104111
if (
@@ -109,6 +116,7 @@ const DocsNav = ({ contentNotTranslated }: DocsNavProps) => {
109116
}
110117
}
111118

119+
// Extract previous and next doc based on current index +/- 1
112120
const previousDoc = currentIndex - 1 >= 0 ? docsArray[currentIndex - 1] : null
113121
const nextDoc =
114122
currentIndex + 1 < docsArray.length ? docsArray[currentIndex + 1] : null

0 commit comments

Comments
 (0)