diff --git a/src/components/Navbar.tsx b/src/components/Navbar.tsx index f236d22f0..bcd9ddf03 100644 --- a/src/components/Navbar.tsx +++ b/src/components/Navbar.tsx @@ -1,4 +1,5 @@ import * as React from 'react' +import * as Sentry from '@sentry/tanstackstart-react' import { twMerge } from 'tailwind-merge' const LazyLibrariesMenuContent = React.lazy(() => import('./LibrariesMenuContent').then((module) => ({ @@ -32,6 +33,7 @@ import { ArrowSquareOutIcon } from '@phosphor-icons/react/ArrowSquareOut' import { BriefcaseIcon } from '@phosphor-icons/react/Briefcase' import { ChatCircleIcon } from '@phosphor-icons/react/ChatCircle' import { CodeIcon } from '@phosphor-icons/react/Code' +import { GearIcon } from '@phosphor-icons/react/Gear' import { GridFourIcon } from '@phosphor-icons/react/GridFour' import { HammerIcon } from '@phosphor-icons/react/Hammer' import { HeartIcon } from '@phosphor-icons/react/Heart' @@ -81,6 +83,7 @@ import { } from '~/utils/partner-inquiry' import { fetchRecentPosts, type RecentPost } from '~/utils/blog.functions' import { useCurrentUserQuery } from '~/hooks/useCurrentUser' +import { reloadOnStaleAppError } from '~/utils/stale-app-reload' const LogoSection = () => { const pathname = useLocation({ select: (location) => location.pathname }) @@ -406,6 +409,12 @@ function AiDockMount() { ) } +function handleAuthControlsError(error: unknown) { + if (!reloadOnStaleAppError(error)) { + Sentry.captureException(error) + } +} + export function Navbar({ children }: { children: React.ReactNode }) { const location = useLocation() const isLibrary = Boolean(findLibrary(location.pathname.split('/')[1])) @@ -545,22 +554,28 @@ export function Navbar({ children }: { children: React.ReactNode }) { const userQuery = useCurrentUserQuery() - const getLoginButtonFallback = (className?: string) => ( - - Log In - - - ) + const renderAuthLink = (className?: string, reloadDocument = false) => { + const signedIn = Boolean(userQuery.data) + const label = signedIn ? 'Account' : 'Log In' + const Icon = signedIn ? GearIcon : SignInIcon + return ( + + {label} + + + ) + } const getAuthControlsFallback = (className?: string) => userQuery.data || userQuery.isLoading ? (
) : ( - getLoginButtonFallback(className) + renderAuthLink(className) ) const renderAuthControls = (className?: string) => ( - - - + 'navbar-auth-controls'} + errorComponent={() => renderAuthLink(className, true)} + onCatch={handleAuthControlsError} + > + + + + ) const socialLinks = @@ -900,17 +921,22 @@ function MobileNavigation({ } } - const signIn = ( - - - Sign In - - ) + const renderAuthLink = (signedIn: boolean, reloadDocument = false) => { + const Icon = signedIn ? GearIcon : SignInIcon + return ( + + + {signedIn ? 'Account' : 'Sign In'} + + ) + } + const signIn = renderAuthLink(false) return (