manifold/web/components/nav-bar.tsx

109 lines
2.7 KiB
TypeScript
Raw Normal View History

import clsx from 'clsx'
import Link from 'next/link'
import { useUser } from '../hooks/use-user'
import { Row } from './layout/row'
import { firebaseLogin, User } from '../lib/firebase/users'
import { ManifoldLogo } from './manifold-logo'
import { ProfileMenu } from './profile-menu'
export function NavBar(props: {
darkBackground?: boolean
2021-12-20 04:37:11 +00:00
wide?: boolean
assertUser?: 'signed-in' | 'signed-out'
className?: string
}) {
const { darkBackground, wide, assertUser, className } = props
const user = useUser()
const hoverClasses =
'hover:underline hover:decoration-indigo-400 hover:decoration-2'
const themeClasses = clsx(darkBackground && 'text-white', hoverClasses)
return (
2021-12-31 19:31:41 +00:00
<nav className={clsx('w-full p-4 mb-4', className)} aria-label="Global">
2021-12-20 04:37:11 +00:00
<Row
className={clsx(
2021-12-20 05:15:18 +00:00
'justify-between items-center mx-auto sm:px-4',
2022-01-13 20:54:31 +00:00
wide ? 'max-w-6xl' : 'max-w-4xl'
2021-12-20 04:37:11 +00:00
)}
>
2022-01-18 19:16:35 +00:00
<ManifoldLogo className="my-1" darkBackground={darkBackground} />
2022-01-13 23:15:32 +00:00
<Row className="items-center gap-6 sm:gap-8 ml-6">
{(user || user === null || assertUser) && (
<NavOptions
user={user}
assertUser={assertUser}
themeClasses={themeClasses}
/>
2021-12-20 04:37:11 +00:00
)}
</Row>
</Row>
</nav>
)
}
function NavOptions(props: {
user: User | null | undefined
assertUser: 'signed-in' | 'signed-out' | undefined
themeClasses: string
}) {
const { user, assertUser, themeClasses } = props
const showSignedIn = assertUser === 'signed-in' || !!user
const showSignedOut =
!showSignedIn && (assertUser === 'signed-out' || user === null)
return (
<>
{showSignedOut && (
<Link href="/about">
<a
className={clsx(
'text-base hidden md:block whitespace-nowrap',
themeClasses
)}
>
About
</a>
</Link>
)}
2022-01-27 23:55:23 +00:00
<Link href="/folds">
<a
className={clsx(
'text-base hidden md:block whitespace-nowrap',
themeClasses
)}
>
2022-01-27 23:55:23 +00:00
Folds
</a>
2022-01-27 07:10:28 +00:00
</Link>
2022-01-27 23:55:23 +00:00
<Link href="/markets">
<a
className={clsx(
'text-base hidden md:block whitespace-nowrap',
themeClasses
)}
>
2022-01-27 23:55:23 +00:00
Markets
</a>
</Link>
{showSignedOut && (
<>
<button
2022-01-27 00:21:14 +00:00
className="btn btn-sm btn-outline normal-case text-base font-medium px-6 bg-gradient-to-r"
onClick={firebaseLogin}
>
Sign in
</button>
</>
)}
{showSignedIn && <ProfileMenu user={user ?? undefined} />}
</>
)
}