2022-05-09 13:04:36 +00:00
|
|
|
import { Col } from 'web/components/layout/col'
|
|
|
|
import { Leaderboard } from 'web/components/leaderboard'
|
|
|
|
import { Page } from 'web/components/page'
|
2022-06-22 16:05:54 +00:00
|
|
|
import {
|
|
|
|
getTopCreators,
|
|
|
|
getTopTraders,
|
|
|
|
getTopFollowed,
|
2022-06-24 17:14:20 +00:00
|
|
|
Period,
|
2022-06-22 16:05:54 +00:00
|
|
|
User,
|
|
|
|
} from 'web/lib/firebase/users'
|
2022-05-09 13:04:36 +00:00
|
|
|
import { formatMoney } from 'common/util/format'
|
2022-06-22 20:29:40 +00:00
|
|
|
import { useEffect, useState } from 'react'
|
|
|
|
import { Title } from 'web/components/title'
|
|
|
|
import { Tabs } from 'web/components/layout/tabs'
|
2022-06-15 21:34:34 +00:00
|
|
|
import { useTracking } from 'web/hooks/use-tracking'
|
2022-01-18 03:20:25 +00:00
|
|
|
|
2022-07-19 20:39:15 +00:00
|
|
|
export async function getStaticProps() {
|
|
|
|
const props = await fetchProps()
|
|
|
|
|
|
|
|
return {
|
|
|
|
props,
|
|
|
|
revalidate: 60, // regenerate after a minute
|
|
|
|
}
|
2022-06-22 20:29:40 +00:00
|
|
|
}
|
2022-07-19 20:39:15 +00:00
|
|
|
|
|
|
|
const fetchProps = async () => {
|
|
|
|
const [allTime, monthly, weekly, daily] = await Promise.all([
|
|
|
|
queryLeaderboardUsers('allTime'),
|
|
|
|
queryLeaderboardUsers('monthly'),
|
|
|
|
queryLeaderboardUsers('weekly'),
|
|
|
|
queryLeaderboardUsers('daily'),
|
|
|
|
])
|
|
|
|
const topFollowed = await getTopFollowed()
|
|
|
|
|
|
|
|
return {
|
|
|
|
allTime,
|
|
|
|
monthly,
|
|
|
|
weekly,
|
|
|
|
daily,
|
|
|
|
topFollowed,
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2022-06-24 17:14:20 +00:00
|
|
|
const queryLeaderboardUsers = async (period: Period) => {
|
2022-07-19 20:39:15 +00:00
|
|
|
const [topTraders, topCreators] = await Promise.all([
|
|
|
|
getTopTraders(period),
|
|
|
|
getTopCreators(period),
|
2022-01-18 03:20:25 +00:00
|
|
|
])
|
|
|
|
return {
|
2022-07-19 20:39:15 +00:00
|
|
|
topTraders,
|
|
|
|
topCreators,
|
2022-01-18 03:20:25 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2022-07-19 20:39:15 +00:00
|
|
|
type leaderboard = {
|
2022-01-18 03:20:25 +00:00
|
|
|
topTraders: User[]
|
|
|
|
topCreators: User[]
|
2022-07-19 20:39:15 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
export default function Leaderboards(_props: {
|
|
|
|
allTime: leaderboard
|
|
|
|
monthly: leaderboard
|
|
|
|
weekly: leaderboard
|
|
|
|
daily: leaderboard
|
2022-06-22 16:05:54 +00:00
|
|
|
topFollowed: User[]
|
2022-01-18 03:20:25 +00:00
|
|
|
}) {
|
2022-07-19 20:39:15 +00:00
|
|
|
const [props, setProps] = useState<Parameters<typeof Leaderboards>[0]>(_props)
|
2022-06-22 20:29:40 +00:00
|
|
|
useEffect(() => {
|
2022-07-19 20:39:15 +00:00
|
|
|
fetchProps().then((props) => setProps(props))
|
|
|
|
}, [])
|
|
|
|
|
|
|
|
const { topFollowed } = props
|
2022-06-22 20:29:40 +00:00
|
|
|
|
2022-06-24 17:14:20 +00:00
|
|
|
const LeaderboardWithPeriod = (period: Period) => {
|
2022-07-19 20:39:15 +00:00
|
|
|
const { topTraders, topCreators } = props[period]
|
|
|
|
|
2022-06-22 20:29:40 +00:00
|
|
|
return (
|
|
|
|
<>
|
|
|
|
<Col className="mx-4 items-center gap-10 lg:flex-row">
|
2022-07-19 20:39:15 +00:00
|
|
|
<Leaderboard
|
|
|
|
title="🏅 Top bettors"
|
|
|
|
users={topTraders}
|
|
|
|
columns={[
|
|
|
|
{
|
|
|
|
header: 'Total profit',
|
|
|
|
renderCell: (user) => formatMoney(user.profitCached[period]),
|
|
|
|
},
|
|
|
|
]}
|
|
|
|
/>
|
2022-06-22 20:29:40 +00:00
|
|
|
|
2022-07-19 20:39:15 +00:00
|
|
|
<Leaderboard
|
|
|
|
title="🏅 Top creators"
|
|
|
|
users={topCreators}
|
|
|
|
columns={[
|
|
|
|
{
|
|
|
|
header: 'Total bet',
|
|
|
|
renderCell: (user) =>
|
|
|
|
formatMoney(user.creatorVolumeCached[period]),
|
|
|
|
},
|
|
|
|
]}
|
|
|
|
/>
|
2022-06-22 20:29:40 +00:00
|
|
|
</Col>
|
|
|
|
{period === 'allTime' ? (
|
2022-06-22 20:52:23 +00:00
|
|
|
<Col className="mx-4 my-10 items-center gap-10 lg:mx-0 lg:w-1/2 lg:flex-row">
|
2022-06-22 20:29:40 +00:00
|
|
|
<Leaderboard
|
2022-06-22 21:22:45 +00:00
|
|
|
title="🏅 Top followed"
|
2022-06-22 20:29:40 +00:00
|
|
|
users={topFollowed}
|
|
|
|
columns={[
|
|
|
|
{
|
2022-06-22 21:17:21 +00:00
|
|
|
header: 'Total followers',
|
2022-06-22 20:29:40 +00:00
|
|
|
renderCell: (user) => user.followerCountCached,
|
|
|
|
},
|
|
|
|
]}
|
|
|
|
/>
|
|
|
|
</Col>
|
|
|
|
) : (
|
|
|
|
<></>
|
|
|
|
)}
|
|
|
|
</>
|
|
|
|
)
|
|
|
|
}
|
2022-06-15 21:34:34 +00:00
|
|
|
useTracking('view leaderboards')
|
|
|
|
|
2022-01-18 03:20:25 +00:00
|
|
|
return (
|
2022-06-16 21:43:34 +00:00
|
|
|
<Page>
|
2022-06-22 20:29:40 +00:00
|
|
|
<Title text={'Leaderboards'} className={'hidden md:block'} />
|
|
|
|
<Tabs
|
2022-07-07 21:24:13 +00:00
|
|
|
currentPageForAnalytics={'leaderboards'}
|
2022-07-19 20:39:40 +00:00
|
|
|
defaultIndex={1}
|
2022-06-22 20:29:40 +00:00
|
|
|
tabs={[
|
|
|
|
{
|
|
|
|
title: 'All Time',
|
|
|
|
content: LeaderboardWithPeriod('allTime'),
|
|
|
|
},
|
2022-07-19 20:39:15 +00:00
|
|
|
// TODO: Enable this near the end of July!
|
|
|
|
// {
|
|
|
|
// title: 'Monthly',
|
|
|
|
// content: LeaderboardWithPeriod('monthly'),
|
|
|
|
// },
|
2022-06-22 20:29:40 +00:00
|
|
|
{
|
|
|
|
title: 'Weekly',
|
|
|
|
content: LeaderboardWithPeriod('weekly'),
|
|
|
|
},
|
|
|
|
{
|
|
|
|
title: 'Daily',
|
|
|
|
content: LeaderboardWithPeriod('daily'),
|
|
|
|
},
|
|
|
|
]}
|
|
|
|
/>
|
2022-01-18 03:20:25 +00:00
|
|
|
</Page>
|
|
|
|
)
|
|
|
|
}
|