Load navbar more gracefully: don't show options until user loaded

This commit is contained in:
jahooma 2022-01-13 16:09:13 -06:00
parent fc5fa000b9
commit dcf07fe0a1
2 changed files with 49 additions and 56 deletions

View File

@ -1,4 +1,5 @@
import Link from 'next/link' import Link from 'next/link'
import Image from 'next/image'
import clsx from 'clsx' import clsx from 'clsx'
export function ManifoldLogo(props: { darkBackground?: boolean }) { export function ManifoldLogo(props: { darkBackground?: boolean }) {
@ -7,7 +8,7 @@ export function ManifoldLogo(props: { darkBackground?: boolean }) {
return ( return (
<Link href="/"> <Link href="/">
<a className="flex flex-row gap-4"> <a className="flex flex-row gap-4">
<img <Image
className="hover:rotate-12 transition-all" className="hover:rotate-12 transition-all"
src={darkBackground ? '/logo-white.svg' : '/logo.svg'} src={darkBackground ? '/logo-white.svg' : '/logo.svg'}
width={45} width={45}

View File

@ -11,9 +11,8 @@ export function NavBar(props: {
darkBackground?: boolean darkBackground?: boolean
wide?: boolean wide?: boolean
className?: string className?: string
children?: any
}) { }) {
const { darkBackground, wide, className, children } = props const { darkBackground, wide, className } = props
const user = useUser() const user = useUser()
@ -32,36 +31,8 @@ export function NavBar(props: {
<ManifoldLogo darkBackground={darkBackground} /> <ManifoldLogo darkBackground={darkBackground} />
<Row className="items-center gap-6 sm:gap-8 md:ml-16 lg:ml-40"> <Row className="items-center gap-6 sm:gap-8 md:ml-16 lg:ml-40">
{children} {(user || user === null) && (
<NavOptions user={user} themeClasses={themeClasses} />
{!user && (
<Link href="/about">
<a
className={clsx(
'text-base hidden md:block whitespace-nowrap',
themeClasses
)}
>
About
</a>
</Link>
)}
<Link href="/markets">
<a
className={clsx(
'text-base hidden md:block whitespace-nowrap',
themeClasses
)}
>
All markets
</a>
</Link>
{user ? (
<SignedInHeaders user={user} themeClasses={themeClasses} />
) : (
<SignedOutHeaders themeClasses={themeClasses} />
)} )}
</Row> </Row>
</Row> </Row>
@ -69,41 +40,62 @@ export function NavBar(props: {
) )
} }
function SignedInHeaders(props: { user: User; themeClasses?: string }) { function NavOptions(props: { user: User | null; themeClasses: string }) {
const { user, themeClasses } = props const { user, themeClasses } = props
return ( return (
<> <>
<Link href="/create"> {user === null && (
<Link href="/about">
<a
className={clsx(
'text-base hidden md:block whitespace-nowrap',
themeClasses
)}
>
About
</a>
</Link>
)}
<Link href="/markets">
<a <a
className={clsx( className={clsx(
'text-base hidden md:block whitespace-nowrap', 'text-base hidden md:block whitespace-nowrap',
themeClasses themeClasses
)} )}
> >
Create a market All markets
</a> </a>
</Link> </Link>
<ProfileMenu user={user} /> {user === null ? (
</> <>
) <div
} className={clsx(
'text-base font-medium cursor-pointer whitespace-nowrap',
function SignedOutHeaders(props: { themeClasses?: string }) { themeClasses
const { themeClasses } = props )}
onClick={firebaseLogin}
return ( >
<> Sign in
<div </div>
className={clsx( </>
'text-base font-medium cursor-pointer whitespace-nowrap', ) : (
themeClasses <>
)} <Link href="/create">
onClick={firebaseLogin} <a
> className={clsx(
Sign in 'text-base hidden md:block whitespace-nowrap',
</div> themeClasses
)}
>
Create a market
</a>
</Link>
<ProfileMenu user={user} />
</>
)}
</> </>
) )
} }