|
3 | 3 | import { useCallback, useEffect, useRef, useState } from 'react' |
4 | 4 | import Image from 'next/image' |
5 | 5 | import Link from 'next/link' |
| 6 | +import { useSearchParams } from 'next/navigation' |
6 | 7 | import { GithubOutlineIcon } from '@/components/icons' |
7 | 8 | import { useSession } from '@/lib/auth/auth-client' |
8 | 9 | import { cn } from '@/lib/core/utils/cn' |
@@ -41,9 +42,12 @@ interface NavbarProps { |
41 | 42 |
|
42 | 43 | export default function Navbar({ logoOnly = false, blogPosts = [] }: NavbarProps) { |
43 | 44 | const brand = getBrandConfig() |
| 45 | + const searchParams = useSearchParams() |
44 | 46 | const { data: session, isPending: isSessionPending } = useSession() |
45 | 47 | const isAuthenticated = Boolean(session?.user?.id) |
46 | | - const logoHref = isAuthenticated ? '/?home' : '/' |
| 48 | + const isBrowsingHome = searchParams.has('home') |
| 49 | + const useHomeLinks = isAuthenticated || isBrowsingHome |
| 50 | + const logoHref = useHomeLinks ? '/?home' : '/' |
47 | 51 | const [activeDropdown, setActiveDropdown] = useState<DropdownId>(null) |
48 | 52 | const [hoveredLink, setHoveredLink] = useState<string | null>(null) |
49 | 53 | const [mobileMenuOpen, setMobileMenuOpen] = useState(false) |
@@ -127,7 +131,7 @@ export default function Navbar({ logoOnly = false, blogPosts = [] }: NavbarProps |
127 | 131 | <ul className='mt-[0.75px] hidden lg:flex'> |
128 | 132 | {NAV_LINKS.map(({ label, href: rawHref, external, icon, dropdown }) => { |
129 | 133 | const href = |
130 | | - isAuthenticated && rawHref.startsWith('/#') ? `/?home${rawHref.slice(1)}` : rawHref |
| 134 | + useHomeLinks && rawHref.startsWith('/#') ? `/?home${rawHref.slice(1)}` : rawHref |
131 | 135 | const hasDropdown = !!dropdown |
132 | 136 | const isActive = hasDropdown && activeDropdown === dropdown |
133 | 137 | const isThisHovered = hoveredLink === label |
@@ -267,7 +271,7 @@ export default function Navbar({ logoOnly = false, blogPosts = [] }: NavbarProps |
267 | 271 | <ul className='flex flex-col'> |
268 | 272 | {NAV_LINKS.map(({ label, href: rawHref, external }) => { |
269 | 273 | const href = |
270 | | - isAuthenticated && rawHref.startsWith('/#') |
| 274 | + useHomeLinks && rawHref.startsWith('/#') |
271 | 275 | ? `/?home${rawHref.slice(1)}` |
272 | 276 | : rawHref |
273 | 277 | return ( |
|
0 commit comments