33import { useCallback , useEffect , useRef , useState } from 'react'
44import Image from 'next/image'
55import Link from 'next/link'
6+ import { useSearchParams } from 'next/navigation'
67import { GithubOutlineIcon } from '@/components/icons'
8+ import { useSession } from '@/lib/auth/auth-client'
79import { cn } from '@/lib/core/utils/cn'
810import {
911 BlogDropdown ,
@@ -40,6 +42,12 @@ interface NavbarProps {
4042
4143export default function Navbar ( { logoOnly = false , blogPosts = [ ] } : NavbarProps ) {
4244 const brand = getBrandConfig ( )
45+ const searchParams = useSearchParams ( )
46+ const { data : session , isPending : isSessionPending } = useSession ( )
47+ const isAuthenticated = Boolean ( session ?. user ?. id )
48+ const isBrowsingHome = searchParams . has ( 'home' )
49+ const useHomeLinks = isAuthenticated || isBrowsingHome
50+ const logoHref = useHomeLinks ? '/?home' : '/'
4351 const [ activeDropdown , setActiveDropdown ] = useState < DropdownId > ( null )
4452 const [ hoveredLink , setHoveredLink ] = useState < string | null > ( null )
4553 const [ mobileMenuOpen , setMobileMenuOpen ] = useState ( false )
@@ -92,7 +100,7 @@ export default function Navbar({ logoOnly = false, blogPosts = [] }: NavbarProps
92100 itemScope
93101 itemType = 'https://schema.org/SiteNavigationElement'
94102 >
95- < Link href = '/' className = { LOGO_CELL } aria-label = { `${ brand . name } home` } itemProp = 'url' >
103+ < Link href = { logoHref } className = { LOGO_CELL } aria-label = { `${ brand . name } home` } itemProp = 'url' >
96104 < span itemProp = 'name' className = 'sr-only' >
97105 { brand . name }
98106 </ span >
@@ -121,7 +129,9 @@ export default function Navbar({ logoOnly = false, blogPosts = [] }: NavbarProps
121129 { ! logoOnly && (
122130 < >
123131 < ul className = 'mt-[0.75px] hidden lg:flex' >
124- { NAV_LINKS . map ( ( { label, href, external, icon, dropdown } ) => {
132+ { NAV_LINKS . map ( ( { label, href : rawHref , external, icon, dropdown } ) => {
133+ const href =
134+ useHomeLinks && rawHref . startsWith ( '/#' ) ? `/?home${ rawHref . slice ( 1 ) } ` : rawHref
125135 const hasDropdown = ! ! dropdown
126136 const isActive = hasDropdown && activeDropdown === dropdown
127137 const isThisHovered = hoveredLink === label
@@ -206,21 +216,38 @@ export default function Navbar({ logoOnly = false, blogPosts = [] }: NavbarProps
206216
207217 < div className = 'hidden flex-1 lg:block' />
208218
209- < div className = 'hidden items-center gap-[8px] pr-[80px] pl-[20px] lg:flex' >
210- < Link
211- href = '/login'
212- className = 'inline-flex h-[30px] items-center rounded-[5px] border border-[#3d3d3d] px-[9px] text-[#ECECEC] text-[13.5px] transition-colors hover:bg-[#2A2A2A]'
213- aria-label = 'Log in'
214- >
215- Log in
216- </ Link >
217- < Link
218- href = '/signup'
219- className = 'inline-flex h-[30px] items-center gap-[7px] rounded-[5px] border border-[#FFFFFF] bg-[#FFFFFF] px-[9px] text-[13.5px] text-black transition-colors hover:border-[#E0E0E0] hover:bg-[#E0E0E0]'
220- aria-label = 'Get started with Sim'
221- >
222- Get started
223- </ Link >
219+ < div
220+ className = { cn (
221+ 'hidden items-center gap-[8px] pr-[80px] pl-[20px] lg:flex' ,
222+ isSessionPending && 'invisible'
223+ ) }
224+ >
225+ { isAuthenticated ? (
226+ < Link
227+ href = '/workspace'
228+ className = 'inline-flex h-[30px] items-center gap-[7px] rounded-[5px] border border-[#FFFFFF] bg-[#FFFFFF] px-[9px] text-[13.5px] text-black transition-colors hover:border-[#E0E0E0] hover:bg-[#E0E0E0]'
229+ aria-label = 'Go to app'
230+ >
231+ Go to App
232+ </ Link >
233+ ) : (
234+ < >
235+ < Link
236+ href = '/login'
237+ className = 'inline-flex h-[30px] items-center rounded-[5px] border border-[#3d3d3d] px-[9px] text-[#ECECEC] text-[13.5px] transition-colors hover:bg-[#2A2A2A]'
238+ aria-label = 'Log in'
239+ >
240+ Log in
241+ </ Link >
242+ < Link
243+ href = '/signup'
244+ className = 'inline-flex h-[30px] items-center gap-[7px] rounded-[5px] border border-[#FFFFFF] bg-[#FFFFFF] px-[9px] text-[13.5px] text-black transition-colors hover:border-[#E0E0E0] hover:bg-[#E0E0E0]'
245+ aria-label = 'Get started with Sim'
246+ >
247+ Get started
248+ </ Link >
249+ </ >
250+ ) }
224251 </ div >
225252
226253 < div className = 'flex flex-1 items-center justify-end pr-[20px] lg:hidden' >
@@ -242,30 +269,34 @@ export default function Navbar({ logoOnly = false, blogPosts = [] }: NavbarProps
242269 ) }
243270 >
244271 < ul className = 'flex flex-col' >
245- { NAV_LINKS . map ( ( { label, href, external } ) => (
246- < li key = { label } className = 'border-[#2A2A2A] border-b' >
247- { external ? (
248- < a
249- href = { href }
250- target = '_blank'
251- rel = 'noopener noreferrer'
252- className = 'flex items-center justify-between px-[20px] py-[14px] text-[#ECECEC] transition-colors active:bg-[#2A2A2A]'
253- onClick = { ( ) => setMobileMenuOpen ( false ) }
254- >
255- { label }
256- < ExternalArrowIcon />
257- </ a >
258- ) : (
259- < Link
260- href = { href }
261- className = 'flex items-center px-[20px] py-[14px] text-[#ECECEC] transition-colors active:bg-[#2A2A2A]'
262- onClick = { ( ) => setMobileMenuOpen ( false ) }
263- >
264- { label }
265- </ Link >
266- ) }
267- </ li >
268- ) ) }
272+ { NAV_LINKS . map ( ( { label, href : rawHref , external } ) => {
273+ const href =
274+ useHomeLinks && rawHref . startsWith ( '/#' ) ? `/?home${ rawHref . slice ( 1 ) } ` : rawHref
275+ return (
276+ < li key = { label } className = 'border-[#2A2A2A] border-b' >
277+ { external ? (
278+ < a
279+ href = { href }
280+ target = '_blank'
281+ rel = 'noopener noreferrer'
282+ className = 'flex items-center justify-between px-[20px] py-[14px] text-[#ECECEC] transition-colors active:bg-[#2A2A2A]'
283+ onClick = { ( ) => setMobileMenuOpen ( false ) }
284+ >
285+ { label }
286+ < ExternalArrowIcon />
287+ </ a >
288+ ) : (
289+ < Link
290+ href = { href }
291+ className = 'flex items-center px-[20px] py-[14px] text-[#ECECEC] transition-colors active:bg-[#2A2A2A]'
292+ onClick = { ( ) => setMobileMenuOpen ( false ) }
293+ >
294+ { label }
295+ </ Link >
296+ ) }
297+ </ li >
298+ )
299+ } ) }
269300 < li className = 'border-[#2A2A2A] border-b' >
270301 < a
271302 href = 'https://github.com/simstudioai/sim'
@@ -280,23 +311,41 @@ export default function Navbar({ logoOnly = false, blogPosts = [] }: NavbarProps
280311 </ li >
281312 </ ul >
282313
283- < div className = 'mt-auto flex flex-col gap-[10px] p-[20px]' >
284- < Link
285- href = '/login'
286- className = 'flex h-[32px] items-center justify-center rounded-[5px] border border-[#3d3d3d] text-[#ECECEC] text-[14px] transition-colors active:bg-[#2A2A2A]'
287- onClick = { ( ) => setMobileMenuOpen ( false ) }
288- aria-label = 'Log in'
289- >
290- Log in
291- </ Link >
292- < Link
293- href = '/signup'
294- className = 'flex h-[32px] items-center justify-center rounded-[5px] border border-[#FFFFFF] bg-[#FFFFFF] text-[14px] text-black transition-colors active:bg-[#E0E0E0]'
295- onClick = { ( ) => setMobileMenuOpen ( false ) }
296- aria-label = 'Get started with Sim'
297- >
298- Get started
299- </ Link >
314+ < div
315+ className = { cn (
316+ 'mt-auto flex flex-col gap-[10px] p-[20px]' ,
317+ isSessionPending && 'invisible'
318+ ) }
319+ >
320+ { isAuthenticated ? (
321+ < Link
322+ href = '/workspace'
323+ className = 'flex h-[32px] items-center justify-center rounded-[5px] border border-[#FFFFFF] bg-[#FFFFFF] text-[14px] text-black transition-colors active:bg-[#E0E0E0]'
324+ onClick = { ( ) => setMobileMenuOpen ( false ) }
325+ aria-label = 'Go to app'
326+ >
327+ Go to App
328+ </ Link >
329+ ) : (
330+ < >
331+ < Link
332+ href = '/login'
333+ className = 'flex h-[32px] items-center justify-center rounded-[5px] border border-[#3d3d3d] text-[#ECECEC] text-[14px] transition-colors active:bg-[#2A2A2A]'
334+ onClick = { ( ) => setMobileMenuOpen ( false ) }
335+ aria-label = 'Log in'
336+ >
337+ Log in
338+ </ Link >
339+ < Link
340+ href = '/signup'
341+ className = 'flex h-[32px] items-center justify-center rounded-[5px] border border-[#FFFFFF] bg-[#FFFFFF] text-[14px] text-black transition-colors active:bg-[#E0E0E0]'
342+ onClick = { ( ) => setMobileMenuOpen ( false ) }
343+ aria-label = 'Get started with Sim'
344+ >
345+ Get started
346+ </ Link >
347+ </ >
348+ ) }
300349 </ div >
301350 </ div >
302351 </ >
0 commit comments