import { HomeIcon, CakeIcon, SearchIcon, BookOpenIcon, DotsHorizontalIcon, CashIcon, HeartIcon, PresentationChartLineIcon, ChatAltIcon, SparklesIcon, NewspaperIcon, } from '@heroicons/react/outline' import clsx from 'clsx' import { sortBy } from 'lodash' import Link from 'next/link' import { useRouter } from 'next/router' import { useFollowedFolds } from 'web/hooks/use-fold' import { useUser } from 'web/hooks/use-user' import { firebaseLogin, firebaseLogout, User } from 'web/lib/firebase/users' import { ManifoldLogo } from './manifold-logo' import { MenuButton } from './menu' import { ProfileSummary } from './profile-menu' import { getUtcFreeMarketResetTime, useHasCreatedContractToday, } from 'web/hooks/use-has-created-contract-today' import { Row } from '../layout/row' import React, { useEffect, useState } from 'react' import { IS_PRIVATE_MANIFOLD } from 'common/envs/constants' // Create an icon from the url of an image function IconFromUrl(url: string): React.ComponentType<{ className?: string }> { return function Icon(props) { return } } function getNavigation(username: string) { return [ { name: 'Home', href: '/home', icon: HomeIcon }, { name: 'Activity', href: '/activity', icon: ChatAltIcon }, { name: 'Portfolio', href: `/${username}/bets`, icon: PresentationChartLineIcon, }, { name: 'Charity', href: '/charity', icon: HeartIcon }, ] } function getMoreNavigation(user?: User | null) { if (IS_PRIVATE_MANIFOLD) { return [{ name: 'Leaderboards', href: '/leaderboards' }] } if (!user) { return [ { name: 'Leaderboards', href: '/leaderboards' }, { name: 'Discord', href: 'https://discord.gg/eHQBNBqXuh' }, { name: 'Twitter', href: 'https://twitter.com/ManifoldMarkets' }, ] } return [ { name: 'Add funds', href: '/add-funds' }, { name: 'Leaderboards', href: '/leaderboards' }, { name: 'Blog', href: 'https://news.manifold.markets' }, { name: 'Discord', href: 'https://discord.gg/eHQBNBqXuh' }, { name: 'Twitter', href: 'https://twitter.com/ManifoldMarkets' }, { name: 'About', href: 'https://docs.manifold.markets' }, { name: 'Sign out', href: '#', onClick: () => firebaseLogout() }, ] } const signedOutNavigation = [ { name: 'Home', href: '/home', icon: HomeIcon }, { name: 'Explore', href: '/markets', icon: SearchIcon }, { name: 'Charity', href: '/charity', icon: HeartIcon }, { name: 'About', href: 'https://docs.manifold.markets', icon: BookOpenIcon }, ] const signedOutMobileNavigation = [ { name: 'Charity', href: '/charity', icon: HeartIcon }, { name: 'Leaderboards', href: '/leaderboards', icon: CakeIcon }, { name: 'Blog', href: 'https://news.manifold.markets', icon: NewspaperIcon }, { name: 'Discord', href: 'https://discord.gg/eHQBNBqXuh', icon: IconFromUrl('/discord-logo.svg'), }, { name: 'Twitter', href: 'https://twitter.com/ManifoldMarkets', icon: IconFromUrl('/twitter-logo.svg'), }, { name: 'About', href: 'https://docs.manifold.markets', icon: BookOpenIcon }, ] const mobileNavigation = [ { name: 'Add funds', href: '/add-funds', icon: CashIcon }, ...signedOutMobileNavigation, ] export type Item = { name: string href: string icon: React.ComponentType<{ className?: string }> } function SidebarItem(props: { item: Item; currentPage: string }) { const { item, currentPage } = props return ( ) } function MoreButton() { return ( ) } export default function Sidebar(props: { className?: string }) { const { className } = props const router = useRouter() const currentPage = router.pathname const [countdown, setCountdown] = useState('...') useEffect(() => { const nextUtcResetTime = getUtcFreeMarketResetTime(false) const interval = setInterval(() => { const now = new Date().getTime() const timeUntil = nextUtcResetTime - now const hoursUntil = timeUntil / 1000 / 60 / 60 const minutesUntil = Math.floor((hoursUntil * 60) % 60) const secondsUntil = Math.floor((hoursUntil * 60 * 60) % 60) const hoursUntilFloor = Math.floor(hoursUntil) const timeString = minutesUntil < 1 ? `${secondsUntil}s` : hoursUntilFloor < 1 ? `${minutesUntil}m` : `${hoursUntilFloor}h` setCountdown(timeString) }, 1000) return () => clearInterval(interval) }, []) const user = useUser() let folds = useFollowedFolds(user) || [] folds = sortBy(folds, 'followCount').reverse() const mustWaitForFreeMarketStatus = useHasCreatedContractToday(user) const navigationOptions = user === null ? signedOutNavigation : getNavigation(user?.username || 'error') const mobileNavigationOptions = user === null ? signedOutMobileNavigation : mobileNavigation const gradient = 'from-indigo-500 to-blue-500 hover:from-indigo-700 hover:to-blue-700' const buttonStyle = 'border-w-0 mx-auto mt-4 -ml-1 w-full rounded-md bg-gradient-to-r py-2.5 text-base font-semibold text-white shadow-sm lg:-ml-0' return ( ) }