|
| 1 | +'use client' |
| 2 | + |
| 3 | +import dynamic from 'next/dynamic' |
1 | 4 | import Link from 'next/link' |
2 | | -import { useRouter } from 'next/router' |
3 | 5 | import React, { useState } from 'react' |
4 | 6 | import { useWindowSize } from 'react-use' |
5 | 7 |
|
6 | | -import { useIsLoggedIn, useIsUserLoading, useUser } from 'common' |
| 8 | +import { useIsLoggedIn, useUser } from 'common' |
7 | 9 | import { Button, buttonVariants, cn } from 'ui' |
8 | 10 | import { AuthenticatedDropdownMenu } from 'ui-patterns' |
9 | | -import { |
10 | | - NavigationMenu, |
11 | | - NavigationMenuContent, |
12 | | - NavigationMenuItem, |
13 | | - NavigationMenuLink, |
14 | | - NavigationMenuList, |
15 | | - NavigationMenuTrigger, |
16 | | -} from 'ui/src/components/shadcn/ui/navigation-menu' |
17 | 11 |
|
18 | | -import ScrollProgress from 'components/ScrollProgress' |
19 | | -import { useSendTelemetryEvent } from 'lib/telemetry' |
20 | 12 | import GitHubButton from './GitHubButton' |
21 | 13 | import HamburgerButton from './HamburgerMenu' |
22 | | -import MenuItem from './MenuItem' |
23 | | -import MobileMenu from './MobileMenu' |
24 | 14 | import RightClickBrandLogo from './RightClickBrandLogo' |
| 15 | +import { useSendTelemetryEvent } from 'lib/telemetry' |
25 | 16 | import useDropdownMenu from './useDropdownMenu' |
26 | 17 |
|
27 | 18 | import { getMenu } from 'data/nav' |
| 19 | +import { usePathname } from 'next/navigation' |
| 20 | + |
| 21 | +const MenuItem = dynamic(() => import('./MenuItem')) |
| 22 | +const MobileMenu = dynamic(() => import('./MobileMenu')) |
| 23 | +const NavigationMenu = dynamic(() => |
| 24 | + import('ui/src/components/shadcn/ui/navigation-menu').then((mod) => mod.NavigationMenu) |
| 25 | +) |
| 26 | +const NavigationMenuContent = dynamic(() => |
| 27 | + import('ui/src/components/shadcn/ui/navigation-menu').then((mod) => mod.NavigationMenuContent) |
| 28 | +) |
| 29 | +const NavigationMenuItem = dynamic(() => |
| 30 | + import('ui/src/components/shadcn/ui/navigation-menu').then((mod) => mod.NavigationMenuItem) |
| 31 | +) |
| 32 | +const NavigationMenuLink = dynamic(() => |
| 33 | + import('ui/src/components/shadcn/ui/navigation-menu').then((mod) => mod.NavigationMenuLink) |
| 34 | +) |
| 35 | +const NavigationMenuList = dynamic(() => |
| 36 | + import('ui/src/components/shadcn/ui/navigation-menu').then((mod) => mod.NavigationMenuList) |
| 37 | +) |
| 38 | +const NavigationMenuTrigger = dynamic(() => |
| 39 | + import('ui/src/components/shadcn/ui/navigation-menu').then((mod) => mod.NavigationMenuTrigger) |
| 40 | +) |
| 41 | +const ScrollProgress = dynamic(() => import('components/ScrollProgress')) |
28 | 42 |
|
29 | 43 | interface Props { |
30 | 44 | hideNavbar: boolean |
31 | 45 | stickyNavbar?: boolean |
32 | 46 | } |
33 | 47 |
|
34 | 48 | const Nav = ({ hideNavbar, stickyNavbar = true }: Props) => { |
35 | | - const router = useRouter() |
| 49 | + const pathname = usePathname() |
36 | 50 | const { width } = useWindowSize() |
37 | 51 | const [open, setOpen] = useState(false) |
| 52 | + const isLoggedIn = useIsLoggedIn() |
38 | 53 | const menu = getMenu() |
39 | 54 | const sendTelemetryEvent = useSendTelemetryEvent() |
40 | 55 | const user = useUser() |
41 | 56 | const userMenu = useDropdownMenu(user) |
42 | 57 |
|
43 | | - const isLoggedIn = useIsLoggedIn() |
44 | | - const isLoadingUser = useIsUserLoading() |
45 | | - console.log({ isLoadingUser, isLoggedIn }) |
46 | | - |
47 | | - const isLaunchWeekPage = router.pathname.includes('/launch-week') |
48 | | - const isLaunchWeekXPage = router.pathname === '/launch-week/x' |
49 | | - const isGAWeekSection = router.pathname.startsWith('/ga-week') |
| 58 | + const isLaunchWeekPage = pathname?.includes('/launch-week') |
| 59 | + const isLaunchWeekXPage = pathname === '/launch-week/x' |
| 60 | + const isGAWeekSection = pathname?.startsWith('/ga-week') |
50 | 61 | const disableStickyNav = isLaunchWeekXPage || isGAWeekSection || isLaunchWeekPage || !stickyNavbar |
51 | 62 | const showLaunchWeekNavMode = !isLaunchWeekXPage && (isLaunchWeekPage || isGAWeekSection) && !open |
52 | 63 |
|
@@ -129,49 +140,47 @@ const Nav = ({ hideNavbar, stickyNavbar = true }: Props) => { |
129 | 140 | </NavigationMenuList> |
130 | 141 | </NavigationMenu> |
131 | 142 | </div> |
132 | | - {!isLoadingUser && ( |
133 | | - <div className="flex items-center gap-2 opacity-0 animate-fade-in !scale-100 delay-300"> |
134 | | - <GitHubButton /> |
| 143 | + <div className="flex items-center gap-2 opacity-0 animate-fade-in !scale-100 delay-300"> |
| 144 | + <GitHubButton /> |
135 | 145 |
|
136 | | - {isLoggedIn ? ( |
137 | | - <> |
138 | | - <Button className="hidden lg:block" asChild> |
139 | | - <Link href="/dashboard/projects">Dashboard</Link> |
140 | | - </Button> |
141 | | - <AuthenticatedDropdownMenu menu={userMenu} user={user} site="www" /> |
142 | | - </> |
143 | | - ) : ( |
144 | | - <> |
145 | | - <Button type="default" className="hidden lg:block" asChild> |
146 | | - <Link |
147 | | - href="https://supabase.com/dashboard" |
148 | | - onClick={() => |
149 | | - sendTelemetryEvent({ |
150 | | - action: 'sign_in_button_clicked', |
151 | | - properties: { buttonLocation: 'Header Nav' }, |
152 | | - }) |
153 | | - } |
154 | | - > |
155 | | - Sign in |
156 | | - </Link> |
157 | | - </Button> |
158 | | - <Button className="hidden lg:block" asChild> |
159 | | - <Link |
160 | | - href="https://supabase.com/dashboard" |
161 | | - onClick={() => |
162 | | - sendTelemetryEvent({ |
163 | | - action: 'start_project_button_clicked', |
164 | | - properties: { buttonLocation: 'Header Nav' }, |
165 | | - }) |
166 | | - } |
167 | | - > |
168 | | - Start your project |
169 | | - </Link> |
170 | | - </Button> |
171 | | - </> |
172 | | - )} |
173 | | - </div> |
174 | | - )} |
| 146 | + {isLoggedIn ? ( |
| 147 | + <> |
| 148 | + <Button className="hidden lg:block" asChild> |
| 149 | + <Link href="/dashboard/projects">Dashboard</Link> |
| 150 | + </Button> |
| 151 | + <AuthenticatedDropdownMenu menu={userMenu} user={user} site="www" /> |
| 152 | + </> |
| 153 | + ) : ( |
| 154 | + <> |
| 155 | + <Button type="default" className="hidden lg:block" asChild> |
| 156 | + <Link |
| 157 | + href="https://supabase.com/dashboard" |
| 158 | + onClick={() => |
| 159 | + sendTelemetryEvent({ |
| 160 | + action: 'sign_in_button_clicked', |
| 161 | + properties: { buttonLocation: 'Header Nav' }, |
| 162 | + }) |
| 163 | + } |
| 164 | + > |
| 165 | + Sign in |
| 166 | + </Link> |
| 167 | + </Button> |
| 168 | + <Button className="hidden lg:block" asChild> |
| 169 | + <Link |
| 170 | + href="https://supabase.com/dashboard" |
| 171 | + onClick={() => |
| 172 | + sendTelemetryEvent({ |
| 173 | + action: 'start_project_button_clicked', |
| 174 | + properties: { buttonLocation: 'Header Nav' }, |
| 175 | + }) |
| 176 | + } |
| 177 | + > |
| 178 | + Start your project |
| 179 | + </Link> |
| 180 | + </Button> |
| 181 | + </> |
| 182 | + )} |
| 183 | + </div> |
175 | 184 | </div> |
176 | 185 | <HamburgerButton |
177 | 186 | toggleFlyOut={() => setOpen(true)} |
|
0 commit comments