manifold/web/components/profile-menu.tsx

102 lines
2.3 KiB
TypeScript
Raw Normal View History

import { firebaseLogout, User } from '../lib/firebase/users'
import { formatMoney } from '../../common/util/format'
2022-01-27 23:24:44 +00:00
import { Avatar } from './avatar'
import { Col } from './layout/col'
import { MenuButton } from './menu'
import { IS_PRIVATE_MANIFOLD } from '../lib/firebase/init'
export function ProfileMenu(props: { user: User | undefined }) {
const { user } = props
return (
<>
<MenuButton
className="hidden md:block"
menuItems={getNavigationOptions(user, { mobile: false })}
buttonContent={<ProfileSummary user={user} />}
/>
<MenuButton
className="mr-2 md:hidden"
menuItems={getNavigationOptions(user, { mobile: true })}
buttonContent={<ProfileSummary user={user} />}
/>
</>
)
}
function getNavigationOptions(
user: User | undefined,
options: { mobile: boolean }
) {
const { mobile } = options
return [
{
name: 'Home',
href: user ? '/home' : '/',
},
...(mobile
? [
{
2022-01-27 07:30:51 +00:00
name: 'Markets',
href: '/markets',
},
2022-01-27 07:30:51 +00:00
{
name: 'Communities',
2022-01-27 07:30:51 +00:00
href: '/folds',
},
]
: []),
2022-02-23 08:24:39 +00:00
{
name: `Your profile`,
href: `/${user?.username}`,
},
{
name: 'Your trades',
href: '/trades',
},
// Disable "Add Funds" for teams
...(IS_PRIVATE_MANIFOLD
? []
: [
{
name: 'Add funds',
href: '/add-funds',
},
]),
{
name: 'Leaderboards',
href: '/leaderboards',
},
2021-12-31 20:33:05 +00:00
{
name: 'Discord',
href: 'https://discord.gg/eHQBNBqXuh',
},
2022-01-12 07:18:14 +00:00
{
name: 'About',
href: '/about',
},
{
name: 'Sign out',
href: '#',
onClick: () => firebaseLogout(),
},
]
}
function ProfileSummary(props: { user: User | undefined }) {
const { user } = props
return (
<Col className="avatar items-center gap-2 sm:flex-row sm:gap-4">
2022-01-27 23:24:44 +00:00
<Avatar avatarUrl={user?.avatarUrl} username={user?.username} noLink />
2022-01-27 23:31:41 +00:00
<div className="truncate text-left sm:w-32">
<div className="hidden sm:flex">{user?.name}</div>
<div className="text-sm text-gray-700">
{user ? formatMoney(Math.floor(user.balance)) : ' '}
2022-01-08 18:14:20 +00:00
</div>
</div>
</Col>
)
}