MCPcopy Create free account
hub / github.com/nodejs/nodejs.org / WithSidebarCrossLinks

Function WithSidebarCrossLinks

apps/site/components/withSidebarCrossLinks.tsx:10–46  ·  view source on GitHub ↗
({ navKey })

Source from the content-addressed store, hash-verified

8type WithCrossLinksProps = { navKey: NavigationKeys };
9
10const 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
48export default WithSidebarCrossLinks;

Callers

nothing calls this directly

Calls 2

useSiteNavigationFunction · 0.85
getSideNavigationFunction · 0.85

Tested by

no test coverage detected