|
5 | 5 | * LICENSE file in the root directory of this source tree. |
6 | 6 | */ |
7 | 7 |
|
8 | | -'use client'; |
9 | | - |
10 | | -import * as React from 'react'; |
11 | | -import {usePathname} from 'next/navigation'; |
12 | 8 | import {SidebarNav} from 'components/Layout/SidebarNav'; |
13 | 9 | import {TopNav} from 'components/Layout/TopNav'; |
14 | | -import {getRouteMeta} from 'components/Layout/getRouteMeta'; |
15 | 10 | import type {RouteItem} from 'components/Layout/getRouteMeta'; |
16 | 11 | import sidebarLearn from '../../sidebarLearn.json'; |
17 | 12 |
|
18 | | -function RestoreHashAfterNavigation({pathname}: {pathname: string}) { |
19 | | - React.useEffect(() => { |
20 | | - if (!window.location.hash) { |
21 | | - return; |
22 | | - } |
23 | | - |
24 | | - const id = decodeURIComponent(window.location.hash.slice(1)); |
25 | | - // The Learn content remounts after a history traversal, so reapply the |
26 | | - // fragment once the replacement content is in the DOM. |
27 | | - const frame = requestAnimationFrame(() => { |
28 | | - document.getElementById(id)?.scrollIntoView(); |
29 | | - }); |
30 | | - return () => cancelAnimationFrame(frame); |
31 | | - }, [pathname]); |
32 | | - |
33 | | - return null; |
34 | | -} |
35 | | - |
36 | 13 | export default function LearnLayout({children}: {children: React.ReactNode}) { |
37 | | - const pathname = usePathname() || '/'; |
38 | 14 | const routeTree = sidebarLearn as RouteItem; |
39 | | - const {breadcrumbs} = getRouteMeta(pathname, routeTree); |
40 | 15 | return ( |
41 | 16 | <> |
42 | | - <RestoreHashAfterNavigation pathname={pathname} /> |
43 | | - <TopNav section="learn" routeTree={routeTree} breadcrumbs={breadcrumbs} /> |
| 17 | + <TopNav section="learn" routeTree={routeTree} /> |
44 | 18 | <div className="grid grid-cols-only-content lg:grid-cols-sidebar-content 2xl:grid-cols-sidebar-content-toc"> |
45 | 19 | <div className="lg:-mt-16 z-10"> |
46 | 20 | <div className="fixed top-0 py-0 shadow lg:pt-16 lg:sticky start-0 end-0 lg:shadow-none"> |
47 | | - <SidebarNav routeTree={routeTree} breadcrumbs={breadcrumbs} /> |
| 21 | + <SidebarNav routeTree={routeTree} /> |
48 | 22 | </div> |
49 | 23 | </div> |
50 | | - <React.Fragment key={pathname}>{children}</React.Fragment> |
| 24 | + {children} |
51 | 25 | </div> |
52 | 26 | </> |
53 | 27 | ); |
|
0 commit comments