import { HomeIcon, SearchIcon, BookOpenIcon, DotsHorizontalIcon, CashIcon, HeartIcon, UserGroupIcon, ChatIcon, } from '@heroicons/react/outline' import clsx from 'clsx' import Link from 'next/link' import Router, { useRouter } from 'next/router' import { useUser } from 'web/hooks/use-user' import { firebaseLogout, User } from 'web/lib/firebase/users' import { ManifoldLogo } from './manifold-logo' import { MenuButton } from './menu' import { ProfileSummary } from './profile-menu' import NotificationsIcon from 'web/components/notifications-icon' import React from 'react' import { IS_PRIVATE_MANIFOLD } from 'common/envs/constants' import { CreateQuestionButton } from 'web/components/create-question-button' import { useMemberGroups } from 'web/hooks/use-group' import { groupPath } from 'web/lib/firebase/groups' import { trackCallback, withTracking } from 'web/lib/service/analytics' import { Group } from 'common/group' import { Spacer } from '../layout/spacer' import { CHALLENGES_ENABLED } from 'common/challenge' import { buildArray } from 'common/util/array' import TrophyIcon from 'web/lib/icons/trophy-icon' import { SignInButton } from '../sign-in-button' 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) } function getNavigation() { return [ { name: 'Home', href: '/home', icon: HomeIcon }, { name: 'Notifications', href: `/notifications`, icon: NotificationsIcon, }, ...(IS_PRIVATE_MANIFOLD ? [] : [ { name: 'Get M$', href: '/add-funds', icon: CashIcon }, { name: 'Tournaments', href: '/tournaments', icon: TrophyIcon }, ]), ] } function getMoreNavigation(user?: User | null) { if (IS_PRIVATE_MANIFOLD) { return [ { name: 'Leaderboards', href: '/leaderboards' }, { name: 'Sign out', href: '#', onClick: logout, }, ] } if (!user) { return buildArray( CHALLENGES_ENABLED && { name: 'Challenges', href: '/challenges' }, [ { name: 'Leaderboards', href: '/leaderboards' }, { name: 'Tournaments', href: '/tournaments' }, { 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' }, ] ) } return buildArray( CHALLENGES_ENABLED && { name: 'Challenges', href: '/challenges' }, [ { name: 'Referrals', href: '/referrals' }, { name: 'Leaderboards', href: '/leaderboards' }, { name: 'Charity', href: '/charity' }, { name: 'Send M$', href: '/links' }, { name: 'Discord', href: 'https://discord.gg/eHQBNBqXuh' }, { name: 'Help & About', href: 'https://help.manifold.markets/' }, { name: 'Sign out', href: '#', onClick: logout, }, ] ) } const signedOutNavigation = [ { name: 'Home', href: '/', icon: HomeIcon }, { name: 'Explore', href: '/home', icon: SearchIcon }, { name: 'Help & About', href: 'https://help.manifold.markets/', icon: BookOpenIcon, }, ] const signedOutMobileNavigation = [ { name: 'Help & About', href: 'https://help.manifold.markets/', icon: BookOpenIcon, }, { name: 'Charity', href: '/charity', icon: HeartIcon }, { name: 'Tournaments', href: '/tournaments', icon: TrophyIcon }, { name: 'Discord', href: 'https://discord.gg/eHQBNBqXuh', icon: ChatIcon }, ] const signedInMobileNavigation = [ { name: 'Tournaments', href: '/tournaments', icon: TrophyIcon }, ...(IS_PRIVATE_MANIFOLD ? [] : [{ name: 'Get M$', href: '/add-funds', icon: CashIcon }]), { name: 'Help & About', href: 'https://help.manifold.markets/', icon: BookOpenIcon, }, ] function getMoreMobileNav() { const signOut = { name: 'Sign out', href: '#', onClick: logout, } if (IS_PRIVATE_MANIFOLD) return [signOut] return buildArray( CHALLENGES_ENABLED && { name: 'Challenges', href: '/challenges' }, [ { name: 'Referrals', href: '/referrals' }, { name: 'Leaderboards', href: '/leaderboards' }, { name: 'Charity', href: '/charity' }, { name: 'Send M$', href: '/links' }, { name: 'Discord', href: 'https://discord.gg/eHQBNBqXuh' }, ], signOut ) } export type Item = { name: string trackingEventName?: string href: string icon?: React.ComponentType<{ className?: string }> } function SidebarItem(props: { item: Item; currentPage: string }) { const { item, currentPage } = props return ( {item.icon && ( ) } function SidebarButton(props: { text: string icon: React.ComponentType<{ className?: string }> children?: React.ReactNode }) { const { text, children } = props return ( ) } function MoreButton() { return } export default function Sidebar(props: { className?: string }) { const { className } = props const router = useRouter() const currentPage = router.pathname const user = useUser() const navigationOptions = !user ? signedOutNavigation : getNavigation() const mobileNavigationOptions = !user ? signedOutMobileNavigation : signedInMobileNavigation const memberItems = ( useMemberGroups(user?.id, undefined, { by: 'mostRecentContractAddedTime', }) ?? [] ).map((group: Group) => ({ name: group.name, href: `${groupPath(group.slug)}`, })) return ( ) } function GroupsList(props: { currentPage: string; memberItems: Item[] }) { const { currentPage, memberItems } = props // const preferredNotifications = useUnseenPreferredNotifications( // privateUser, // { // customHref: '/group/', // }, // memberItems.length > 0 ? memberItems.length : undefined // ) // const notifIsForThisItem = useMemo( // () => (itemHref: string) => // preferredNotifications.some( // (n) => // !n.isSeen && // (n.isSeenOnHref === itemHref || // n.isSeenOnHref?.replace('/chat', '') === itemHref) // ), // [preferredNotifications] // ) return ( <>
{memberItems.map((item) => ( {item.name} ))}
) }