2022-09-17 23:25:53 +00:00
|
|
|
import React from 'react'
|
2022-03-31 05:35:20 +00:00
|
|
|
import {
|
|
|
|
HomeIcon,
|
|
|
|
SearchIcon,
|
|
|
|
BookOpenIcon,
|
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-09-17 23:25:53 +00:00
|
|
|
ChartBarIcon,
|
2022-03-31 05:35:20 +00:00
|
|
|
} from '@heroicons/react/outline'
|
|
|
|
import clsx from 'clsx'
|
2022-07-22 07:03:16 +00:00
|
|
|
import Router, { useRouter } from 'next/router'
|
2022-09-17 23:25:53 +00:00
|
|
|
|
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-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-09-17 23:25:53 +00:00
|
|
|
import { withTracking } from 'web/lib/service/analytics'
|
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-09-17 23:25:53 +00:00
|
|
|
import { SidebarItem } from './sidebar-item'
|
|
|
|
import { MoreButton } from './more-button'
|
2022-09-22 16:12:53 +00:00
|
|
|
import { Row } from '../layout/row'
|
|
|
|
import { Spacer } from '../layout/spacer'
|
2022-09-17 23:25:53 +00:00
|
|
|
|
2022-09-22 16:12:53 +00:00
|
|
|
export default function Sidebar(props: {
|
|
|
|
className?: string
|
|
|
|
logoSubheading?: string
|
|
|
|
}) {
|
|
|
|
const { className, logoSubheading } = props
|
2022-09-17 23:25:53 +00:00
|
|
|
const router = useRouter()
|
|
|
|
const currentPage = router.pathname
|
|
|
|
|
|
|
|
const user = useUser()
|
|
|
|
|
|
|
|
const desktopNavOptions = !user
|
|
|
|
? signedOutDesktopNavigation
|
|
|
|
: getDesktopNavigation()
|
|
|
|
|
|
|
|
const mobileNavOptions = !user
|
|
|
|
? signedOutMobileNavigation
|
|
|
|
: signedInMobileNavigation
|
|
|
|
|
|
|
|
const createMarketButton = user && !user.isBannedFromPosting && (
|
|
|
|
<CreateQuestionButton />
|
|
|
|
)
|
|
|
|
|
|
|
|
return (
|
|
|
|
<nav
|
|
|
|
aria-label="Sidebar"
|
|
|
|
className={clsx('flex max-h-[100vh] flex-col', className)}
|
|
|
|
>
|
2022-09-22 16:12:53 +00:00
|
|
|
<ManifoldLogo className="pt-6" twoLine />
|
|
|
|
{logoSubheading && (
|
|
|
|
<Row className="pl-2 text-2xl text-indigo-700 sm:mt-3">
|
|
|
|
{logoSubheading}
|
|
|
|
</Row>
|
|
|
|
)}
|
|
|
|
<Spacer h={6} />
|
2022-09-17 23:25:53 +00:00
|
|
|
|
|
|
|
{!user && <SignInButton className="mb-4" />}
|
|
|
|
|
|
|
|
{user && <ProfileSummary user={user} />}
|
|
|
|
|
|
|
|
{/* Mobile navigation */}
|
|
|
|
<div className="flex min-h-0 shrink flex-col gap-1 lg:hidden">
|
|
|
|
{mobileNavOptions.map((item) => (
|
|
|
|
<SidebarItem key={item.href} item={item} currentPage={currentPage} />
|
|
|
|
))}
|
|
|
|
|
|
|
|
{user && (
|
|
|
|
<MenuButton
|
|
|
|
menuItems={getMoreMobileNav()}
|
|
|
|
buttonContent={<MoreButton />}
|
|
|
|
/>
|
|
|
|
)}
|
|
|
|
|
|
|
|
{createMarketButton}
|
|
|
|
</div>
|
|
|
|
|
|
|
|
{/* Desktop navigation */}
|
|
|
|
<div className="hidden min-h-0 shrink flex-col items-stretch gap-1 lg:flex ">
|
|
|
|
{desktopNavOptions.map((item) => (
|
|
|
|
<SidebarItem key={item.href} item={item} currentPage={currentPage} />
|
|
|
|
))}
|
|
|
|
<MenuButton
|
|
|
|
menuItems={getMoreDesktopNavigation(user)}
|
|
|
|
buttonContent={<MoreButton />}
|
|
|
|
/>
|
|
|
|
|
|
|
|
{createMarketButton}
|
|
|
|
</div>
|
|
|
|
</nav>
|
|
|
|
)
|
|
|
|
}
|
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-09-17 23:25:53 +00:00
|
|
|
function getDesktopNavigation() {
|
2022-05-18 15:52:12 +00:00
|
|
|
return [
|
|
|
|
{ name: 'Home', href: '/home', icon: HomeIcon },
|
2022-09-16 21:46:24 +00:00
|
|
|
{ name: 'Search', href: '/search', icon: SearchIcon },
|
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-09-17 23:25:53 +00:00
|
|
|
function getMoreDesktopNavigation(user?: User | null) {
|
2022-05-30 00:33:41 +00:00
|
|
|
if (IS_PRIVATE_MANIFOLD) {
|
2022-08-22 05:13:42 +00:00
|
|
|
return [
|
2022-09-17 23:25:53 +00:00
|
|
|
{ name: 'Leaderboards', href: '/leaderboards', icon: ChartBarIcon },
|
2022-08-22 05:13:42 +00:00
|
|
|
{
|
|
|
|
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-10-02 19:49:08 +00:00
|
|
|
{ name: 'Tournaments', href: '/tournaments' },
|
|
|
|
{ name: 'Charity', href: '/charity' },
|
|
|
|
{ name: 'Labs', href: '/labs' },
|
|
|
|
{ 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-09-18 00:15:26 +00:00
|
|
|
{ name: 'Leaderboards', href: '/leaderboards' },
|
2022-08-29 05:00:58 +00:00
|
|
|
{ name: 'Groups', href: '/groups' },
|
2022-10-02 19:49:08 +00:00
|
|
|
{ name: 'Referrals', href: '/referrals' },
|
|
|
|
{ name: 'Charity', href: '/charity' },
|
|
|
|
{ name: 'Labs', href: '/labs' },
|
|
|
|
{ name: 'Discord', href: 'https://discord.gg/eHQBNBqXuh' },
|
|
|
|
{ name: 'Help & About', href: 'https://help.manifold.markets/' },
|
|
|
|
{
|
|
|
|
name: 'Sign out',
|
|
|
|
href: '#',
|
|
|
|
onClick: logout,
|
|
|
|
}
|
2022-08-10 17:17:33 +00:00
|
|
|
)
|
2022-05-30 00:33:41 +00:00
|
|
|
}
|
|
|
|
|
2022-09-17 23:25:53 +00:00
|
|
|
const signedOutDesktopNavigation = [
|
2022-08-18 06:15:25 +00:00
|
|
|
{ name: 'Home', href: '/', icon: HomeIcon },
|
2022-09-16 21:46:24 +00:00
|
|
|
{ name: 'Explore', href: '/search', 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-09-17 23:25:53 +00:00
|
|
|
{ name: 'Leaderboards', href: '/leaderboards', icon: ChartBarIcon },
|
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-09-17 23:25:53 +00:00
|
|
|
{ name: 'Search', href: '/search', icon: SearchIcon },
|
2022-08-26 17:45:01 +00:00
|
|
|
{ name: 'Tournaments', href: '/tournaments', icon: TrophyIcon },
|
2022-09-17 23:25:53 +00:00
|
|
|
{ name: 'Leaderboards', href: '/leaderboards', icon: ChartBarIcon },
|
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-10-02 19:49:08 +00:00
|
|
|
{ name: 'Groups', href: '/groups' },
|
|
|
|
{ name: 'Referrals', href: '/referrals' },
|
|
|
|
{ name: 'Charity', href: '/charity' },
|
|
|
|
{ name: 'Labs', href: '/labs' },
|
|
|
|
{ name: 'Discord', href: 'https://discord.gg/eHQBNBqXuh' },
|
2022-08-10 17:17:33 +00:00
|
|
|
signOut
|
|
|
|
)
|
2022-06-28 16:18:55 +00:00
|
|
|
}
|