2021-12-20 03:12:12 +00:00
|
|
|
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'
|
2022-01-11 06:16:58 +00:00
|
|
|
import { ManifoldLogo } from './manifold-logo'
|
2021-12-20 03:12:12 +00:00
|
|
|
import { ProfileMenu } from './profile-menu'
|
2022-02-01 01:02:17 +00:00
|
|
|
import {
|
|
|
|
CollectionIcon,
|
|
|
|
HomeIcon,
|
|
|
|
SearchIcon,
|
|
|
|
UserGroupIcon,
|
|
|
|
} from '@heroicons/react/outline'
|
2021-12-20 03:12:12 +00:00
|
|
|
|
|
|
|
export function NavBar(props: {
|
|
|
|
darkBackground?: boolean
|
2021-12-20 04:37:11 +00:00
|
|
|
wide?: boolean
|
2022-01-27 23:06:31 +00:00
|
|
|
assertUser?: 'signed-in' | 'signed-out'
|
2021-12-20 03:12:12 +00:00
|
|
|
className?: string
|
|
|
|
}) {
|
2022-01-27 23:06:31 +00:00
|
|
|
const { darkBackground, wide, assertUser, className } = props
|
2021-12-20 03:12:12 +00:00
|
|
|
|
|
|
|
const user = useUser()
|
|
|
|
|
2021-12-20 04:06:30 +00:00
|
|
|
const hoverClasses =
|
|
|
|
'hover:underline hover:decoration-indigo-400 hover:decoration-2'
|
2021-12-20 03:12:12 +00:00
|
|
|
const themeClasses = clsx(darkBackground && 'text-white', hoverClasses)
|
|
|
|
|
|
|
|
return (
|
2022-02-01 01:02:17 +00:00
|
|
|
<>
|
2022-02-11 18:40:22 +00:00
|
|
|
<nav className={clsx('mb-4 w-full p-4', className)} aria-label="Global">
|
2022-02-01 01:02:17 +00:00
|
|
|
<Row
|
|
|
|
className={clsx(
|
2022-02-11 18:40:22 +00:00
|
|
|
'mx-auto items-center justify-between sm:px-4',
|
2022-02-01 01:02:17 +00:00
|
|
|
wide ? 'max-w-6xl' : 'max-w-4xl'
|
2021-12-20 04:37:11 +00:00
|
|
|
)}
|
2022-02-01 01:02:17 +00:00
|
|
|
>
|
|
|
|
<ManifoldLogo className="my-1" darkBackground={darkBackground} />
|
|
|
|
|
2022-02-11 18:40:22 +00:00
|
|
|
<Row className="ml-6 items-center gap-6 sm:gap-8">
|
2022-02-01 01:02:17 +00:00
|
|
|
{(user || user === null || assertUser) && (
|
|
|
|
<NavOptions
|
|
|
|
user={user}
|
|
|
|
assertUser={assertUser}
|
|
|
|
themeClasses={themeClasses}
|
|
|
|
/>
|
|
|
|
)}
|
|
|
|
</Row>
|
2021-12-20 04:37:11 +00:00
|
|
|
</Row>
|
2022-02-01 01:02:17 +00:00
|
|
|
</nav>
|
|
|
|
{user && <BottomNavBar user={user} />}
|
|
|
|
</>
|
|
|
|
)
|
|
|
|
}
|
|
|
|
|
|
|
|
// From https://codepen.io/chris__sev/pen/QWGvYbL
|
|
|
|
function BottomNavBar(props: { user: User }) {
|
|
|
|
const { user } = props
|
|
|
|
return (
|
2022-02-11 18:40:22 +00:00
|
|
|
<nav className="fixed inset-x-0 bottom-0 z-20 flex justify-between border-t-2 bg-white text-xs text-gray-700 md:hidden">
|
2022-02-01 01:02:17 +00:00
|
|
|
<Link href="/home">
|
|
|
|
<a
|
|
|
|
href="#"
|
2022-02-11 18:40:22 +00:00
|
|
|
className="block w-full py-2 px-3 text-center transition duration-300 hover:bg-indigo-200 hover:text-indigo-700"
|
2022-02-01 01:02:17 +00:00
|
|
|
>
|
2022-02-11 18:40:22 +00:00
|
|
|
<HomeIcon className="my-1 mx-auto h-6 w-6" aria-hidden="true" />
|
2022-02-01 01:02:17 +00:00
|
|
|
{/* Home */}
|
|
|
|
</a>
|
|
|
|
</Link>
|
|
|
|
|
|
|
|
<Link href="/markets">
|
|
|
|
<a
|
|
|
|
href="#"
|
2022-02-11 18:40:22 +00:00
|
|
|
className="block w-full py-2 px-3 text-center hover:bg-indigo-200 hover:text-indigo-700"
|
2022-02-01 01:02:17 +00:00
|
|
|
>
|
2022-02-11 18:40:22 +00:00
|
|
|
<SearchIcon className="my-1 mx-auto h-6 w-6" aria-hidden="true" />
|
2022-02-01 01:02:17 +00:00
|
|
|
{/* Explore */}
|
|
|
|
</a>
|
|
|
|
</Link>
|
|
|
|
|
|
|
|
<Link href="/folds">
|
|
|
|
<a
|
|
|
|
href="#"
|
2022-02-11 18:40:22 +00:00
|
|
|
className="block w-full py-2 px-3 text-center hover:bg-indigo-200 hover:text-indigo-700"
|
2022-02-01 01:02:17 +00:00
|
|
|
>
|
2022-02-11 18:40:22 +00:00
|
|
|
<UserGroupIcon className="my-1 mx-auto h-6 w-6" aria-hidden="true" />
|
2022-02-01 01:02:17 +00:00
|
|
|
{/* Folds */}
|
|
|
|
</a>
|
|
|
|
</Link>
|
|
|
|
|
2022-02-02 18:56:02 +00:00
|
|
|
<Link href="/trades">
|
2022-02-01 01:02:17 +00:00
|
|
|
<a
|
|
|
|
href="#"
|
2022-02-11 18:40:22 +00:00
|
|
|
className="block w-full py-2 px-3 text-center hover:bg-indigo-200 hover:text-indigo-700"
|
2022-02-01 01:02:17 +00:00
|
|
|
>
|
2022-02-11 18:40:22 +00:00
|
|
|
<CollectionIcon className="my-1 mx-auto h-6 w-6" aria-hidden="true" />
|
2022-02-02 18:56:02 +00:00
|
|
|
{/* Your Trades */}
|
2022-02-01 01:02:17 +00:00
|
|
|
</a>
|
|
|
|
</Link>
|
2021-12-20 03:12:12 +00:00
|
|
|
</nav>
|
|
|
|
)
|
|
|
|
}
|
|
|
|
|
2022-01-27 23:06:31 +00:00
|
|
|
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)
|
|
|
|
|
2021-12-20 03:12:12 +00:00
|
|
|
return (
|
|
|
|
<>
|
2022-01-27 23:06:31 +00:00
|
|
|
{showSignedOut && (
|
2022-01-13 22:09:13 +00:00
|
|
|
<Link href="/about">
|
|
|
|
<a
|
|
|
|
className={clsx(
|
2022-02-11 18:40:22 +00:00
|
|
|
'hidden whitespace-nowrap text-base md:block',
|
2022-01-13 22:09:13 +00:00
|
|
|
themeClasses
|
|
|
|
)}
|
|
|
|
>
|
|
|
|
About
|
|
|
|
</a>
|
|
|
|
</Link>
|
|
|
|
)}
|
|
|
|
|
2022-01-27 23:55:23 +00:00
|
|
|
<Link href="/folds">
|
2022-01-21 23:21:46 +00:00
|
|
|
<a
|
|
|
|
className={clsx(
|
2022-02-11 18:40:22 +00:00
|
|
|
'hidden whitespace-nowrap text-base md:block',
|
2022-01-21 23:21:46 +00:00
|
|
|
themeClasses
|
|
|
|
)}
|
|
|
|
>
|
2022-02-01 18:12:55 +00:00
|
|
|
Communities
|
2022-01-21 23:21:46 +00:00
|
|
|
</a>
|
2022-01-27 07:10:28 +00:00
|
|
|
</Link>
|
2022-01-21 23:21:46 +00:00
|
|
|
|
2022-01-27 23:55:23 +00:00
|
|
|
<Link href="/markets">
|
2021-12-20 03:12:12 +00:00
|
|
|
<a
|
|
|
|
className={clsx(
|
2022-02-11 18:40:22 +00:00
|
|
|
'hidden whitespace-nowrap text-base md:block',
|
2021-12-20 03:12:12 +00:00
|
|
|
themeClasses
|
|
|
|
)}
|
|
|
|
>
|
2022-01-27 23:55:23 +00:00
|
|
|
Markets
|
2021-12-20 03:12:12 +00:00
|
|
|
</a>
|
|
|
|
</Link>
|
|
|
|
|
2022-01-27 23:06:31 +00:00
|
|
|
{showSignedOut && (
|
2022-01-13 22:09:13 +00:00
|
|
|
<>
|
2022-01-21 18:33:58 +00:00
|
|
|
<button
|
2022-02-11 18:40:22 +00:00
|
|
|
className="btn btn-sm btn-outline bg-gradient-to-r px-6 text-base font-medium normal-case"
|
2022-01-13 22:09:13 +00:00
|
|
|
onClick={firebaseLogin}
|
|
|
|
>
|
|
|
|
Sign in
|
2022-01-21 18:33:58 +00:00
|
|
|
</button>
|
2022-01-13 22:09:13 +00:00
|
|
|
</>
|
|
|
|
)}
|
2022-01-27 23:06:31 +00:00
|
|
|
{showSignedIn && <ProfileMenu user={user ?? undefined} />}
|
2021-12-20 03:12:12 +00:00
|
|
|
</>
|
|
|
|
)
|
|
|
|
}
|