2022-03-31 05:35:20 +00:00
|
|
|
import {
|
|
|
|
HomeIcon,
|
|
|
|
SearchIcon,
|
|
|
|
BookOpenIcon,
|
|
|
|
DotsHorizontalIcon,
|
2022-04-04 04:20:41 +00:00
|
|
|
CashIcon,
|
2022-04-29 23:35:56 +00:00
|
|
|
HeartIcon,
|
2022-06-29 17:33:20 +00:00
|
|
|
ChatIcon,
|
2022-03-31 05:35:20 +00:00
|
|
|
} from '@heroicons/react/outline'
|
|
|
|
import clsx from 'clsx'
|
|
|
|
import Link from 'next/link'
|
2022-07-22 07:03:16 +00:00
|
|
|
import Router, { useRouter } from 'next/router'
|
2022-08-24 17:58:32 +00:00
|
|
|
import { useUser } from 'web/hooks/use-user'
|
2022-07-17 20:17:31 +00:00
|
|
|
import { firebaseLogout, User } from 'web/lib/firebase/users'
|
2022-03-31 05:35:20 +00:00
|
|
|
import { ManifoldLogo } from './manifold-logo'
|
2022-09-16 13:32:15 +00:00
|
|
|
import { MenuButton, MenuItem } from './menu'
|
2022-05-30 00:33:41 +00:00
|
|
|
import { ProfileSummary } from './profile-menu'
|
2022-06-01 13:11:25 +00:00
|
|
|
import NotificationsIcon from 'web/components/notifications-icon'
|
2022-08-26 21:23:06 +00:00
|
|
|
import React from 'react'
|
2022-05-30 00:33:41 +00:00
|
|
|
import { IS_PRIVATE_MANIFOLD } from 'common/envs/constants'
|
2022-06-22 16:35:50 +00:00
|
|
|
import { CreateQuestionButton } from 'web/components/create-question-button'
|
2022-06-15 21:34:34 +00:00
|
|
|
import { trackCallback, withTracking } from 'web/lib/service/analytics'
|
2022-08-04 21:27:02 +00:00
|
|
|
import { CHALLENGES_ENABLED } from 'common/challenge'
|
2022-08-10 17:17:33 +00:00
|
|
|
import { buildArray } from 'common/util/array'
|
2022-08-26 17:45:01 +00:00
|
|
|
import TrophyIcon from 'web/lib/icons/trophy-icon'
|
2022-08-28 20:56:35 +00:00
|
|
|
import { SignInButton } from '../sign-in-button'
|
2022-03-31 05:35:20 +00:00
|
|
|
|
2022-07-22 07:03:16 +00:00
|
|
|
const logout = async () => {
|
|
|
|
// log out, and then reload the page, in case SSR wants to boot them out
|
|
|
|
// of whatever logged-in-only area of the site they might be in
|
|
|
|
await withTracking(firebaseLogout, 'sign out')()
|
|
|
|
await Router.replace(Router.asPath)
|
|
|
|
}
|
|
|
|
|
2022-06-28 16:03:14 +00:00
|
|
|
function getNavigation() {
|
2022-05-18 15:52:12 +00:00
|
|
|
return [
|
|
|
|
{ name: 'Home', href: '/home', icon: HomeIcon },
|
2022-06-01 13:11:25 +00:00
|
|
|
{
|
|
|
|
name: 'Notifications',
|
|
|
|
href: `/notifications`,
|
|
|
|
icon: NotificationsIcon,
|
|
|
|
},
|
2022-06-02 20:35:28 +00:00
|
|
|
|
2022-06-14 09:08:55 +00:00
|
|
|
...(IS_PRIVATE_MANIFOLD
|
|
|
|
? []
|
2022-08-26 17:45:01 +00:00
|
|
|
: [
|
|
|
|
{ name: 'Get M$', href: '/add-funds', icon: CashIcon },
|
|
|
|
{ name: 'Tournaments', href: '/tournaments', icon: TrophyIcon },
|
|
|
|
]),
|
2022-05-18 15:52:12 +00:00
|
|
|
]
|
|
|
|
}
|
2022-04-03 20:48:25 +00:00
|
|
|
|
2022-05-30 00:33:41 +00:00
|
|
|
function getMoreNavigation(user?: User | null) {
|
|
|
|
if (IS_PRIVATE_MANIFOLD) {
|
2022-08-22 05:13:42 +00:00
|
|
|
return [
|
|
|
|
{ name: 'Leaderboards', href: '/leaderboards' },
|
|
|
|
{
|
|
|
|
name: 'Sign out',
|
|
|
|
href: '#',
|
|
|
|
onClick: logout,
|
|
|
|
},
|
|
|
|
]
|
2022-05-30 00:33:41 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
if (!user) {
|
2022-08-29 03:59:14 +00:00
|
|
|
// Signed out "More"
|
2022-08-10 17:17:33 +00:00
|
|
|
return buildArray(
|
2022-08-29 05:00:58 +00:00
|
|
|
{ name: 'Leaderboards', href: '/leaderboards' },
|
|
|
|
{ name: 'Groups', href: '/groups' },
|
2022-08-10 17:17:33 +00:00
|
|
|
CHALLENGES_ENABLED && { name: 'Challenges', href: '/challenges' },
|
|
|
|
[
|
2022-08-26 17:45:01 +00:00
|
|
|
{ name: 'Tournaments', href: '/tournaments' },
|
2022-08-04 21:27:02 +00:00
|
|
|
{ name: 'Charity', href: '/charity' },
|
|
|
|
{ name: 'Blog', href: 'https://news.manifold.markets' },
|
|
|
|
{ name: 'Discord', href: 'https://discord.gg/eHQBNBqXuh' },
|
|
|
|
{ name: 'Twitter', href: 'https://twitter.com/ManifoldMarkets' },
|
|
|
|
]
|
2022-08-10 17:17:33 +00:00
|
|
|
)
|
2022-08-04 21:27:02 +00:00
|
|
|
}
|
|
|
|
|
2022-08-29 03:59:14 +00:00
|
|
|
// Signed in "More"
|
2022-08-10 17:17:33 +00:00
|
|
|
return buildArray(
|
2022-08-29 05:00:58 +00:00
|
|
|
{ name: 'Leaderboards', href: '/leaderboards' },
|
|
|
|
{ name: 'Groups', href: '/groups' },
|
2022-08-10 17:17:33 +00:00
|
|
|
CHALLENGES_ENABLED && { name: 'Challenges', href: '/challenges' },
|
|
|
|
[
|
2022-08-04 21:27:02 +00:00
|
|
|
{ name: 'Referrals', href: '/referrals' },
|
2022-06-13 04:34:11 +00:00
|
|
|
{ name: 'Charity', href: '/charity' },
|
2022-08-04 21:27:02 +00:00
|
|
|
{ name: 'Send M$', href: '/links' },
|
|
|
|
{ name: 'Discord', href: 'https://discord.gg/eHQBNBqXuh' },
|
2022-08-24 21:51:33 +00:00
|
|
|
{ name: 'Help & About', href: 'https://help.manifold.markets/' },
|
2022-08-04 21:27:02 +00:00
|
|
|
{
|
|
|
|
name: 'Sign out',
|
|
|
|
href: '#',
|
|
|
|
onClick: logout,
|
|
|
|
},
|
2022-05-30 00:33:41 +00:00
|
|
|
]
|
2022-08-10 17:17:33 +00:00
|
|
|
)
|
2022-05-30 00:33:41 +00:00
|
|
|
}
|
|
|
|
|
2022-04-03 20:48:25 +00:00
|
|
|
const signedOutNavigation = [
|
2022-08-18 06:15:25 +00:00
|
|
|
{ name: 'Home', href: '/', icon: HomeIcon },
|
|
|
|
{ name: 'Explore', href: '/home', icon: SearchIcon },
|
2022-06-14 17:02:21 +00:00
|
|
|
{
|
2022-08-24 21:51:33 +00:00
|
|
|
name: 'Help & About',
|
|
|
|
href: 'https://help.manifold.markets/',
|
2022-06-14 17:02:21 +00:00
|
|
|
icon: BookOpenIcon,
|
|
|
|
},
|
2022-03-31 05:35:20 +00:00
|
|
|
]
|
|
|
|
|
2022-04-04 04:20:41 +00:00
|
|
|
const signedOutMobileNavigation = [
|
2022-06-14 17:02:21 +00:00
|
|
|
{
|
2022-08-24 21:51:33 +00:00
|
|
|
name: 'Help & About',
|
|
|
|
href: 'https://help.manifold.markets/',
|
2022-06-14 17:02:21 +00:00
|
|
|
icon: BookOpenIcon,
|
|
|
|
},
|
2022-06-29 17:33:20 +00:00
|
|
|
{ name: 'Charity', href: '/charity', icon: HeartIcon },
|
2022-08-26 17:45:01 +00:00
|
|
|
{ name: 'Tournaments', href: '/tournaments', icon: TrophyIcon },
|
2022-06-29 17:33:20 +00:00
|
|
|
{ name: 'Discord', href: 'https://discord.gg/eHQBNBqXuh', icon: ChatIcon },
|
2022-04-04 04:20:41 +00:00
|
|
|
]
|
|
|
|
|
2022-06-22 16:35:50 +00:00
|
|
|
const signedInMobileNavigation = [
|
2022-08-26 17:45:01 +00:00
|
|
|
{ name: 'Tournaments', href: '/tournaments', icon: TrophyIcon },
|
2022-06-14 09:08:55 +00:00
|
|
|
...(IS_PRIVATE_MANIFOLD
|
|
|
|
? []
|
|
|
|
: [{ name: 'Get M$', href: '/add-funds', icon: CashIcon }]),
|
2022-06-29 17:33:20 +00:00
|
|
|
{
|
2022-08-24 21:51:33 +00:00
|
|
|
name: 'Help & About',
|
|
|
|
href: 'https://help.manifold.markets/',
|
2022-06-29 17:33:20 +00:00
|
|
|
icon: BookOpenIcon,
|
|
|
|
},
|
2022-04-04 04:20:41 +00:00
|
|
|
]
|
|
|
|
|
2022-06-28 16:18:55 +00:00
|
|
|
function getMoreMobileNav() {
|
2022-08-10 17:17:33 +00:00
|
|
|
const signOut = {
|
|
|
|
name: 'Sign out',
|
|
|
|
href: '#',
|
|
|
|
onClick: logout,
|
|
|
|
}
|
|
|
|
if (IS_PRIVATE_MANIFOLD) return [signOut]
|
|
|
|
|
2022-09-16 13:32:15 +00:00
|
|
|
return buildArray<MenuItem>(
|
2022-08-10 17:17:33 +00:00
|
|
|
CHALLENGES_ENABLED && { name: 'Challenges', href: '/challenges' },
|
|
|
|
[
|
2022-08-29 03:59:14 +00:00
|
|
|
{ name: 'Groups', href: '/groups' },
|
2022-08-10 17:17:33 +00:00
|
|
|
{ name: 'Referrals', href: '/referrals' },
|
2022-08-26 17:45:01 +00:00
|
|
|
{ name: 'Leaderboards', href: '/leaderboards' },
|
2022-08-10 17:17:33 +00:00
|
|
|
{ name: 'Charity', href: '/charity' },
|
|
|
|
{ name: 'Send M$', href: '/links' },
|
|
|
|
{ name: 'Discord', href: 'https://discord.gg/eHQBNBqXuh' },
|
|
|
|
],
|
|
|
|
signOut
|
|
|
|
)
|
2022-06-28 16:18:55 +00:00
|
|
|
}
|
|
|
|
|
2022-05-18 19:45:08 +00:00
|
|
|
export type Item = {
|
2022-03-31 05:35:20 +00:00
|
|
|
name: string
|
2022-07-04 03:43:18 +00:00
|
|
|
trackingEventName?: string
|
2022-09-16 13:32:15 +00:00
|
|
|
href?: string
|
|
|
|
key?: string
|
2022-06-29 17:33:20 +00:00
|
|
|
icon?: React.ComponentType<{ className?: string }>
|
2022-03-31 05:35:20 +00:00
|
|
|
}
|
|
|
|
|
2022-09-16 13:32:15 +00:00
|
|
|
export function SidebarItem(props: {
|
|
|
|
item: Item
|
|
|
|
currentPage: string
|
|
|
|
onClick?: (key: string) => void
|
|
|
|
}) {
|
|
|
|
const { item, currentPage, onClick } = props
|
|
|
|
const isCurrentPage =
|
|
|
|
item.href != null ? item.href === currentPage : item.key === currentPage
|
|
|
|
|
|
|
|
const sidebarItem = (
|
|
|
|
<a
|
|
|
|
onClick={trackCallback('sidebar: ' + item.name)}
|
|
|
|
className={clsx(
|
|
|
|
isCurrentPage
|
|
|
|
? 'bg-gray-200 text-gray-900'
|
|
|
|
: 'text-gray-600 hover:bg-gray-100',
|
|
|
|
'group flex items-center rounded-md px-3 py-2 text-sm font-medium'
|
|
|
|
)}
|
|
|
|
aria-current={item.href == currentPage ? 'page' : undefined}
|
|
|
|
>
|
|
|
|
{item.icon && (
|
|
|
|
<item.icon
|
|
|
|
className={clsx(
|
|
|
|
isCurrentPage
|
|
|
|
? 'text-gray-500'
|
|
|
|
: 'text-gray-400 group-hover:text-gray-500',
|
|
|
|
'-ml-1 mr-3 h-6 w-6 flex-shrink-0'
|
|
|
|
)}
|
|
|
|
aria-hidden="true"
|
|
|
|
/>
|
|
|
|
)}
|
|
|
|
<span className="truncate">{item.name}</span>
|
|
|
|
</a>
|
2022-03-31 05:35:20 +00:00
|
|
|
)
|
2022-09-16 13:32:15 +00:00
|
|
|
|
|
|
|
if (item.href) {
|
|
|
|
return (
|
|
|
|
<Link href={item.href} key={item.name}>
|
|
|
|
{sidebarItem}
|
|
|
|
</Link>
|
|
|
|
)
|
|
|
|
} else {
|
|
|
|
return onClick ? (
|
|
|
|
<button onClick={() => onClick(item.key ?? '#')}>{sidebarItem}</button>
|
|
|
|
) : (
|
|
|
|
<> </>
|
|
|
|
)
|
|
|
|
}
|
2022-03-31 05:35:20 +00:00
|
|
|
}
|
|
|
|
|
2022-06-22 16:35:50 +00:00
|
|
|
function SidebarButton(props: {
|
|
|
|
text: string
|
|
|
|
icon: React.ComponentType<{ className?: string }>
|
|
|
|
children?: React.ReactNode
|
|
|
|
}) {
|
|
|
|
const { text, children } = props
|
2022-03-31 05:35:20 +00:00
|
|
|
return (
|
|
|
|
<a className="group flex items-center rounded-md px-3 py-2 text-sm font-medium text-gray-600 hover:cursor-pointer hover:bg-gray-100">
|
2022-06-22 16:35:50 +00:00
|
|
|
<props.icon
|
2022-03-31 05:35:20 +00:00
|
|
|
className="-ml-1 mr-3 h-6 w-6 flex-shrink-0 text-gray-400 group-hover:text-gray-500"
|
|
|
|
aria-hidden="true"
|
|
|
|
/>
|
2022-06-22 16:35:50 +00:00
|
|
|
<span className="truncate">{text}</span>
|
|
|
|
{children}
|
2022-03-31 05:35:20 +00:00
|
|
|
</a>
|
|
|
|
)
|
|
|
|
}
|
|
|
|
|
2022-06-22 16:35:50 +00:00
|
|
|
function MoreButton() {
|
|
|
|
return <SidebarButton text={'More'} icon={DotsHorizontalIcon} />
|
|
|
|
}
|
|
|
|
|
2022-05-13 23:47:50 +00:00
|
|
|
export default function Sidebar(props: { className?: string }) {
|
|
|
|
const { className } = props
|
2022-03-31 05:35:20 +00:00
|
|
|
const router = useRouter()
|
|
|
|
const currentPage = router.pathname
|
2022-07-05 23:18:37 +00:00
|
|
|
|
2022-03-31 05:35:20 +00:00
|
|
|
const user = useUser()
|
2022-07-17 20:17:31 +00:00
|
|
|
|
2022-06-28 16:03:14 +00:00
|
|
|
const navigationOptions = !user ? signedOutNavigation : getNavigation()
|
2022-06-22 16:35:50 +00:00
|
|
|
const mobileNavigationOptions = !user
|
|
|
|
? signedOutMobileNavigation
|
|
|
|
: signedInMobileNavigation
|
2022-07-17 20:17:31 +00:00
|
|
|
|
2022-03-31 05:35:20 +00:00
|
|
|
return (
|
2022-08-26 21:23:06 +00:00
|
|
|
<nav
|
|
|
|
aria-label="Sidebar"
|
|
|
|
className={clsx('flex max-h-[100vh] flex-col', className)}
|
|
|
|
>
|
2022-07-11 23:40:25 +00:00
|
|
|
<ManifoldLogo className="py-6" twoLine />
|
2022-06-29 17:33:20 +00:00
|
|
|
|
2022-08-29 05:00:58 +00:00
|
|
|
{!user && <SignInButton className="mb-4" />}
|
2022-08-28 20:56:35 +00:00
|
|
|
|
2022-09-02 19:52:27 +00:00
|
|
|
{user && <ProfileSummary user={user} />}
|
2022-03-31 05:35:20 +00:00
|
|
|
|
2022-06-22 22:34:42 +00:00
|
|
|
{/* Mobile navigation */}
|
2022-08-26 21:23:06 +00:00
|
|
|
<div className="flex min-h-0 shrink flex-col gap-1 lg:hidden">
|
2022-04-04 04:20:41 +00:00
|
|
|
{mobileNavigationOptions.map((item) => (
|
2022-06-22 16:35:50 +00:00
|
|
|
<SidebarItem key={item.href} item={item} currentPage={currentPage} />
|
2022-04-04 04:20:41 +00:00
|
|
|
))}
|
|
|
|
|
|
|
|
{user && (
|
|
|
|
<MenuButton
|
2022-06-28 16:18:55 +00:00
|
|
|
menuItems={getMoreMobileNav()}
|
2022-04-04 04:20:41 +00:00
|
|
|
buttonContent={<MoreButton />}
|
|
|
|
/>
|
|
|
|
)}
|
|
|
|
</div>
|
|
|
|
|
2022-06-22 22:34:42 +00:00
|
|
|
{/* Desktop navigation */}
|
2022-09-02 19:52:27 +00:00
|
|
|
<div className="hidden min-h-0 shrink flex-col items-stretch gap-1 lg:flex ">
|
2022-06-29 17:33:20 +00:00
|
|
|
{navigationOptions.map((item) => (
|
|
|
|
<SidebarItem key={item.href} item={item} currentPage={currentPage} />
|
|
|
|
))}
|
2022-03-31 05:35:20 +00:00
|
|
|
<MenuButton
|
2022-05-30 00:33:41 +00:00
|
|
|
menuItems={getMoreNavigation(user)}
|
2022-03-31 05:35:20 +00:00
|
|
|
buttonContent={<MoreButton />}
|
|
|
|
/>
|
2022-08-29 05:00:58 +00:00
|
|
|
|
2022-09-02 19:52:27 +00:00
|
|
|
{user && !user.isBannedFromPosting && <CreateQuestionButton />}
|
2022-03-31 05:35:20 +00:00
|
|
|
</div>
|
|
|
|
</nav>
|
|
|
|
)
|
|
|
|
}
|