1
1
import { useRouter } from "next/router"
2
2
import { useTranslation } from "next-i18next"
3
3
import { FaChevronLeft , FaChevronRight } from "react-icons/fa"
4
+ import { Text } from "@chakra-ui/react"
4
5
5
6
import { TranslationKey } from "@/lib/types"
6
7
import type { DeveloperDocsLink } from "@/lib/interfaces"
7
8
8
9
import { BaseLink } from "@/components/Link"
9
- import Text from "@/components/OldText"
10
10
11
11
import { cn } from "@/lib/utils/cn"
12
12
import { trackCustomEvent } from "@/lib/utils/matomo"
@@ -87,18 +87,25 @@ const DocsNav = ({ contentNotTranslated }: DocsNavProps) => {
87
87
const { asPath } = useRouter ( )
88
88
const docsArray : DocsArrayProps [ ] = [ ]
89
89
const getDocs = ( links : Array < DeveloperDocsLink > ) : void => {
90
+ // If object has 'items' key
90
91
for ( const item of links ) {
92
+ // And if item has a 'to' key
93
+ // Add 'to' path and 'id' to docsArray
91
94
if ( item . items ) {
92
95
item . href && docsArray . push ( { href : item . href , id : item . id } )
96
+ // Then recursively add sub-items
93
97
getDocs ( item . items )
94
98
} else {
99
+ // If object has no further 'items', add and continue
95
100
docsArray . push ( { href : item . href , id : item . id } )
96
101
}
97
102
}
98
103
}
99
104
105
+ // Initiate recursive loop with full docLinks yaml
100
106
getDocs ( docLinks )
101
107
108
+ // Find index that matches current page
102
109
let currentIndex = 0
103
110
for ( let i = 0 ; i < docsArray . length ; i ++ ) {
104
111
if (
@@ -109,6 +116,7 @@ const DocsNav = ({ contentNotTranslated }: DocsNavProps) => {
109
116
}
110
117
}
111
118
119
+ // Extract previous and next doc based on current index +/- 1
112
120
const previousDoc = currentIndex - 1 >= 0 ? docsArray [ currentIndex - 1 ] : null
113
121
const nextDoc =
114
122
currentIndex + 1 < docsArray . length ? docsArray [ currentIndex + 1 ] : null
0 commit comments