2022-04-08 21:13:10 +00:00
|
|
|
import { Bet } from '../../../common/bet'
|
|
|
|
import { Contract } from '../../../common/contract'
|
|
|
|
import { Comment } from '../../lib/firebase/comments'
|
|
|
|
import { User } from '../../../common/user'
|
|
|
|
import { useBets } from '../../hooks/use-bets'
|
|
|
|
import { ContractActivity } from '../feed/contract-activity'
|
|
|
|
import { ContractBetsTable, MyBetsSummary } from '../bets-list'
|
|
|
|
import { Spacer } from '../layout/spacer'
|
|
|
|
import { Tabs } from '../layout/tabs'
|
|
|
|
|
|
|
|
export function ContractTabs(props: {
|
|
|
|
contract: Contract
|
|
|
|
user: User | null | undefined
|
|
|
|
bets: Bet[]
|
|
|
|
comments: Comment[]
|
|
|
|
}) {
|
|
|
|
const { contract, user, comments } = props
|
|
|
|
|
|
|
|
const bets = useBets(contract.id) ?? props.bets
|
|
|
|
// Decending creation time.
|
|
|
|
bets.sort((bet1, bet2) => bet2.createdTime - bet1.createdTime)
|
|
|
|
const userBets = user && bets.filter((bet) => bet.userId === user.id)
|
|
|
|
|
2022-04-26 21:08:50 +00:00
|
|
|
const betActivity = (
|
2022-04-08 21:13:10 +00:00
|
|
|
<ContractActivity
|
|
|
|
contract={contract}
|
|
|
|
bets={bets}
|
|
|
|
comments={comments}
|
|
|
|
user={user}
|
2022-04-26 21:08:50 +00:00
|
|
|
mode="bets"
|
|
|
|
betRowClassName="!mt-0 xl:hidden"
|
|
|
|
/>
|
|
|
|
)
|
|
|
|
|
|
|
|
const commentActivity = (
|
|
|
|
<ContractActivity
|
|
|
|
contract={contract}
|
|
|
|
bets={bets}
|
|
|
|
comments={comments}
|
|
|
|
user={user}
|
|
|
|
mode="comments"
|
2022-04-08 21:13:10 +00:00
|
|
|
betRowClassName="!mt-0 xl:hidden"
|
|
|
|
/>
|
|
|
|
)
|
|
|
|
|
|
|
|
const yourTrades = (
|
|
|
|
<div>
|
2022-04-09 21:34:43 +00:00
|
|
|
<MyBetsSummary
|
|
|
|
className="px-2"
|
|
|
|
contract={contract}
|
|
|
|
bets={userBets ?? []}
|
|
|
|
/>
|
2022-04-08 21:13:10 +00:00
|
|
|
<Spacer h={6} />
|
2022-04-09 21:34:43 +00:00
|
|
|
<ContractBetsTable contract={contract} bets={userBets ?? []} />
|
2022-04-08 21:13:10 +00:00
|
|
|
<Spacer h={12} />
|
|
|
|
</div>
|
|
|
|
)
|
|
|
|
|
|
|
|
return (
|
|
|
|
<Tabs
|
|
|
|
tabs={[
|
2022-04-26 21:08:50 +00:00
|
|
|
{ title: 'Comments', content: commentActivity },
|
|
|
|
{ title: 'Bets', content: betActivity },
|
2022-04-09 21:34:43 +00:00
|
|
|
...(!user || !userBets?.length
|
|
|
|
? []
|
2022-04-26 14:38:28 +00:00
|
|
|
: [{ title: 'Your bets', content: yourTrades }]),
|
2022-04-08 21:13:10 +00:00
|
|
|
]}
|
|
|
|
/>
|
|
|
|
)
|
|
|
|
}
|