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,
|
|
|
|
PresentationChartLineIcon,
|
2022-05-18 15:57:22 +00:00
|
|
|
SparklesIcon,
|
2022-06-22 16:35:50 +00:00
|
|
|
UserGroupIcon,
|
|
|
|
ChevronDownIcon,
|
2022-06-17 17:38:47 +00:00
|
|
|
TrendingUpIcon,
|
2022-03-31 05:35:20 +00:00
|
|
|
} from '@heroicons/react/outline'
|
|
|
|
import clsx from 'clsx'
|
|
|
|
import Link from 'next/link'
|
|
|
|
import { useRouter } from 'next/router'
|
2022-05-09 13:04:36 +00:00
|
|
|
import { useUser } from 'web/hooks/use-user'
|
2022-06-22 16:35:50 +00:00
|
|
|
import { firebaseLogout, User } from 'web/lib/firebase/users'
|
2022-03-31 05:35:20 +00:00
|
|
|
import { ManifoldLogo } from './manifold-logo'
|
|
|
|
import { MenuButton } from './menu'
|
2022-05-30 00:33:41 +00:00
|
|
|
import { ProfileSummary } from './profile-menu'
|
2022-05-23 14:43:11 +00:00
|
|
|
import {
|
2022-05-23 21:14:44 +00:00
|
|
|
getUtcFreeMarketResetTime,
|
2022-05-23 14:43:11 +00:00
|
|
|
useHasCreatedContractToday,
|
|
|
|
} from 'web/hooks/use-has-created-contract-today'
|
2022-05-18 15:57:22 +00:00
|
|
|
import { Row } from '../layout/row'
|
2022-06-01 13:11:25 +00:00
|
|
|
import NotificationsIcon from 'web/components/notifications-icon'
|
2022-05-26 21:41:24 +00:00
|
|
|
import React, { useEffect, useState } 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'
|
|
|
|
import { useMemberGroups } from 'web/hooks/use-group'
|
|
|
|
import { groupPath } from 'web/lib/firebase/groups'
|
2022-06-15 21:34:34 +00:00
|
|
|
import { trackCallback, withTracking } from 'web/lib/service/analytics'
|
2022-06-22 16:35:50 +00:00
|
|
|
import { Group } from 'common/group'
|
2022-03-31 05:35:20 +00:00
|
|
|
|
2022-05-18 15:52:12 +00:00
|
|
|
function getNavigation(username: string) {
|
|
|
|
return [
|
|
|
|
{ name: 'Home', href: '/home', icon: HomeIcon },
|
|
|
|
{
|
|
|
|
name: 'Portfolio',
|
2022-06-22 17:51:20 +00:00
|
|
|
href: `/${username}?tab=bets`,
|
2022-05-18 15:52:12 +00:00
|
|
|
icon: PresentationChartLineIcon,
|
|
|
|
},
|
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
|
|
|
|
? []
|
|
|
|
: [{ name: 'Get M$', href: '/add-funds', icon: CashIcon }]),
|
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) {
|
|
|
|
return [{ name: 'Leaderboards', href: '/leaderboards' }]
|
|
|
|
}
|
|
|
|
|
|
|
|
if (!user) {
|
|
|
|
return [
|
|
|
|
{ name: 'Leaderboards', href: '/leaderboards' },
|
2022-06-13 04:34:11 +00:00
|
|
|
{ name: 'Charity', href: '/charity' },
|
2022-06-22 22:34:42 +00:00
|
|
|
{ name: 'Blog', href: 'https://news.manifold.markets' },
|
2022-05-30 00:33:41 +00:00
|
|
|
{ name: 'Discord', href: 'https://discord.gg/eHQBNBqXuh' },
|
|
|
|
{ name: 'Twitter', href: 'https://twitter.com/ManifoldMarkets' },
|
|
|
|
]
|
|
|
|
}
|
|
|
|
|
|
|
|
return [
|
|
|
|
{ name: 'Leaderboards', href: '/leaderboards' },
|
2022-06-13 04:34:11 +00:00
|
|
|
{ name: 'Charity', href: '/charity' },
|
2022-05-30 00:33:41 +00:00
|
|
|
{ name: 'Blog', href: 'https://news.manifold.markets' },
|
|
|
|
{ name: 'Discord', href: 'https://discord.gg/eHQBNBqXuh' },
|
|
|
|
{ name: 'Twitter', href: 'https://twitter.com/ManifoldMarkets' },
|
2022-06-20 23:28:18 +00:00
|
|
|
{ name: 'Statistics', href: '/stats' },
|
2022-06-14 17:02:21 +00:00
|
|
|
{ name: 'About', href: 'https://docs.manifold.markets/$how-to' },
|
2022-06-22 22:34:42 +00:00
|
|
|
{
|
|
|
|
name: 'Sign out',
|
|
|
|
href: '#',
|
|
|
|
onClick: withTracking(firebaseLogout, 'sign out'),
|
|
|
|
},
|
2022-05-30 00:33:41 +00:00
|
|
|
]
|
|
|
|
}
|
|
|
|
|
2022-04-03 20:48:25 +00:00
|
|
|
const signedOutNavigation = [
|
2022-03-31 05:35:20 +00:00
|
|
|
{ name: 'Home', href: '/home', icon: HomeIcon },
|
2022-04-04 04:20:41 +00:00
|
|
|
{ name: 'Explore', href: '/markets', icon: SearchIcon },
|
2022-06-02 20:35:28 +00:00
|
|
|
{ name: 'Charity', href: '/charity', icon: HeartIcon },
|
2022-06-14 17:02:21 +00:00
|
|
|
{
|
|
|
|
name: 'About',
|
|
|
|
href: 'https://docs.manifold.markets/$how-to',
|
|
|
|
icon: BookOpenIcon,
|
|
|
|
},
|
2022-03-31 05:35:20 +00:00
|
|
|
]
|
|
|
|
|
2022-04-04 04:20:41 +00:00
|
|
|
const signedOutMobileNavigation = [
|
2022-04-29 23:35:56 +00:00
|
|
|
{ name: 'Charity', href: '/charity', icon: HeartIcon },
|
2022-06-17 17:38:47 +00:00
|
|
|
{ name: 'Leaderboards', href: '/leaderboards', icon: TrendingUpIcon },
|
2022-06-14 17:02:21 +00:00
|
|
|
{
|
|
|
|
name: 'About',
|
|
|
|
href: 'https://docs.manifold.markets/$how-to',
|
|
|
|
icon: BookOpenIcon,
|
|
|
|
},
|
2022-04-04 04:20:41 +00:00
|
|
|
]
|
|
|
|
|
2022-06-22 16:35:50 +00:00
|
|
|
const signedInMobileNavigation = [
|
2022-06-14 09:08:55 +00:00
|
|
|
...(IS_PRIVATE_MANIFOLD
|
|
|
|
? []
|
|
|
|
: [{ name: 'Get M$', href: '/add-funds', icon: CashIcon }]),
|
2022-04-04 04:20:41 +00:00
|
|
|
...signedOutMobileNavigation,
|
|
|
|
]
|
|
|
|
|
2022-05-18 19:45:08 +00:00
|
|
|
export type Item = {
|
2022-03-31 05:35:20 +00:00
|
|
|
name: string
|
|
|
|
href: string
|
|
|
|
icon: React.ComponentType<{ className?: string }>
|
|
|
|
}
|
|
|
|
|
|
|
|
function SidebarItem(props: { item: Item; currentPage: string }) {
|
|
|
|
const { item, currentPage } = props
|
|
|
|
return (
|
|
|
|
<Link href={item.href} key={item.name}>
|
|
|
|
<a
|
2022-06-15 21:34:34 +00:00
|
|
|
onClick={trackCallback('sidebar: ' + item.name)}
|
2022-03-31 05:35:20 +00:00
|
|
|
className={clsx(
|
|
|
|
item.href == currentPage
|
|
|
|
? '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
|
|
|
|
className={clsx(
|
|
|
|
item.href == currentPage
|
|
|
|
? '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>
|
|
|
|
</Link>
|
|
|
|
)
|
|
|
|
}
|
|
|
|
|
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} />
|
|
|
|
}
|
|
|
|
|
|
|
|
function GroupsButton() {
|
|
|
|
return (
|
|
|
|
<SidebarButton icon={UserGroupIcon} text={'Groups'}>
|
|
|
|
<ChevronDownIcon className=" mt-0.5 ml-2 h-5 w-5" aria-hidden="true" />
|
|
|
|
</SidebarButton>
|
|
|
|
)
|
|
|
|
}
|
|
|
|
|
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-05-23 14:43:11 +00:00
|
|
|
const [countdown, setCountdown] = useState('...')
|
|
|
|
useEffect(() => {
|
2022-06-01 13:54:48 +00:00
|
|
|
const nextUtcResetTime = getUtcFreeMarketResetTime({ previousTime: false })
|
2022-05-23 14:43:11 +00:00
|
|
|
const interval = setInterval(() => {
|
2022-05-24 13:31:44 +00:00
|
|
|
const now = new Date().getTime()
|
2022-05-26 21:41:24 +00:00
|
|
|
const timeUntil = nextUtcResetTime - now
|
2022-05-24 13:31:44 +00:00
|
|
|
const hoursUntil = timeUntil / 1000 / 60 / 60
|
2022-06-10 15:15:55 +00:00
|
|
|
const minutesUntil = (hoursUntil * 60) % 60
|
|
|
|
const secondsUntil = Math.round((hoursUntil * 60 * 60) % 60)
|
2022-05-23 14:43:11 +00:00
|
|
|
const timeString =
|
2022-06-10 15:15:55 +00:00
|
|
|
hoursUntil < 1 && minutesUntil < 1
|
2022-05-23 14:43:11 +00:00
|
|
|
? `${secondsUntil}s`
|
2022-06-10 15:15:55 +00:00
|
|
|
: hoursUntil < 1
|
|
|
|
? `${Math.round(minutesUntil)}m`
|
|
|
|
: `${Math.floor(hoursUntil)}h`
|
2022-05-23 14:43:11 +00:00
|
|
|
setCountdown(timeString)
|
|
|
|
}, 1000)
|
|
|
|
return () => clearInterval(interval)
|
|
|
|
}, [])
|
2022-03-31 05:35:20 +00:00
|
|
|
|
|
|
|
const user = useUser()
|
2022-05-23 14:43:11 +00:00
|
|
|
const mustWaitForFreeMarketStatus = useHasCreatedContractToday(user)
|
2022-06-22 16:35:50 +00:00
|
|
|
const navigationOptions = !user
|
|
|
|
? signedOutNavigation
|
|
|
|
: getNavigation(user?.username || 'error')
|
|
|
|
const mobileNavigationOptions = !user
|
|
|
|
? signedOutMobileNavigation
|
|
|
|
: signedInMobileNavigation
|
|
|
|
const memberItems = (useMemberGroups(user) ?? []).map((group: Group) => ({
|
|
|
|
name: group.name,
|
|
|
|
href: groupPath(group.slug),
|
|
|
|
}))
|
2022-05-23 21:38:31 +00:00
|
|
|
|
2022-03-31 05:35:20 +00:00
|
|
|
return (
|
2022-05-13 23:47:50 +00:00
|
|
|
<nav aria-label="Sidebar" className={className}>
|
2022-05-14 01:07:44 +00:00
|
|
|
<ManifoldLogo className="pb-6" twoLine />
|
2022-05-18 16:06:41 +00:00
|
|
|
{user && (
|
|
|
|
<div className="mb-2" style={{ minHeight: 80 }}>
|
2022-05-14 01:07:44 +00:00
|
|
|
<ProfileSummary user={user} />
|
2022-05-18 16:06:41 +00:00
|
|
|
</div>
|
|
|
|
)}
|
2022-03-31 05:35:20 +00:00
|
|
|
|
2022-06-22 22:34:42 +00:00
|
|
|
{/* Mobile navigation */}
|
2022-04-04 04:20:41 +00:00
|
|
|
<div className="space-y-1 lg:hidden">
|
2022-06-22 16:35:50 +00:00
|
|
|
{user && (
|
|
|
|
<MenuButton
|
|
|
|
buttonContent={<GroupsButton />}
|
|
|
|
menuItems={[{ name: 'Explore', href: '/groups' }, ...memberItems]}
|
|
|
|
className={'relative z-50 flex-shrink-0'}
|
|
|
|
/>
|
|
|
|
)}
|
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
|
|
|
))}
|
2022-06-22 16:35:50 +00:00
|
|
|
{!user && (
|
|
|
|
<SidebarItem
|
|
|
|
key={'Groups'}
|
|
|
|
item={{ name: 'Groups', href: '/groups', icon: UserGroupIcon }}
|
|
|
|
currentPage={currentPage}
|
|
|
|
/>
|
|
|
|
)}
|
2022-04-04 04:20:41 +00:00
|
|
|
|
|
|
|
{user && (
|
|
|
|
<MenuButton
|
|
|
|
menuItems={[
|
2022-06-22 22:34:42 +00:00
|
|
|
{
|
|
|
|
name: 'Blog',
|
|
|
|
href: 'https://news.manifold.markets',
|
|
|
|
},
|
|
|
|
{
|
|
|
|
name: 'Discord',
|
|
|
|
href: 'https://discord.gg/eHQBNBqXuh',
|
|
|
|
},
|
|
|
|
{
|
|
|
|
name: 'Twitter',
|
|
|
|
href: 'https://twitter.com/ManifoldMarkets',
|
|
|
|
},
|
|
|
|
{
|
|
|
|
name: 'Statistics',
|
|
|
|
href: '/stats',
|
|
|
|
},
|
2022-06-15 21:34:34 +00:00
|
|
|
{
|
|
|
|
name: 'Sign out',
|
|
|
|
href: '#',
|
|
|
|
onClick: withTracking(firebaseLogout, 'sign out'),
|
|
|
|
},
|
2022-04-04 04:20:41 +00:00
|
|
|
]}
|
|
|
|
buttonContent={<MoreButton />}
|
|
|
|
/>
|
|
|
|
)}
|
|
|
|
</div>
|
|
|
|
|
2022-06-22 22:34:42 +00:00
|
|
|
{/* Desktop navigation */}
|
2022-04-04 04:20:41 +00:00
|
|
|
<div className="hidden space-y-1 lg:block">
|
2022-06-22 16:35:50 +00:00
|
|
|
{navigationOptions.map((item) =>
|
|
|
|
item.name === 'Notifications' ? (
|
|
|
|
<div key={item.href}>
|
|
|
|
<SidebarItem item={item} currentPage={currentPage} />
|
|
|
|
{user && (
|
|
|
|
<MenuButton
|
|
|
|
key={'groupsdropdown'}
|
|
|
|
buttonContent={<GroupsButton />}
|
|
|
|
menuItems={[
|
|
|
|
{ name: 'Explore', href: '/groups' },
|
|
|
|
...memberItems,
|
|
|
|
]}
|
|
|
|
className={'relative z-50 flex-shrink-0'}
|
|
|
|
/>
|
|
|
|
)}
|
|
|
|
</div>
|
|
|
|
) : (
|
|
|
|
<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 />}
|
|
|
|
/>
|
|
|
|
</div>
|
2022-06-22 16:35:50 +00:00
|
|
|
<CreateQuestionButton user={user} />
|
2022-05-18 15:57:22 +00:00
|
|
|
|
2022-05-23 14:43:11 +00:00
|
|
|
{user &&
|
|
|
|
mustWaitForFreeMarketStatus != 'loading' &&
|
|
|
|
mustWaitForFreeMarketStatus ? (
|
2022-05-18 15:57:22 +00:00
|
|
|
<Row className="mt-2 justify-center">
|
2022-05-23 14:43:11 +00:00
|
|
|
<Row className="gap-1 text-sm text-gray-400">
|
2022-05-24 14:28:09 +00:00
|
|
|
Next free question in {countdown}
|
2022-05-18 15:57:22 +00:00
|
|
|
</Row>
|
|
|
|
</Row>
|
2022-05-23 14:43:11 +00:00
|
|
|
) : (
|
|
|
|
user &&
|
|
|
|
mustWaitForFreeMarketStatus != 'loading' &&
|
|
|
|
!mustWaitForFreeMarketStatus && (
|
|
|
|
<Row className="mt-2 justify-center">
|
|
|
|
<Row className="gap-1 text-sm text-indigo-400">
|
2022-05-24 14:28:09 +00:00
|
|
|
Daily free question
|
2022-05-23 14:43:11 +00:00
|
|
|
<SparklesIcon className="mt-0.5 h-4 w-4" aria-hidden="true" />
|
|
|
|
</Row>
|
|
|
|
</Row>
|
|
|
|
)
|
2022-05-18 15:57:22 +00:00
|
|
|
)}
|
2022-03-31 05:35:20 +00:00
|
|
|
</nav>
|
|
|
|
)
|
|
|
|
}
|