2022-06-22 16:35:50 +00:00
|
|
|
import { take, sortBy, debounce } from 'lodash'
|
|
|
|
|
|
|
|
import { Group } from 'common/group'
|
|
|
|
import { Page } from 'web/components/page'
|
|
|
|
import { Title } from 'web/components/title'
|
|
|
|
import { listAllBets } from 'web/lib/firebase/bets'
|
2022-07-01 22:37:30 +00:00
|
|
|
import { Contract } from 'web/lib/firebase/contracts'
|
2022-06-22 16:35:50 +00:00
|
|
|
import {
|
|
|
|
groupPath,
|
|
|
|
getGroupBySlug,
|
|
|
|
getGroupContracts,
|
|
|
|
updateGroup,
|
2022-07-01 22:37:30 +00:00
|
|
|
addContractToGroup,
|
|
|
|
addUserToGroup,
|
2022-06-22 16:35:50 +00:00
|
|
|
} from 'web/lib/firebase/groups'
|
|
|
|
import { Row } from 'web/components/layout/row'
|
|
|
|
import { UserLink } from 'web/components/user-page'
|
2022-07-01 13:47:19 +00:00
|
|
|
import {
|
|
|
|
firebaseLogin,
|
|
|
|
getUser,
|
|
|
|
User,
|
|
|
|
writeReferralInfo,
|
|
|
|
} from 'web/lib/firebase/users'
|
2022-06-22 16:35:50 +00:00
|
|
|
import { Spacer } from 'web/components/layout/spacer'
|
|
|
|
import { Col } from 'web/components/layout/col'
|
|
|
|
import { useUser } from 'web/hooks/use-user'
|
2022-06-24 23:38:39 +00:00
|
|
|
import { listMembers, useGroup, useMembers } from 'web/hooks/use-group'
|
2022-06-22 16:35:50 +00:00
|
|
|
import { useRouter } from 'next/router'
|
|
|
|
import { scoreCreators, scoreTraders } from 'common/scoring'
|
|
|
|
import { Leaderboard } from 'web/components/leaderboard'
|
|
|
|
import { formatMoney } from 'common/util/format'
|
|
|
|
import { EditGroupButton } from 'web/components/groups/edit-group-button'
|
|
|
|
import Custom404 from '../../404'
|
|
|
|
import { SEO } from 'web/components/SEO'
|
|
|
|
import { Linkify } from 'web/components/linkify'
|
|
|
|
import { fromPropz, usePropz } from 'web/hooks/use-propz'
|
|
|
|
import { Tabs } from 'web/components/layout/tabs'
|
|
|
|
import { ContractsGrid } from 'web/components/contract/contracts-list'
|
|
|
|
import { CreateQuestionButton } from 'web/components/create-question-button'
|
|
|
|
import React, { useEffect, useState } from 'react'
|
2022-06-24 17:16:37 +00:00
|
|
|
import { GroupChat } from 'web/components/groups/group-chat'
|
2022-06-22 16:35:50 +00:00
|
|
|
import { LoadingIndicator } from 'web/components/loading-indicator'
|
|
|
|
import { Modal } from 'web/components/layout/modal'
|
|
|
|
import { checkAgainstQuery } from 'web/hooks/use-sort-and-query-params'
|
|
|
|
import { ChoicesToggleGroup } from 'web/components/choices-toggle-group'
|
|
|
|
import { toast } from 'react-hot-toast'
|
2022-06-24 17:16:37 +00:00
|
|
|
import { useCommentsOnGroup } from 'web/hooks/use-comments'
|
2022-06-24 23:38:39 +00:00
|
|
|
import ShortToggle from 'web/components/widgets/short-toggle'
|
2022-07-01 13:47:19 +00:00
|
|
|
import { ShareIconButton } from 'web/components/share-icon-button'
|
|
|
|
import { REFERRAL_AMOUNT } from 'common/user'
|
|
|
|
import { SiteLink } from 'web/components/site-link'
|
2022-07-01 22:37:30 +00:00
|
|
|
import { ContractSearch } from 'web/components/contract-search'
|
2022-06-22 16:35:50 +00:00
|
|
|
|
|
|
|
export const getStaticProps = fromPropz(getStaticPropz)
|
|
|
|
export async function getStaticPropz(props: { params: { slugs: string[] } }) {
|
|
|
|
const { slugs } = props.params
|
|
|
|
|
|
|
|
const group = await getGroupBySlug(slugs[0])
|
2022-06-24 23:38:39 +00:00
|
|
|
const members = group ? await listMembers(group) : []
|
2022-06-22 16:35:50 +00:00
|
|
|
const creatorPromise = group ? getUser(group.creatorId) : null
|
|
|
|
|
|
|
|
const contracts = group ? await getGroupContracts(group).catch((_) => []) : []
|
|
|
|
|
|
|
|
const bets = await Promise.all(
|
|
|
|
contracts.map((contract: Contract) => listAllBets(contract.id))
|
|
|
|
)
|
|
|
|
|
|
|
|
const creatorScores = scoreCreators(contracts)
|
|
|
|
const traderScores = scoreTraders(contracts, bets)
|
|
|
|
const [topCreators, topTraders] = await Promise.all([
|
|
|
|
toTopUsers(creatorScores),
|
|
|
|
toTopUsers(traderScores),
|
|
|
|
])
|
|
|
|
|
|
|
|
const creator = await creatorPromise
|
|
|
|
|
|
|
|
return {
|
|
|
|
props: {
|
|
|
|
group,
|
2022-06-24 23:38:39 +00:00
|
|
|
members,
|
2022-06-22 16:35:50 +00:00
|
|
|
creator,
|
|
|
|
traderScores,
|
|
|
|
topTraders,
|
|
|
|
creatorScores,
|
|
|
|
topCreators,
|
|
|
|
},
|
|
|
|
|
|
|
|
revalidate: 60, // regenerate after a minute
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
async function toTopUsers(userScores: { [userId: string]: number }) {
|
|
|
|
const topUserPairs = take(
|
|
|
|
sortBy(Object.entries(userScores), ([_, score]) => -1 * score),
|
|
|
|
10
|
|
|
|
).filter(([_, score]) => score >= 0.5)
|
|
|
|
|
|
|
|
const topUsers = await Promise.all(
|
|
|
|
topUserPairs.map(([userId]) => getUser(userId))
|
|
|
|
)
|
|
|
|
return topUsers.filter((user) => user)
|
|
|
|
}
|
|
|
|
|
|
|
|
export async function getStaticPaths() {
|
|
|
|
return { paths: [], fallback: 'blocking' }
|
|
|
|
}
|
2022-06-24 23:41:02 +00:00
|
|
|
const groupSubpages = [undefined, 'chat', 'questions', 'about'] as const
|
2022-06-22 16:35:50 +00:00
|
|
|
|
|
|
|
export default function GroupPage(props: {
|
|
|
|
group: Group | null
|
2022-06-24 23:38:39 +00:00
|
|
|
members: User[]
|
2022-06-22 16:35:50 +00:00
|
|
|
creator: User
|
|
|
|
traderScores: { [userId: string]: number }
|
|
|
|
topTraders: User[]
|
|
|
|
creatorScores: { [userId: string]: number }
|
|
|
|
topCreators: User[]
|
|
|
|
}) {
|
|
|
|
props = usePropz(props, getStaticPropz) ?? {
|
|
|
|
group: null,
|
2022-06-24 23:38:39 +00:00
|
|
|
members: [],
|
2022-06-22 16:35:50 +00:00
|
|
|
creator: null,
|
|
|
|
traderScores: {},
|
|
|
|
topTraders: [],
|
|
|
|
creatorScores: {},
|
|
|
|
topCreators: [],
|
|
|
|
}
|
2022-06-24 23:38:39 +00:00
|
|
|
const {
|
|
|
|
creator,
|
|
|
|
members,
|
|
|
|
traderScores,
|
|
|
|
topTraders,
|
|
|
|
creatorScores,
|
|
|
|
topCreators,
|
|
|
|
} = props
|
2022-06-22 16:35:50 +00:00
|
|
|
|
|
|
|
const router = useRouter()
|
|
|
|
const { slugs } = router.query as { slugs: string[] }
|
2022-06-24 17:16:37 +00:00
|
|
|
const page = (slugs?.[1] ?? 'chat') as typeof groupSubpages[number]
|
2022-06-22 16:35:50 +00:00
|
|
|
|
|
|
|
const group = useGroup(props.group?.id) ?? props.group
|
|
|
|
const [contracts, setContracts] = useState<Contract[] | undefined>(undefined)
|
2022-06-24 17:32:59 +00:00
|
|
|
const [query, setQuery] = useState('')
|
|
|
|
|
2022-06-24 17:16:37 +00:00
|
|
|
const messages = useCommentsOnGroup(group?.id)
|
2022-06-24 17:32:59 +00:00
|
|
|
const debouncedQuery = debounce(setQuery, 50)
|
|
|
|
const filteredContracts =
|
|
|
|
query != '' && contracts
|
|
|
|
? contracts.filter(
|
|
|
|
(c) =>
|
|
|
|
checkAgainstQuery(query, c.question) ||
|
|
|
|
checkAgainstQuery(query, c.description || '') ||
|
|
|
|
checkAgainstQuery(query, c.creatorName) ||
|
|
|
|
checkAgainstQuery(query, c.creatorUsername)
|
|
|
|
)
|
|
|
|
: []
|
2022-06-22 16:35:50 +00:00
|
|
|
|
|
|
|
useEffect(() => {
|
|
|
|
if (group)
|
|
|
|
getGroupContracts(group).then((contracts) => setContracts(contracts))
|
|
|
|
}, [group])
|
|
|
|
|
|
|
|
const user = useUser()
|
2022-07-01 13:47:19 +00:00
|
|
|
useEffect(() => {
|
|
|
|
const { referrer } = router.query as {
|
|
|
|
referrer?: string
|
|
|
|
}
|
|
|
|
if (!user && router.isReady)
|
|
|
|
writeReferralInfo(creator.username, undefined, referrer, group?.slug)
|
|
|
|
}, [user, creator, group, router])
|
|
|
|
|
2022-06-22 16:35:50 +00:00
|
|
|
if (group === null || !groupSubpages.includes(page) || slugs[2]) {
|
|
|
|
return <Custom404 />
|
|
|
|
}
|
|
|
|
const { memberIds } = group
|
|
|
|
const isCreator = user && group && user.id === group.creatorId
|
|
|
|
const isMember = user && memberIds.includes(user.id)
|
|
|
|
|
|
|
|
const rightSidebar = (
|
|
|
|
<Col className="mt-6 hidden xl:block">
|
2022-06-24 21:02:05 +00:00
|
|
|
<JoinOrCreateButton group={group} user={user} isMember={!!isMember} />
|
|
|
|
<Spacer h={6} />
|
2022-06-22 16:35:50 +00:00
|
|
|
{contracts && (
|
|
|
|
<div className={'mt-2'}>
|
2022-06-24 21:02:05 +00:00
|
|
|
<div className={'my-2 text-gray-500'}>Recent Questions</div>
|
2022-06-22 16:35:50 +00:00
|
|
|
<ContractsGrid
|
|
|
|
contracts={contracts
|
|
|
|
.sort((a, b) => b.createdTime - a.createdTime)
|
|
|
|
.slice(0, 3)}
|
|
|
|
hasMore={false}
|
|
|
|
loadMore={() => {}}
|
|
|
|
overrideGridClassName={'grid w-full grid-cols-1 gap-4'}
|
|
|
|
/>
|
|
|
|
</div>
|
|
|
|
)}
|
|
|
|
</Col>
|
|
|
|
)
|
|
|
|
|
2022-06-24 23:41:02 +00:00
|
|
|
const aboutTab = (
|
2022-06-24 21:02:05 +00:00
|
|
|
<Col>
|
|
|
|
<GroupOverview
|
|
|
|
group={group}
|
|
|
|
creator={creator}
|
|
|
|
isCreator={!!isCreator}
|
2022-06-22 16:35:50 +00:00
|
|
|
user={user}
|
|
|
|
/>
|
2022-06-24 21:02:05 +00:00
|
|
|
<Spacer h={8} />
|
2022-06-24 23:38:39 +00:00
|
|
|
|
|
|
|
<GroupLeaderboards
|
|
|
|
traderScores={traderScores}
|
|
|
|
creatorScores={creatorScores}
|
|
|
|
topTraders={topTraders}
|
|
|
|
topCreators={topCreators}
|
|
|
|
members={members}
|
|
|
|
user={user}
|
|
|
|
/>
|
2022-06-22 16:35:50 +00:00
|
|
|
</Col>
|
|
|
|
)
|
|
|
|
return (
|
|
|
|
<Page rightSidebar={rightSidebar}>
|
|
|
|
<SEO
|
|
|
|
title={group.name}
|
|
|
|
description={`Created by ${creator.name}. ${group.about}`}
|
|
|
|
url={groupPath(group.slug)}
|
|
|
|
/>
|
|
|
|
|
2022-06-24 21:02:05 +00:00
|
|
|
<Col className="px-3 lg:px-1">
|
|
|
|
<Row className={'items-center justify-between gap-4'}>
|
2022-06-22 16:35:50 +00:00
|
|
|
<div className={'mb-1'}>
|
|
|
|
<Title className={'line-clamp-2'} text={group.name} />
|
2022-06-24 21:02:05 +00:00
|
|
|
<Linkify text={group.about} />
|
2022-06-22 16:35:50 +00:00
|
|
|
</div>
|
2022-06-24 21:02:05 +00:00
|
|
|
<div className="hidden sm:block xl:hidden">
|
|
|
|
<JoinOrCreateButton
|
|
|
|
group={group}
|
2022-06-22 16:35:50 +00:00
|
|
|
user={user}
|
2022-06-24 21:02:05 +00:00
|
|
|
isMember={!!isMember}
|
2022-06-22 16:35:50 +00:00
|
|
|
/>
|
2022-06-24 21:02:05 +00:00
|
|
|
</div>
|
2022-06-22 16:35:50 +00:00
|
|
|
</Row>
|
2022-06-24 21:02:05 +00:00
|
|
|
<div className="block sm:hidden">
|
|
|
|
<JoinOrCreateButton group={group} user={user} isMember={!!isMember} />
|
|
|
|
</div>
|
|
|
|
</Col>
|
2022-06-22 16:35:50 +00:00
|
|
|
|
|
|
|
<Tabs
|
2022-06-24 23:41:02 +00:00
|
|
|
defaultIndex={page === 'about' ? 2 : page === 'questions' ? 1 : 0}
|
2022-06-22 16:35:50 +00:00
|
|
|
tabs={[
|
|
|
|
{
|
2022-06-24 17:16:37 +00:00
|
|
|
title: 'Chat',
|
2022-06-22 16:35:50 +00:00
|
|
|
content: messages ? (
|
2022-06-24 17:16:37 +00:00
|
|
|
<GroupChat messages={messages} user={user} group={group} />
|
2022-06-22 16:35:50 +00:00
|
|
|
) : (
|
|
|
|
<LoadingIndicator />
|
|
|
|
),
|
2022-06-24 17:16:37 +00:00
|
|
|
href: groupPath(group.slug, 'chat'),
|
2022-06-22 16:35:50 +00:00
|
|
|
},
|
|
|
|
{
|
|
|
|
title: 'Questions',
|
|
|
|
content: (
|
2022-06-24 17:32:59 +00:00
|
|
|
<div className={'mt-2 px-1'}>
|
2022-06-22 16:35:50 +00:00
|
|
|
{contracts ? (
|
|
|
|
contracts.length > 0 ? (
|
2022-06-24 17:32:59 +00:00
|
|
|
<>
|
|
|
|
<input
|
|
|
|
type="text"
|
|
|
|
onChange={(e) => debouncedQuery(e.target.value)}
|
|
|
|
placeholder="Search the group's questions"
|
|
|
|
className="input input-bordered mb-4 w-full"
|
|
|
|
/>
|
|
|
|
<ContractsGrid
|
|
|
|
contracts={query != '' ? filteredContracts : contracts}
|
|
|
|
hasMore={false}
|
|
|
|
loadMore={() => {}}
|
|
|
|
/>
|
|
|
|
</>
|
2022-06-22 16:35:50 +00:00
|
|
|
) : (
|
|
|
|
<div className="p-2 text-gray-500">
|
2022-07-01 13:47:19 +00:00
|
|
|
No questions yet. Why not{' '}
|
|
|
|
<SiteLink
|
|
|
|
href={`/create/?groupId=${group.id}`}
|
|
|
|
className={'font-bold text-gray-700'}
|
|
|
|
>
|
|
|
|
add one?
|
|
|
|
</SiteLink>
|
2022-06-22 16:35:50 +00:00
|
|
|
</div>
|
|
|
|
)
|
|
|
|
) : (
|
|
|
|
<LoadingIndicator />
|
|
|
|
)}
|
|
|
|
{isMember && <AddContractButton group={group} user={user} />}
|
|
|
|
</div>
|
|
|
|
),
|
|
|
|
href: groupPath(group.slug, 'questions'),
|
|
|
|
},
|
|
|
|
{
|
2022-06-24 23:41:02 +00:00
|
|
|
title: 'About',
|
|
|
|
content: aboutTab,
|
|
|
|
href: groupPath(group.slug, 'about'),
|
2022-06-22 16:35:50 +00:00
|
|
|
},
|
|
|
|
]}
|
|
|
|
/>
|
|
|
|
</Page>
|
|
|
|
)
|
|
|
|
}
|
|
|
|
|
2022-06-24 21:02:05 +00:00
|
|
|
function JoinOrCreateButton(props: {
|
|
|
|
group: Group
|
|
|
|
user: User | null | undefined
|
|
|
|
isMember: boolean
|
|
|
|
}) {
|
|
|
|
const { group, user, isMember } = props
|
|
|
|
return isMember ? (
|
|
|
|
<CreateQuestionButton
|
|
|
|
user={user}
|
|
|
|
overrideText={'Add a new question'}
|
|
|
|
className={'w-48 flex-shrink-0'}
|
|
|
|
query={`?groupId=${group.id}`}
|
|
|
|
/>
|
|
|
|
) : group.anyoneCanJoin ? (
|
|
|
|
<JoinGroupButton group={group} user={user} />
|
|
|
|
) : null
|
|
|
|
}
|
|
|
|
|
2022-06-22 16:35:50 +00:00
|
|
|
function GroupOverview(props: {
|
|
|
|
group: Group
|
|
|
|
creator: User
|
|
|
|
user: User | null | undefined
|
|
|
|
isCreator: boolean
|
|
|
|
}) {
|
|
|
|
const { group, creator, isCreator, user } = props
|
|
|
|
const anyoneCanJoinChoices: { [key: string]: string } = {
|
|
|
|
Closed: 'false',
|
|
|
|
Open: 'true',
|
|
|
|
}
|
|
|
|
const [anyoneCanJoin, setAnyoneCanJoin] = useState(group.anyoneCanJoin)
|
|
|
|
function updateAnyoneCanJoin(newVal: boolean) {
|
|
|
|
if (group.anyoneCanJoin == newVal || !isCreator) return
|
|
|
|
setAnyoneCanJoin(newVal)
|
|
|
|
toast.promise(updateGroup(group, { ...group, anyoneCanJoin: newVal }), {
|
|
|
|
loading: 'Updating group...',
|
|
|
|
success: 'Updated group!',
|
|
|
|
error: "Couldn't update group",
|
|
|
|
})
|
|
|
|
}
|
|
|
|
|
|
|
|
return (
|
|
|
|
<Col>
|
|
|
|
<Col className="gap-2 rounded-b bg-white p-4">
|
2022-07-01 13:47:19 +00:00
|
|
|
<Row className={'flex-wrap justify-between'}>
|
|
|
|
<div className={'inline-flex items-center'}>
|
|
|
|
<div className="mr-1 text-gray-500">Created by</div>
|
|
|
|
<UserLink
|
|
|
|
className="text-neutral"
|
|
|
|
name={creator.name}
|
|
|
|
username={creator.username}
|
|
|
|
/>
|
|
|
|
</div>
|
|
|
|
{isCreator && <EditGroupButton className={'ml-1'} group={group} />}
|
2022-06-22 16:35:50 +00:00
|
|
|
</Row>
|
|
|
|
<Row className={'items-center gap-1'}>
|
|
|
|
<span className={'text-gray-500'}>Membership</span>
|
|
|
|
{user && user.id === creator.id ? (
|
|
|
|
<ChoicesToggleGroup
|
|
|
|
currentChoice={anyoneCanJoin.toString()}
|
|
|
|
choicesMap={anyoneCanJoinChoices}
|
|
|
|
setChoice={(choice) =>
|
|
|
|
updateAnyoneCanJoin(choice.toString() === 'true')
|
|
|
|
}
|
|
|
|
toggleClassName={'h-10'}
|
|
|
|
className={'ml-2'}
|
|
|
|
/>
|
|
|
|
) : (
|
|
|
|
<span className={'text-gray-700'}>
|
|
|
|
{anyoneCanJoin ? 'Open' : 'Closed'}
|
|
|
|
</span>
|
|
|
|
)}
|
|
|
|
</Row>
|
2022-07-01 13:47:19 +00:00
|
|
|
{anyoneCanJoin && user && (
|
|
|
|
<Row className={'flex-wrap items-center gap-1'}>
|
|
|
|
<span className={'text-gray-500'}>Sharing</span>
|
|
|
|
<ShareIconButton
|
|
|
|
group={group}
|
|
|
|
username={user.username}
|
|
|
|
buttonClassName={'hover:bg-gray-300 mt-1 !text-gray-700'}
|
|
|
|
>
|
|
|
|
<span className={'mx-2'}>
|
|
|
|
Invite a friend and get M${REFERRAL_AMOUNT} if they sign up!
|
|
|
|
</span>
|
|
|
|
</ShareIconButton>
|
|
|
|
</Row>
|
|
|
|
)}
|
2022-06-22 16:35:50 +00:00
|
|
|
</Col>
|
|
|
|
</Col>
|
|
|
|
)
|
|
|
|
}
|
|
|
|
|
|
|
|
export function GroupMembersList(props: { group: Group }) {
|
|
|
|
const { group } = props
|
|
|
|
const members = useMembers(group)
|
|
|
|
const maxMambersToShow = 5
|
|
|
|
if (group.memberIds.length === 1) return <div />
|
|
|
|
return (
|
|
|
|
<div>
|
|
|
|
<div>
|
|
|
|
<div className="text-neutral flex flex-wrap gap-1">
|
|
|
|
<span className={'text-gray-500'}>Other members</span>
|
|
|
|
{members.slice(0, maxMambersToShow).map((member, i) => (
|
|
|
|
<div key={member.id} className={'flex-shrink'}>
|
|
|
|
<UserLink name={member.name} username={member.username} />
|
|
|
|
{members.length > 1 && i !== members.length - 1 && <span>,</span>}
|
|
|
|
</div>
|
|
|
|
))}
|
|
|
|
{members.length > maxMambersToShow && (
|
|
|
|
<span> & {members.length - maxMambersToShow} more</span>
|
|
|
|
)}
|
|
|
|
</div>
|
|
|
|
</div>
|
|
|
|
</div>
|
|
|
|
)
|
|
|
|
}
|
|
|
|
|
2022-06-24 23:38:39 +00:00
|
|
|
function SortedLeaderboard(props: {
|
|
|
|
users: User[]
|
|
|
|
scoreFunction: (user: User) => number
|
|
|
|
title: string
|
|
|
|
header: string
|
|
|
|
}) {
|
|
|
|
const { users, scoreFunction, title, header } = props
|
|
|
|
const sortedUsers = users.sort((a, b) => scoreFunction(b) - scoreFunction(a))
|
|
|
|
return (
|
|
|
|
<Leaderboard
|
|
|
|
className="max-w-xl"
|
|
|
|
users={sortedUsers}
|
|
|
|
title={title}
|
|
|
|
columns={[
|
|
|
|
{ header, renderCell: (user) => formatMoney(scoreFunction(user)) },
|
|
|
|
]}
|
|
|
|
/>
|
|
|
|
)
|
|
|
|
}
|
|
|
|
|
2022-06-22 16:35:50 +00:00
|
|
|
function GroupLeaderboards(props: {
|
|
|
|
traderScores: { [userId: string]: number }
|
|
|
|
creatorScores: { [userId: string]: number }
|
|
|
|
topTraders: User[]
|
|
|
|
topCreators: User[]
|
2022-06-24 23:38:39 +00:00
|
|
|
members: User[]
|
2022-06-22 16:35:50 +00:00
|
|
|
user: User | null | undefined
|
|
|
|
}) {
|
2022-06-24 23:38:39 +00:00
|
|
|
const { traderScores, creatorScores, members, topTraders, topCreators } =
|
|
|
|
props
|
|
|
|
const [includeOutsiders, setIncludeOutsiders] = useState(false)
|
2022-06-22 16:35:50 +00:00
|
|
|
|
2022-06-24 23:38:39 +00:00
|
|
|
// Consider hiding M$0
|
2022-06-22 16:35:50 +00:00
|
|
|
return (
|
2022-06-24 23:38:39 +00:00
|
|
|
<Col>
|
|
|
|
<Row className="items-center justify-end gap-4 text-gray-500">
|
|
|
|
Include all users
|
|
|
|
<ShortToggle
|
|
|
|
enabled={includeOutsiders}
|
|
|
|
setEnabled={setIncludeOutsiders}
|
|
|
|
/>
|
|
|
|
</Row>
|
2022-06-22 16:35:50 +00:00
|
|
|
|
2022-06-24 23:38:39 +00:00
|
|
|
<div className="mt-4 flex flex-col gap-8 px-4 md:flex-row">
|
|
|
|
{!includeOutsiders ? (
|
|
|
|
<>
|
|
|
|
<SortedLeaderboard
|
|
|
|
users={members}
|
|
|
|
scoreFunction={(user) => traderScores[user.id] ?? 0}
|
|
|
|
title="🏅 Top bettors"
|
|
|
|
header="Profit"
|
|
|
|
/>
|
|
|
|
<SortedLeaderboard
|
|
|
|
users={members}
|
|
|
|
scoreFunction={(user) => creatorScores[user.id] ?? 0}
|
|
|
|
title="🏅 Top creators"
|
|
|
|
header="Market volume"
|
|
|
|
/>
|
|
|
|
</>
|
|
|
|
) : (
|
|
|
|
<>
|
|
|
|
<Leaderboard
|
|
|
|
className="max-w-xl"
|
|
|
|
title="🏅 Top bettors"
|
|
|
|
users={topTraders}
|
|
|
|
columns={[
|
|
|
|
{
|
|
|
|
header: 'Profit',
|
|
|
|
renderCell: (user) => formatMoney(traderScores[user.id] ?? 0),
|
|
|
|
},
|
|
|
|
]}
|
|
|
|
/>
|
|
|
|
<Leaderboard
|
|
|
|
className="max-w-xl"
|
|
|
|
title="🏅 Top creators"
|
|
|
|
users={topCreators}
|
|
|
|
columns={[
|
|
|
|
{
|
|
|
|
header: 'Market volume',
|
|
|
|
renderCell: (user) =>
|
|
|
|
formatMoney(creatorScores[user.id] ?? 0),
|
|
|
|
},
|
|
|
|
]}
|
|
|
|
/>
|
|
|
|
</>
|
|
|
|
)}
|
|
|
|
</div>
|
|
|
|
</Col>
|
2022-06-22 16:35:50 +00:00
|
|
|
)
|
|
|
|
}
|
|
|
|
|
|
|
|
function AddContractButton(props: { group: Group; user: User }) {
|
2022-07-01 22:37:30 +00:00
|
|
|
const { group } = props
|
2022-06-22 16:35:50 +00:00
|
|
|
const [open, setOpen] = useState(false)
|
|
|
|
|
2022-07-01 22:37:30 +00:00
|
|
|
async function addContractToCurrentGroup(contract: Contract) {
|
|
|
|
await addContractToGroup(group, contract.id)
|
2022-06-22 16:35:50 +00:00
|
|
|
setOpen(false)
|
|
|
|
}
|
|
|
|
|
|
|
|
return (
|
|
|
|
<>
|
2022-07-01 22:37:30 +00:00
|
|
|
<Modal open={open} setOpen={setOpen} className={'sm:p-0'}>
|
|
|
|
<Col
|
|
|
|
className={
|
|
|
|
'max-h-[60vh] min-h-[60vh] w-full gap-4 rounded-md bg-white p-8'
|
|
|
|
}
|
|
|
|
>
|
2022-06-22 16:35:50 +00:00
|
|
|
<div className={'text-lg text-indigo-700'}>
|
|
|
|
Add a question to your group
|
|
|
|
</div>
|
2022-07-01 22:37:30 +00:00
|
|
|
<div className={'overflow-y-scroll p-1'}>
|
|
|
|
<ContractSearch
|
|
|
|
hideOrderSelector={true}
|
|
|
|
onContractClick={addContractToCurrentGroup}
|
|
|
|
showCategorySelector={false}
|
|
|
|
overrideGridClassName={'flex grid-cols-1 flex-col gap-3 p-1'}
|
|
|
|
showPlaceHolder={true}
|
|
|
|
hideQuickBet={true}
|
|
|
|
additionalFilter={{ excludeContractIds: group.contractIds }}
|
|
|
|
/>
|
2022-06-22 16:35:50 +00:00
|
|
|
</div>
|
|
|
|
</Col>
|
|
|
|
</Modal>
|
|
|
|
<Row className={'items-center justify-center'}>
|
|
|
|
<button
|
|
|
|
className={
|
2022-07-01 22:37:30 +00:00
|
|
|
'btn btn-md btn-outline cursor-pointer gap-2 whitespace-nowrap text-sm normal-case'
|
2022-06-22 16:35:50 +00:00
|
|
|
}
|
|
|
|
onClick={() => setOpen(true)}
|
|
|
|
>
|
2022-07-01 22:37:30 +00:00
|
|
|
Add an old question
|
2022-06-22 16:35:50 +00:00
|
|
|
</button>
|
|
|
|
</Row>
|
|
|
|
</>
|
|
|
|
)
|
|
|
|
}
|
|
|
|
|
|
|
|
function JoinGroupButton(props: {
|
|
|
|
group: Group
|
|
|
|
user: User | null | undefined
|
|
|
|
}) {
|
|
|
|
const { group, user } = props
|
|
|
|
function joinGroup() {
|
|
|
|
if (user && !group.memberIds.includes(user.id)) {
|
2022-07-01 22:37:30 +00:00
|
|
|
toast.promise(addUserToGroup(group, user.id), {
|
|
|
|
loading: 'Joining group...',
|
|
|
|
success: 'Joined group!',
|
|
|
|
error: "Couldn't join group",
|
|
|
|
})
|
2022-06-22 16:35:50 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
return (
|
|
|
|
<div>
|
2022-06-23 17:40:32 +00:00
|
|
|
<button
|
|
|
|
onClick={user ? joinGroup : firebaseLogin}
|
|
|
|
className={'btn-md btn-outline btn whitespace-nowrap normal-case'}
|
|
|
|
>
|
|
|
|
{user ? 'Join group' : 'Login to join group'}
|
2022-06-22 16:35:50 +00:00
|
|
|
</button>
|
|
|
|
</div>
|
|
|
|
)
|
|
|
|
}
|