2022-01-15 23:28:32 +00:00
|
|
|
import clsx from 'clsx'
|
2022-06-23 08:07:52 +00:00
|
|
|
import { useEffect, useState } from 'react'
|
2022-09-26 23:01:13 +00:00
|
|
|
import { NextRouter, useRouter } from 'next/router'
|
2022-06-14 02:08:56 +00:00
|
|
|
import { LinkIcon } from '@heroicons/react/solid'
|
2022-09-26 23:01:13 +00:00
|
|
|
import {
|
|
|
|
ChatIcon,
|
|
|
|
FolderIcon,
|
|
|
|
PencilIcon,
|
|
|
|
ScaleIcon,
|
|
|
|
} from '@heroicons/react/outline'
|
2022-06-14 02:08:56 +00:00
|
|
|
|
2022-08-12 03:44:51 +00:00
|
|
|
import { User } from 'web/lib/firebase/users'
|
2022-08-13 03:42:58 +00:00
|
|
|
import { useUser } from 'web/hooks/use-user'
|
2022-08-06 00:46:32 +00:00
|
|
|
import { CreatorContractsList } from './contract/contracts-grid'
|
2021-12-16 21:17:32 +00:00
|
|
|
import { SEO } from './SEO'
|
2021-12-20 04:06:30 +00:00
|
|
|
import { Page } from './page'
|
2021-12-31 19:17:32 +00:00
|
|
|
import { SiteLink } from './site-link'
|
2022-02-18 01:16:58 +00:00
|
|
|
import { Avatar } from './avatar'
|
|
|
|
import { Col } from './layout/col'
|
|
|
|
import { Linkify } from './linkify'
|
|
|
|
import { Spacer } from './layout/spacer'
|
|
|
|
import { Row } from './layout/row'
|
2022-05-09 13:04:36 +00:00
|
|
|
import { genHash } from 'common/util/random'
|
2022-07-25 20:27:09 +00:00
|
|
|
import { QueryUncontrolledTabs } from './layout/tabs'
|
2022-05-05 22:30:30 +00:00
|
|
|
import { UserCommentsList } from './comments-list'
|
2022-08-11 19:55:25 +00:00
|
|
|
import { FullscreenConfetti } from 'web/components/fullscreen-confetti'
|
2022-05-18 15:52:12 +00:00
|
|
|
import { BetsList } from './bets-list'
|
2022-06-08 03:24:18 +00:00
|
|
|
import { FollowersButton, FollowingButton } from './following-button'
|
2022-08-11 19:54:09 +00:00
|
|
|
import { UserFollowButton } from './follow-button'
|
2022-06-29 16:00:43 +00:00
|
|
|
import { GroupsButton } from 'web/components/groups/groups-button'
|
2022-07-03 19:18:12 +00:00
|
|
|
import { PortfolioValueSection } from './portfolio/portfolio-value-section'
|
2022-09-15 15:57:14 +00:00
|
|
|
import { formatMoney } from 'common/util/format'
|
2022-09-14 14:56:05 +00:00
|
|
|
import {
|
|
|
|
BettingStreakModal,
|
|
|
|
hasCompletedStreakToday,
|
|
|
|
} from 'web/components/profile/betting-streak-modal'
|
2022-08-22 05:22:49 +00:00
|
|
|
import { LoansModal } from './profile/loans-modal'
|
2021-12-16 02:11:29 +00:00
|
|
|
|
2022-08-13 03:42:58 +00:00
|
|
|
export function UserPage(props: { user: User }) {
|
|
|
|
const { user } = props
|
2022-06-23 08:07:52 +00:00
|
|
|
const router = useRouter()
|
2022-08-13 03:42:58 +00:00
|
|
|
const currentUser = useUser()
|
2021-12-16 21:17:32 +00:00
|
|
|
const isCurrentUser = user.id === currentUser?.id
|
2022-06-23 08:07:52 +00:00
|
|
|
const [showConfetti, setShowConfetti] = useState(false)
|
|
|
|
|
|
|
|
useEffect(() => {
|
|
|
|
const claimedMana = router.query['claimed-mana'] === 'yes'
|
2022-09-26 23:01:13 +00:00
|
|
|
setShowConfetti(claimedMana)
|
2022-08-19 21:51:52 +00:00
|
|
|
const query = { ...router.query }
|
|
|
|
if (query.claimedMana || query.show) {
|
|
|
|
delete query['claimed-mana']
|
|
|
|
delete query['show']
|
|
|
|
router.replace(
|
|
|
|
{
|
|
|
|
pathname: router.pathname,
|
|
|
|
query,
|
|
|
|
},
|
|
|
|
undefined,
|
|
|
|
{ shallow: true }
|
|
|
|
)
|
|
|
|
}
|
|
|
|
// eslint-disable-next-line react-hooks/exhaustive-deps
|
|
|
|
}, [])
|
2022-05-05 22:30:30 +00:00
|
|
|
|
2022-07-19 21:05:49 +00:00
|
|
|
const profit = user.profitCached.allTime
|
2022-06-03 04:52:14 +00:00
|
|
|
|
2021-12-16 02:11:29 +00:00
|
|
|
return (
|
2022-06-08 20:51:51 +00:00
|
|
|
<Page key={user.id}>
|
2021-12-16 21:17:32 +00:00
|
|
|
<SEO
|
2022-02-18 01:16:58 +00:00
|
|
|
title={`${user.name} (@${user.username})`}
|
2022-03-17 17:03:15 +00:00
|
|
|
description={user.bio ?? ''}
|
2022-02-18 01:16:58 +00:00
|
|
|
url={`/${user.username}`}
|
2021-12-16 21:17:32 +00:00
|
|
|
/>
|
2022-08-19 21:51:52 +00:00
|
|
|
{showConfetti && (
|
|
|
|
<FullscreenConfetti recycle={false} numberOfPieces={300} />
|
|
|
|
)}
|
2022-09-26 23:01:13 +00:00
|
|
|
<Col className="relative">
|
|
|
|
<Row className="relative px-4 pt-4">
|
2022-02-18 01:16:58 +00:00
|
|
|
<Avatar
|
|
|
|
username={user.username}
|
|
|
|
avatarUrl={user.avatarUrl}
|
2022-07-04 14:32:51 +00:00
|
|
|
size={24}
|
2022-09-26 23:01:13 +00:00
|
|
|
className="bg-white shadow-sm shadow-indigo-300"
|
2022-02-18 01:16:58 +00:00
|
|
|
/>
|
|
|
|
{isCurrentUser && (
|
2022-09-28 21:30:00 +00:00
|
|
|
<div className="absolute ml-16 mt-16 rounded-full bg-indigo-600 p-2 text-white shadow-sm shadow-indigo-300">
|
2022-09-26 23:01:13 +00:00
|
|
|
<SiteLink href="/profile">
|
|
|
|
<PencilIcon className="h-5" />{' '}
|
|
|
|
</SiteLink>
|
|
|
|
</div>
|
2022-02-18 01:16:58 +00:00
|
|
|
)}
|
|
|
|
|
2022-09-26 23:01:13 +00:00
|
|
|
<Col className="w-full gap-4 pl-5">
|
|
|
|
<div className="flex flex-col gap-2 sm:flex-row sm:justify-between">
|
|
|
|
<Col>
|
|
|
|
<span className="break-anywhere text-lg font-bold sm:text-2xl">
|
|
|
|
{user.name}
|
2022-08-19 17:10:32 +00:00
|
|
|
</span>
|
2022-09-26 23:01:13 +00:00
|
|
|
<span className="sm:text-md text-greyscale-4 text-sm">
|
|
|
|
@{user.username}
|
2022-08-22 05:22:49 +00:00
|
|
|
</span>
|
|
|
|
</Col>
|
2022-09-26 23:01:13 +00:00
|
|
|
{isCurrentUser && (
|
|
|
|
<ProfilePrivateStats
|
|
|
|
currentUser={currentUser}
|
|
|
|
profit={profit}
|
|
|
|
user={user}
|
|
|
|
router={router}
|
|
|
|
/>
|
|
|
|
)}
|
|
|
|
{!isCurrentUser && <UserFollowButton userId={user.id} />}
|
|
|
|
</div>
|
|
|
|
<ProfilePublicStats
|
|
|
|
className="sm:text-md text-greyscale-6 hidden text-sm md:inline"
|
|
|
|
user={user}
|
|
|
|
/>
|
2022-08-19 17:10:32 +00:00
|
|
|
</Col>
|
2022-08-18 15:54:30 +00:00
|
|
|
</Row>
|
2022-09-26 23:01:13 +00:00
|
|
|
<Col className="mx-4 mt-2">
|
|
|
|
<Spacer h={1} />
|
|
|
|
<ProfilePublicStats
|
|
|
|
className="text-greyscale-6 text-sm md:hidden"
|
|
|
|
user={user}
|
|
|
|
/>
|
|
|
|
<Spacer h={1} />
|
|
|
|
{user.bio && (
|
|
|
|
<>
|
|
|
|
<div className="sm:text-md mt-2 text-sm sm:mt-0">
|
|
|
|
<Linkify text={user.bio}></Linkify>
|
|
|
|
</div>
|
|
|
|
<Spacer h={2} />
|
|
|
|
</>
|
|
|
|
)}
|
|
|
|
{(user.website || user.twitterHandle || user.discordHandle) && (
|
|
|
|
<Row className="mb-2 flex-wrap items-center gap-2 sm:gap-4">
|
|
|
|
{user.website && (
|
|
|
|
<SiteLink
|
|
|
|
href={
|
|
|
|
'https://' +
|
|
|
|
user.website.replace('http://', '').replace('https://', '')
|
|
|
|
}
|
|
|
|
>
|
|
|
|
<Row className="items-center gap-1">
|
|
|
|
<LinkIcon className="h-4 w-4" />
|
|
|
|
<span className="text-greyscale-4 text-sm">
|
|
|
|
{user.website}
|
|
|
|
</span>
|
|
|
|
</Row>
|
|
|
|
</SiteLink>
|
|
|
|
)}
|
2021-12-16 02:11:29 +00:00
|
|
|
|
2022-09-26 23:01:13 +00:00
|
|
|
{user.twitterHandle && (
|
|
|
|
<SiteLink
|
|
|
|
href={`https://twitter.com/${user.twitterHandle
|
|
|
|
.replace('https://www.twitter.com/', '')
|
|
|
|
.replace('https://twitter.com/', '')
|
|
|
|
.replace('www.twitter.com/', '')
|
|
|
|
.replace('twitter.com/', '')}`}
|
|
|
|
>
|
|
|
|
<Row className="items-center gap-1">
|
|
|
|
<img
|
|
|
|
src="/twitter-logo.svg"
|
|
|
|
className="h-4 w-4"
|
|
|
|
alt="Twitter"
|
|
|
|
/>
|
|
|
|
<span className="text-greyscale-4 text-sm">
|
|
|
|
{user.twitterHandle}
|
|
|
|
</span>
|
|
|
|
</Row>
|
|
|
|
</SiteLink>
|
|
|
|
)}
|
2022-02-18 01:16:58 +00:00
|
|
|
|
2022-09-26 23:01:13 +00:00
|
|
|
{user.discordHandle && (
|
|
|
|
<SiteLink href="https://discord.com/invite/eHQBNBqXuh">
|
|
|
|
<Row className="items-center gap-1">
|
|
|
|
<img
|
|
|
|
src="/discord-logo.svg"
|
|
|
|
className="h-4 w-4"
|
|
|
|
alt="Discord"
|
|
|
|
/>
|
|
|
|
<span className="text-greyscale-4 text-sm">
|
|
|
|
{user.discordHandle}
|
|
|
|
</span>
|
2022-09-07 04:24:56 +00:00
|
|
|
</Row>
|
2022-09-26 23:01:13 +00:00
|
|
|
</SiteLink>
|
|
|
|
)}
|
|
|
|
</Row>
|
|
|
|
)}
|
|
|
|
<QueryUncontrolledTabs
|
|
|
|
currentPageForAnalytics={'profile'}
|
|
|
|
labelClassName={'pb-2 pt-1 sm:pt-4 '}
|
|
|
|
tabs={[
|
|
|
|
{
|
2022-09-27 04:46:23 +00:00
|
|
|
title: 'Markets',
|
|
|
|
tabIcon: <ScaleIcon className="h-5" />,
|
2022-09-26 23:01:13 +00:00
|
|
|
content: (
|
|
|
|
<>
|
|
|
|
<Spacer h={4} />
|
2022-09-27 04:46:23 +00:00
|
|
|
<CreatorContractsList user={currentUser} creator={user} />
|
2022-09-26 23:01:13 +00:00
|
|
|
</>
|
|
|
|
),
|
|
|
|
},
|
|
|
|
{
|
2022-09-27 04:46:23 +00:00
|
|
|
title: 'Portfolio',
|
|
|
|
tabIcon: <FolderIcon className="h-5" />,
|
2022-09-26 23:01:13 +00:00
|
|
|
content: (
|
|
|
|
<>
|
|
|
|
<Spacer h={4} />
|
2022-09-27 04:46:23 +00:00
|
|
|
<PortfolioValueSection userId={user.id} />
|
|
|
|
<Spacer h={4} />
|
|
|
|
<BetsList user={user} />
|
2022-09-26 23:01:13 +00:00
|
|
|
</>
|
|
|
|
),
|
|
|
|
},
|
|
|
|
{
|
|
|
|
title: 'Comments',
|
|
|
|
tabIcon: <ChatIcon className="h-5" />,
|
|
|
|
content: (
|
|
|
|
<>
|
|
|
|
<Spacer h={4} />
|
|
|
|
<Col>
|
|
|
|
<UserCommentsList user={user} />
|
|
|
|
</Col>
|
|
|
|
</>
|
|
|
|
),
|
|
|
|
},
|
|
|
|
]}
|
|
|
|
/>
|
|
|
|
</Col>
|
2022-02-18 01:16:58 +00:00
|
|
|
</Col>
|
2021-12-20 04:06:30 +00:00
|
|
|
</Page>
|
2021-12-16 02:11:29 +00:00
|
|
|
)
|
|
|
|
}
|
2022-02-18 01:16:58 +00:00
|
|
|
|
|
|
|
// Assign each user to a random default banner based on the hash of userId
|
|
|
|
// TODO: Consider handling banner uploads using our own storage bucket, like user avatars.
|
|
|
|
export function defaultBannerUrl(userId: string) {
|
|
|
|
const defaultBanner = [
|
|
|
|
'https://images.unsplash.com/photo-1501523460185-2aa5d2a0f981?ixlib=rb-1.2.1&ixid=MnwxMjA3fDB8MHxwaG90by1wYWdlfHx8fGVufDB8fHx8&auto=format&fit=crop&w=2131&q=80',
|
|
|
|
'https://images.unsplash.com/photo-1458682625221-3a45f8a844c7?ixlib=rb-1.2.1&ixid=MnwxMjA3fDB8MHxwaG90by1wYWdlfHx8fGVufDB8fHx8&auto=format&fit=crop&w=1974&q=80',
|
|
|
|
'https://images.unsplash.com/photo-1558517259-165ae4b10f7f?ixlib=rb-1.2.1&ixid=MnwxMjA3fDB8MHxwaG90by1wYWdlfHx8fGVufDB8fHx8&auto=format&fit=crop&w=2080&q=80',
|
|
|
|
'https://images.unsplash.com/photo-1563260797-cb5cd70254c8?ixlib=rb-1.2.1&ixid=MnwxMjA3fDB8MHxwaG90by1wYWdlfHx8fGVufDB8fHx8&auto=format&fit=crop&w=2069&q=80',
|
|
|
|
'https://images.unsplash.com/photo-1603399587513-136aa9398f2d?ixlib=rb-1.2.1&ixid=MnwxMjA3fDB8MHxwaG90by1wYWdlfHx8fGVufDB8fHx8&auto=format&fit=crop&w=1467&q=80',
|
|
|
|
]
|
|
|
|
return defaultBanner[genHash(userId)() % defaultBanner.length]
|
|
|
|
}
|
2022-09-26 23:01:13 +00:00
|
|
|
|
|
|
|
export function ProfilePrivateStats(props: {
|
|
|
|
currentUser: User | null | undefined
|
|
|
|
profit: number
|
|
|
|
user: User
|
|
|
|
router: NextRouter
|
|
|
|
}) {
|
|
|
|
const { currentUser, profit, user, router } = props
|
|
|
|
const [showBettingStreakModal, setShowBettingStreakModal] = useState(false)
|
|
|
|
const [showLoansModal, setShowLoansModal] = useState(false)
|
|
|
|
|
|
|
|
useEffect(() => {
|
|
|
|
const showBettingStreak = router.query['show'] === 'betting-streak'
|
|
|
|
setShowBettingStreakModal(showBettingStreak)
|
|
|
|
|
|
|
|
const showLoansModel = router.query['show'] === 'loans'
|
|
|
|
setShowLoansModal(showLoansModel)
|
|
|
|
// eslint-disable-next-line react-hooks/exhaustive-deps
|
|
|
|
}, [])
|
|
|
|
return (
|
|
|
|
<>
|
|
|
|
<Row className={'justify-between gap-4 sm:justify-end'}>
|
|
|
|
<Col className={'text-greyscale-4 text-md sm:text-lg'}>
|
|
|
|
<span
|
|
|
|
className={clsx(profit >= 0 ? 'text-green-600' : 'text-red-400')}
|
|
|
|
>
|
|
|
|
{formatMoney(profit)}
|
|
|
|
</span>
|
|
|
|
<span className="mx-auto text-xs sm:text-sm">profit</span>
|
|
|
|
</Col>
|
|
|
|
<Col
|
|
|
|
className={clsx('text-,d cursor-pointer sm:text-lg ')}
|
|
|
|
onClick={() => setShowBettingStreakModal(true)}
|
|
|
|
>
|
|
|
|
<span
|
|
|
|
className={clsx(
|
|
|
|
!hasCompletedStreakToday(user)
|
|
|
|
? 'opacity-50 grayscale'
|
|
|
|
: 'grayscale-0'
|
|
|
|
)}
|
|
|
|
>
|
|
|
|
🔥 {user.currentBettingStreak ?? 0}
|
|
|
|
</span>
|
|
|
|
<span className="text-greyscale-4 mx-auto text-xs sm:text-sm">
|
|
|
|
streak
|
|
|
|
</span>
|
|
|
|
</Col>
|
|
|
|
<Col
|
|
|
|
className={
|
|
|
|
'text-greyscale-4 text-md flex-shrink-0 cursor-pointer sm:text-lg'
|
|
|
|
}
|
|
|
|
onClick={() => setShowLoansModal(true)}
|
|
|
|
>
|
|
|
|
<span className="text-green-600">
|
|
|
|
🏦 {formatMoney(user.nextLoanCached ?? 0)}
|
|
|
|
</span>
|
|
|
|
<span className="mx-auto text-xs sm:text-sm">next loan</span>
|
|
|
|
</Col>
|
|
|
|
</Row>
|
|
|
|
{BettingStreakModal && (
|
|
|
|
<BettingStreakModal
|
|
|
|
isOpen={showBettingStreakModal}
|
|
|
|
setOpen={setShowBettingStreakModal}
|
|
|
|
currentUser={currentUser}
|
|
|
|
/>
|
|
|
|
)}
|
|
|
|
{showLoansModal && (
|
|
|
|
<LoansModal isOpen={showLoansModal} setOpen={setShowLoansModal} />
|
|
|
|
)}
|
|
|
|
</>
|
|
|
|
)
|
|
|
|
}
|
|
|
|
|
|
|
|
export function ProfilePublicStats(props: { user: User; className?: string }) {
|
|
|
|
const { user, className } = props
|
|
|
|
return (
|
|
|
|
<Row className={'flex-wrap items-center gap-3'}>
|
|
|
|
<FollowingButton user={user} className={className} />
|
|
|
|
<FollowersButton user={user} className={className} />
|
|
|
|
{/* <ReferralsButton user={user} className={className} /> */}
|
|
|
|
<GroupsButton user={user} className={className} />
|
|
|
|
{/* <UserLikesButton user={user} className={className} /> */}
|
|
|
|
</Row>
|
|
|
|
)
|
|
|
|
}
|