diff --git a/apps/www/components/Nav/AuthenticatedDropdownMenu.tsx b/apps/www/components/Nav/AuthenticatedDropdownMenu.tsx new file mode 100644 index 00000000000..e0e31f5f4f3 --- /dev/null +++ b/apps/www/components/Nav/AuthenticatedDropdownMenu.tsx @@ -0,0 +1,171 @@ +'use client' + +import React, { Fragment } from 'react' +import Link from 'next/link' +import { useTheme } from 'next-themes' +import { Home, LogOut, Menu, Search, Settings, User } from 'lucide-react' +import { + DropdownMenu, + DropdownMenuContent, + DropdownMenuGroup, + DropdownMenuItem, + DropdownMenuLabel, + DropdownMenuRadioGroup, + DropdownMenuRadioItem, + DropdownMenuSeparator, + DropdownMenuShortcut, + DropdownMenuTrigger, + Theme, + buttonVariants, + cn, + themes, +} from 'ui' +import { useSetCommandMenuOpen } from 'ui-patterns/CommandMenu' +import { logOut, useUser } from 'common' +import { LucideIcon } from 'icons/src/createSupabaseIcon' + +const AuthenticatedDropdownMenu = () => { + const { theme, setTheme } = useTheme() + const setCommandMenuOpen = useSetCommandMenuOpen() + const user = useUser() + + interface menuItem { + label: string + type?: 'link' | 'button' | 'text' + icon?: LucideIcon + href?: string + shortcut?: string + onClick?: VoidFunction + otherProps?: { + target?: '_blank' + rel?: 'noreferrer noopener' + } + } + + const menu: menuItem[][] = [ + [ + { + label: user?.email ?? '', + type: 'text', + icon: User, + }, + { + label: 'Projects', + icon: Home, + href: 'https://supabase.com/dashboard/projects', + }, + { + label: 'Account Preferences', + icon: Settings, + href: 'https://supabase.com/dashboard/account/me', + }, + { + label: 'Logout', + type: 'button', + icon: LogOut, + onClick: () => logOut(), + }, + ], + [ + { + label: 'Search', + type: 'button', + icon: Search, + onClick: () => setCommandMenuOpen(true), + shortcut: '⌘K', + }, + ], + ] + + return ( + + + + + + + + {menu.map((menuSection, sectionIdx) => ( + + {sectionIdx !== 0 && } + {menuSection.map(({ icon: Icon, ...sectionItem }, itemIdx) => { + switch (sectionItem.type) { + case 'text': + return ( + + {Icon && } + {sectionItem.label} + {sectionItem.shortcut && ( + {sectionItem.shortcut} + )} + + ) + case 'button': + return ( + + {Icon && } + {sectionItem.label} + {sectionItem.shortcut && ( + {sectionItem.shortcut} + )} + + ) + default: + return ( + + {}}> + {Icon && } + {sectionItem.label} + {sectionItem.shortcut && ( + {sectionItem.shortcut} + )} + + + ) + } + })} + + ))} + + + Theme + { + setTheme(value) + }} + > + {themes + .filter((x) => x.value === 'light' || x.value === 'dark' || x.value === 'system') + .map((theme: Theme) => ( + + {theme.name} + + ))} + + + + + ) +} + +export default AuthenticatedDropdownMenu diff --git a/apps/www/components/Nav/GitHubButton.tsx b/apps/www/components/Nav/GitHubButton.tsx index b59232b4fa6..76cb30f36a7 100644 --- a/apps/www/components/Nav/GitHubButton.tsx +++ b/apps/www/components/Nav/GitHubButton.tsx @@ -29,11 +29,7 @@ const GitHubButton = () => { }, []) return ( - + { const { resolvedTheme } = useTheme() + const [mounted, setMounted] = useState(false) const router = useRouter() const { width } = useWindowSize() const [open, setOpen] = useState(false) - const isLoggedIn = useIsLoggedIn() - const isUserLoading = useIsUserLoading() + const isLoggedIn = + (isBrowser && globalThis?.localStorage?.getItem(STORAGE_KEY)) || useIsLoggedIn() const isHomePage = router.pathname === '/' const isLaunchWeekPage = router.pathname.includes('/launch-week') @@ -56,6 +58,10 @@ const Nav = (props: Props) => { if (width >= 1024) setOpen(false) }, [width]) + React.useEffect(() => { + setMounted(true) + }, []) + if (props.hideNavbar) { return null } @@ -126,31 +132,29 @@ const Nav = (props: Props) => { - + - {!isUserLoading && ( + {isLoggedIn ? ( <> - {isLoggedIn ? ( - <> - - Dashboard - - {/* !Temporary! */} - - Log out - - > - ) : ( - <> - - Sign in - - - Start your project - - > - )} + + Dashboard + + + > + ) : ( + <> + + Sign in + + + Start your project + > )}