Skip to content

armgit / E2B

Public Imported from GitHub
0

Open-source, secure environment with real-world tools for enterprise-grade agents.

Correctly highlight either SDK reference or docs links; fix bug causing the navigation items not being highlighted in the sdk reference

Vasek Mlejnsky9030f348cc0a
diff --git a/apps/web/src/components/Header.tsx b/apps/web/src/components/Header.tsx
index d275a8f59..aaedbb3c7 100644
--- a/apps/web/src/components/Header.tsx
+++ b/apps/web/src/components/Header.tsx
@@ -33,9 +33,7 @@ function DocumentationTypeLink({
<Link
className={clsx(
'hover:text-white hover:cursor-pointer text-sm font-medium px-2 py-1 rounded-md',
- pathname.startsWith(href) &&
- // XXX: this is a hack to avoid the /docs and /docs/sdk-reference links being highlighted at the same time
- !(href === '/docs' && pathname.startsWith('/docs/sdk-reference'))
+ pathname.startsWith(href)
? 'text-white bg-zinc-800'
: 'text-neutral-400'
)}
@@ -149,15 +147,7 @@ export const Header = forwardRef(function Header({ className }, ref) {
/>
</ul>
</nav>
- {/* {isDocs && <MobileSearch />} */}
<div className="hidden min-[540px]:contents">
- {/* <Link className='hover:text-white hover:cursor-pointer text-sm text-neutral-400' href='/docs'>
- Docs
- </Link>
- <Link className='hover:text-white hover:cursor-pointer text-sm text-neutral-400' href='/dashboard'>
- Dashboard
- </Link>
- <HeaderSeparator /> */}
<Auth />
</div>
</div>
diff --git a/apps/web/src/components/Navigation/DocsTypeItems.tsx b/apps/web/src/components/Navigation/DocsTypeItems.tsx
index 3c4ae954d..88d9878cc 100644
--- a/apps/web/src/components/Navigation/DocsTypeItems.tsx
+++ b/apps/web/src/components/Navigation/DocsTypeItems.tsx
@@ -5,16 +5,23 @@ import { BookIcon, BracesIcon } from 'lucide-react'
function Item({
href,
+ allHrefs,
icon,
title,
}: {
href: string
+ allHrefs: string[]
icon: React.ReactNode
title: string
}) {
const pathname = usePathname()
- console.log(pathname, href)
- const isActive = pathname === href
+ const bestMatch = allHrefs.find(h =>
+ pathname.startsWith(h) &&
+ (pathname.length === h.length || pathname.charAt(h.length) === '/')
+ )
+
+ const isActive = href === bestMatch
+
return (
<Link href={href} className={clsx(
'text-xs flex items-center gap-2 group p-1 transition-all',
@@ -36,8 +43,9 @@ function Item({
export function DocsTypes() {
return (
<>
- <Item href="/docs" icon={<BookIcon className="w-4 h-4 text-white" />} title="Documentation" />
- <Item href="/docs/sdk-reference" icon={<BracesIcon className="w-4 h-4 text-white" />} title="SDK Reference" />
+ {/* Order of allHrefs is important here to calculate `bestMatch` correctly! */}
+ <Item href="/docs" icon={<BookIcon className="w-4 h-4 text-white" />} title="Documentation" allHrefs={['/docs/sdk-reference', '/docs']} />
+ <Item href="/docs/sdk-reference" icon={<BracesIcon className="w-4 h-4 text-white" />} title="SDK Reference" allHrefs={['/docs/sdk-reference', '/docs']} />
<li className="h-px bg-white/5 my-4"></li>
</>
)
diff --git a/apps/web/src/components/Navigation/NavigationLink.tsx b/apps/web/src/components/Navigation/NavigationLink.tsx
index 59d0611ba..5153a35a9 100644
--- a/apps/web/src/components/Navigation/NavigationLink.tsx
+++ b/apps/web/src/components/Navigation/NavigationLink.tsx
@@ -16,7 +16,16 @@ export function NavigationLink({
tag?: string
}) {
const pathname = usePathname()
- const isActive = pathname === link.href
+ // Add this to get the hash
+ const hash = typeof window !== 'undefined' ? window.location.hash : ''
+
+ // Modify the isActive check to include hash comparison if needed
+ const isActive = pathname === link.href ||
+ (link.href.includes('#') && pathname + hash === link.href)
+ // const pathname = usePathname()
+ // console.log(link)
+ // console.log(link.title, pathname, link.href)
+ // const isActive = pathname === link.href
return (
<Link