33import { useEffect , useRef , useState } from "react"
44import { clsx } from "clsx" ;
55import Link from "next/link" ;
6+ import { usePathname } from "next/navigation" ;
67
78const tabs = [ {
89 title : 'Product Docs' ,
@@ -18,15 +19,28 @@ const tabs = [{
1819{
1920 title : 'Changelog (EE)' ,
2021 href : '/docs/changelog' ,
22+ } ,
23+ {
24+ title : 'Legal' ,
25+ href : '/docs/legal' ,
2126}
2227]
2328
2429export default function TopBarNaigation ( ) {
30+ const pathname = usePathname ( )
2531 const [ hoveredIndex , setHoveredIndex ] = useState < number | null > ( null )
2632 const [ activeIndex , setActiveIndex ] = useState ( - 1 )
2733 const [ hoverStyle , setHoverStyle ] = useState ( { } )
2834 const [ activeStyle , setActiveStyle ] = useState ( { left : "0px" , width : "0px" } )
2935 const tabRefs = useRef < ( HTMLDivElement | null ) [ ] > ( [ ] )
36+
37+ // Filter tabs based on current path - only show Legal if we're on /docs/legal
38+ const visibleTabs = tabs . filter ( tab => {
39+ if ( tab . href === '/docs/legal' ) {
40+ return pathname === '/docs/legal' || pathname . startsWith ( '/docs/legal/' )
41+ }
42+ return true
43+ } )
3044
3145 useEffect ( ( ) => {
3246 if ( hoveredIndex !== null ) {
@@ -52,14 +66,11 @@ export default function TopBarNaigation() {
5266 }
5367 } , [ activeIndex ] )
5468
55- // Determine which tab should be active based on the current path when component mounts
69+ // Determine which tab should be active based on the current path
5670 useEffect ( ( ) => {
57- if ( typeof window !== 'undefined' ) {
58- const path = window . location . pathname ;
59- const activeTabIndex = tabs . findIndex ( tab => path . startsWith ( tab . href ) ) ;
60- setActiveIndex ( activeTabIndex !== - 1 ? activeTabIndex : 0 ) ;
61- }
62- } , [ ] ) ;
71+ const activeTabIndex = visibleTabs . findIndex ( tab => pathname . startsWith ( tab . href ) ) ;
72+ setActiveIndex ( activeTabIndex !== - 1 ? activeTabIndex : 0 ) ;
73+ } , [ pathname , visibleTabs ] ) ;
6374
6475 // Apply active style whenever activeIndex changes or after the component has mounted
6576 useEffect ( ( ) => {
@@ -95,7 +106,7 @@ export default function TopBarNaigation() {
95106
96107 { /* Tabs */ }
97108 < div className = "relative flex gap-3 items-center" >
98- { tabs . map ( ( tab , index ) => (
109+ { visibleTabs . map ( ( tab , index ) => (
99110 < Link key = { index } href = { tab . href } >
100111 < div
101112 ref = { ( el ) => { tabRefs . current [ index ] = el ; } }
0 commit comments