({ navKey })
| 8 | type WithCrossLinksProps = { navKey: NavigationKeys }; |
| 9 | |
| 10 | const WithSidebarCrossLinks: FC<WithCrossLinksProps> = ({ navKey }) => { |
| 11 | const { getSideNavigation } = useSiteNavigation(); |
| 12 | const { pathname } = getClientContext(); |
| 13 | |
| 14 | const [[, sidebarNavigation]] = getSideNavigation([navKey]); |
| 15 | |
| 16 | const crossLinkItems = sidebarNavigation.items |
| 17 | .map(([, { items }]) => items.map(([, item]) => item)) |
| 18 | .flat(); |
| 19 | |
| 20 | const currentItem = crossLinkItems.findIndex(({ link }) => link === pathname); |
| 21 | |
| 22 | const [previousCrossLink, nextCrossLink] = [ |
| 23 | crossLinkItems[currentItem - 1], |
| 24 | crossLinkItems[currentItem + 1], |
| 25 | ]; |
| 26 | |
| 27 | return ( |
| 28 | <div className="mt-4 grid w-full grid-cols-1 gap-4 md:grid-cols-2"> |
| 29 | {(previousCrossLink && ( |
| 30 | <CrossLink |
| 31 | type="previous" |
| 32 | text={previousCrossLink.label} |
| 33 | link={previousCrossLink.link} |
| 34 | /> |
| 35 | )) || <div />} |
| 36 | |
| 37 | {nextCrossLink && ( |
| 38 | <CrossLink |
| 39 | type="next" |
| 40 | text={nextCrossLink.label} |
| 41 | link={nextCrossLink.link} |
| 42 | /> |
| 43 | )} |
| 44 | </div> |
| 45 | ); |
| 46 | }; |
| 47 | |
| 48 | export default WithSidebarCrossLinks; |
nothing calls this directly
no test coverage detected