2021-12-10 22:56:26 +00:00
|
|
|
import clsx from 'clsx'
|
2021-12-08 16:30:29 +00:00
|
|
|
import Link from 'next/link'
|
2021-12-18 01:13:12 +00:00
|
|
|
import Image from 'next/image'
|
2021-12-11 00:19:35 +00:00
|
|
|
|
2021-12-09 23:37:26 +00:00
|
|
|
import { useUser } from '../hooks/use-user'
|
2021-12-17 23:40:17 +00:00
|
|
|
import { formatMoney } from '../lib/util/format'
|
|
|
|
import { Row } from './layout/row'
|
2021-12-18 01:29:09 +00:00
|
|
|
import { firebaseLogin, User } from '../lib/firebase/users'
|
2021-12-18 06:37:05 +00:00
|
|
|
import { MenuButton } from './menu'
|
2021-12-08 16:30:29 +00:00
|
|
|
|
2021-12-16 09:53:19 +00:00
|
|
|
const hoverClasses =
|
|
|
|
'hover:underline hover:decoration-indigo-400 hover:decoration-2'
|
|
|
|
|
2021-12-18 06:37:05 +00:00
|
|
|
const mobileNavigation = [
|
|
|
|
{
|
|
|
|
name: 'Home',
|
|
|
|
href: '/',
|
|
|
|
},
|
|
|
|
{
|
|
|
|
name: 'Account',
|
|
|
|
href: '/account',
|
|
|
|
},
|
|
|
|
{
|
|
|
|
name: 'Your bets',
|
|
|
|
href: '/bets',
|
|
|
|
},
|
|
|
|
{
|
|
|
|
name: 'Create a market',
|
|
|
|
href: '/create',
|
|
|
|
},
|
|
|
|
]
|
|
|
|
|
|
|
|
function ProfileSummary(props: { user: User }) {
|
|
|
|
const { user } = props
|
|
|
|
return (
|
|
|
|
<Row className="avatar items-center">
|
|
|
|
<div className="rounded-full w-10 h-10 mr-4">
|
|
|
|
<Image src={user.avatarUrl} width={40} height={40} />
|
|
|
|
</div>
|
|
|
|
<div className="truncate" style={{ maxWidth: 175 }}>
|
|
|
|
{user.name}
|
|
|
|
<div className="text-gray-700 text-sm">{formatMoney(user.balance)}</div>
|
|
|
|
</div>
|
|
|
|
</Row>
|
|
|
|
)
|
|
|
|
}
|
|
|
|
|
2021-12-17 23:40:17 +00:00
|
|
|
function SignedInHeaders(props: { user: User; themeClasses?: string }) {
|
|
|
|
const { user, themeClasses } = props
|
2021-12-10 22:56:26 +00:00
|
|
|
|
2021-12-17 23:40:17 +00:00
|
|
|
return (
|
|
|
|
<>
|
|
|
|
<Link href="/create">
|
2021-12-18 06:37:05 +00:00
|
|
|
<a
|
|
|
|
className={clsx(
|
|
|
|
'text-base font-medium hidden md:block',
|
|
|
|
themeClasses
|
|
|
|
)}
|
|
|
|
>
|
2021-12-17 23:40:17 +00:00
|
|
|
Create a market
|
|
|
|
</a>
|
|
|
|
</Link>
|
2021-12-09 01:57:59 +00:00
|
|
|
|
2021-12-17 23:40:17 +00:00
|
|
|
<Link href="/bets">
|
2021-12-18 06:37:05 +00:00
|
|
|
<a
|
|
|
|
className={clsx(
|
|
|
|
'text-base font-medium hidden md:block',
|
|
|
|
themeClasses
|
|
|
|
)}
|
|
|
|
>
|
|
|
|
Your bets
|
|
|
|
</a>
|
2021-12-17 23:40:17 +00:00
|
|
|
</Link>
|
|
|
|
|
|
|
|
<Link href="/account">
|
2021-12-18 06:37:05 +00:00
|
|
|
<a className={clsx('text-base font-medium hidden md:block')}>
|
|
|
|
<ProfileSummary user={user} />
|
2021-12-17 23:40:17 +00:00
|
|
|
</a>
|
|
|
|
</Link>
|
2021-12-18 06:37:05 +00:00
|
|
|
|
|
|
|
<MenuButton
|
|
|
|
className="md:hidden"
|
|
|
|
menuItems={mobileNavigation}
|
|
|
|
buttonContent={<ProfileSummary user={user} />}
|
|
|
|
/>
|
2021-12-17 23:40:17 +00:00
|
|
|
</>
|
|
|
|
)
|
|
|
|
}
|
|
|
|
|
|
|
|
function SignedOutHeaders(props: { themeClasses?: string }) {
|
|
|
|
const { themeClasses } = props
|
2021-12-10 22:56:26 +00:00
|
|
|
|
2021-12-09 01:57:59 +00:00
|
|
|
return (
|
|
|
|
<>
|
2021-12-18 01:29:09 +00:00
|
|
|
<div
|
|
|
|
className={clsx('text-base font-medium cursor-pointer', themeClasses)}
|
|
|
|
onClick={firebaseLogin}
|
|
|
|
>
|
|
|
|
Sign in
|
|
|
|
</div>
|
2021-12-09 01:57:59 +00:00
|
|
|
</>
|
|
|
|
)
|
|
|
|
}
|
|
|
|
|
2021-12-17 07:21:40 +00:00
|
|
|
export function Header(props: { darkBackground?: boolean; children?: any }) {
|
|
|
|
const { darkBackground, children } = props
|
2021-12-10 22:56:26 +00:00
|
|
|
|
2021-12-17 23:40:17 +00:00
|
|
|
const user = useUser()
|
|
|
|
|
|
|
|
const themeClasses = clsx(darkBackground && 'text-white', hoverClasses)
|
|
|
|
|
2021-12-08 16:30:29 +00:00
|
|
|
return (
|
2021-12-17 23:40:17 +00:00
|
|
|
<nav
|
2021-12-18 06:37:05 +00:00
|
|
|
className="max-w-7xl w-full flex flex-row justify-between md:justify-start mx-auto pt-5 px-4 sm:px-6"
|
2021-12-17 23:40:17 +00:00
|
|
|
aria-label="Global"
|
|
|
|
>
|
|
|
|
<Link href="/">
|
|
|
|
<a className="flex flex-row gap-3">
|
2021-12-18 06:37:05 +00:00
|
|
|
<img
|
2021-12-18 00:28:40 +00:00
|
|
|
className="sm:h-10 sm:w-10 hover:rotate-12 transition-all"
|
2021-12-17 23:40:17 +00:00
|
|
|
src="/logo-icon.svg"
|
|
|
|
width={40}
|
|
|
|
height={40}
|
|
|
|
/>
|
|
|
|
<div
|
|
|
|
className={clsx(
|
2021-12-18 06:37:05 +00:00
|
|
|
'font-major-mono lowercase mt-1 sm:text-2xl',
|
2021-12-17 23:40:17 +00:00
|
|
|
darkBackground && 'text-white'
|
|
|
|
)}
|
|
|
|
>
|
|
|
|
Mantic Markets
|
2021-12-17 04:12:33 +00:00
|
|
|
</div>
|
2021-12-17 23:40:17 +00:00
|
|
|
</a>
|
|
|
|
</Link>
|
2021-12-17 04:12:33 +00:00
|
|
|
|
2021-12-18 06:37:05 +00:00
|
|
|
<Row className="gap-8 mt-1 md:ml-16">
|
2021-12-17 23:40:17 +00:00
|
|
|
{children}
|
2021-12-17 07:21:40 +00:00
|
|
|
|
2021-12-17 23:40:17 +00:00
|
|
|
{user ? (
|
|
|
|
<SignedInHeaders user={user} themeClasses={themeClasses} />
|
|
|
|
) : (
|
|
|
|
<SignedOutHeaders themeClasses={themeClasses} />
|
|
|
|
)}
|
|
|
|
</Row>
|
|
|
|
</nav>
|
2021-12-08 16:30:29 +00:00
|
|
|
)
|
|
|
|
}
|