Paginate contract bets tab (#881)
* Apply pagination to bets list on contract * Make contract trades tab number actually match number of entries
This commit is contained in:
parent
1476f669d3
commit
b903183fff
|
@ -19,6 +19,10 @@ import { BetSignUpPrompt } from '../sign-up-prompt'
|
||||||
import { PlayMoneyDisclaimer } from '../play-money-disclaimer'
|
import { PlayMoneyDisclaimer } from '../play-money-disclaimer'
|
||||||
import BetButton from '../bet-button'
|
import BetButton from '../bet-button'
|
||||||
import { capitalize } from 'lodash'
|
import { capitalize } from 'lodash'
|
||||||
|
import {
|
||||||
|
DEV_HOUSE_LIQUIDITY_PROVIDER_ID,
|
||||||
|
HOUSE_LIQUIDITY_PROVIDER_ID,
|
||||||
|
} from 'common/antes'
|
||||||
|
|
||||||
export function ContractTabs(props: {
|
export function ContractTabs(props: {
|
||||||
contract: Contract
|
contract: Contract
|
||||||
|
@ -37,13 +41,19 @@ export function ContractTabs(props: {
|
||||||
const visibleBets = bets.filter(
|
const visibleBets = bets.filter(
|
||||||
(bet) => !bet.isAnte && !bet.isRedemption && bet.amount !== 0
|
(bet) => !bet.isAnte && !bet.isRedemption && bet.amount !== 0
|
||||||
)
|
)
|
||||||
const visibleLps = lps?.filter((l) => !l.isAnte && l.amount > 0)
|
const visibleLps = (lps ?? []).filter(
|
||||||
|
(l) =>
|
||||||
|
!l.isAnte &&
|
||||||
|
l.userId !== HOUSE_LIQUIDITY_PROVIDER_ID &&
|
||||||
|
l.userId !== DEV_HOUSE_LIQUIDITY_PROVIDER_ID &&
|
||||||
|
l.amount > 0
|
||||||
|
)
|
||||||
|
|
||||||
// Load comments here, so the badge count will be correct
|
// Load comments here, so the badge count will be correct
|
||||||
const updatedComments = useComments(contract.id)
|
const updatedComments = useComments(contract.id)
|
||||||
const comments = updatedComments ?? props.comments
|
const comments = updatedComments ?? props.comments
|
||||||
|
|
||||||
const betActivity = visibleLps && (
|
const betActivity = lps != null && (
|
||||||
<ContractBetsActivity
|
<ContractBetsActivity
|
||||||
contract={contract}
|
contract={contract}
|
||||||
bets={visibleBets}
|
bets={visibleBets}
|
||||||
|
@ -117,7 +127,7 @@ export function ContractTabs(props: {
|
||||||
{
|
{
|
||||||
title: capitalize(PAST_BETS),
|
title: capitalize(PAST_BETS),
|
||||||
content: betActivity,
|
content: betActivity,
|
||||||
badge: `${visibleBets.length}`,
|
badge: `${visibleBets.length + visibleLps.length}`,
|
||||||
},
|
},
|
||||||
...(!user || !userBets?.length
|
...(!user || !userBets?.length
|
||||||
? []
|
? []
|
||||||
|
|
|
@ -1,8 +1,10 @@
|
||||||
|
import { useState } from 'react'
|
||||||
import { Contract, FreeResponseContract } from 'common/contract'
|
import { Contract, FreeResponseContract } from 'common/contract'
|
||||||
import { ContractComment } from 'common/comment'
|
import { ContractComment } from 'common/comment'
|
||||||
import { Answer } from 'common/answer'
|
import { Answer } from 'common/answer'
|
||||||
import { Bet } from 'common/bet'
|
import { Bet } from 'common/bet'
|
||||||
import { getOutcomeProbability } from 'common/calculate'
|
import { getOutcomeProbability } from 'common/calculate'
|
||||||
|
import { Pagination } from 'web/components/pagination'
|
||||||
import { FeedBet } from './feed-bets'
|
import { FeedBet } from './feed-bets'
|
||||||
import { FeedLiquidity } from './feed-liquidity'
|
import { FeedLiquidity } from './feed-liquidity'
|
||||||
import { FeedAnswerCommentGroup } from './feed-answer-comment-group'
|
import { FeedAnswerCommentGroup } from './feed-answer-comment-group'
|
||||||
|
@ -19,6 +21,10 @@ export function ContractBetsActivity(props: {
|
||||||
lps: LiquidityProvision[]
|
lps: LiquidityProvision[]
|
||||||
}) {
|
}) {
|
||||||
const { contract, bets, lps } = props
|
const { contract, bets, lps } = props
|
||||||
|
const [page, setPage] = useState(0)
|
||||||
|
const ITEMS_PER_PAGE = 50
|
||||||
|
const start = page * ITEMS_PER_PAGE
|
||||||
|
const end = start + ITEMS_PER_PAGE
|
||||||
|
|
||||||
const items = [
|
const items = [
|
||||||
...bets.map((bet) => ({
|
...bets.map((bet) => ({
|
||||||
|
@ -33,24 +39,35 @@ export function ContractBetsActivity(props: {
|
||||||
})),
|
})),
|
||||||
]
|
]
|
||||||
|
|
||||||
const sortedItems = sortBy(items, (item) =>
|
const pageItems = sortBy(items, (item) =>
|
||||||
item.type === 'bet'
|
item.type === 'bet'
|
||||||
? -item.bet.createdTime
|
? -item.bet.createdTime
|
||||||
: item.type === 'liquidity'
|
: item.type === 'liquidity'
|
||||||
? -item.lp.createdTime
|
? -item.lp.createdTime
|
||||||
: undefined
|
: undefined
|
||||||
)
|
).slice(start, end)
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<Col className="gap-4">
|
<>
|
||||||
{sortedItems.map((item) =>
|
<Col className="mb-4 gap-4">
|
||||||
item.type === 'bet' ? (
|
{pageItems.map((item) =>
|
||||||
<FeedBet key={item.id} contract={contract} bet={item.bet} />
|
item.type === 'bet' ? (
|
||||||
) : (
|
<FeedBet key={item.id} contract={contract} bet={item.bet} />
|
||||||
<FeedLiquidity key={item.id} liquidity={item.lp} />
|
) : (
|
||||||
)
|
<FeedLiquidity key={item.id} liquidity={item.lp} />
|
||||||
)}
|
)
|
||||||
</Col>
|
)}
|
||||||
|
</Col>
|
||||||
|
<Pagination
|
||||||
|
page={page}
|
||||||
|
itemsPerPage={50}
|
||||||
|
totalItems={items.length}
|
||||||
|
setPage={setPage}
|
||||||
|
scrollToTop
|
||||||
|
nextTitle={'Older'}
|
||||||
|
prevTitle={'Newer'}
|
||||||
|
/>
|
||||||
|
</>
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -9,17 +9,13 @@ import { RelativeTimestamp } from 'web/components/relative-timestamp'
|
||||||
import React from 'react'
|
import React from 'react'
|
||||||
import { LiquidityProvision } from 'common/liquidity-provision'
|
import { LiquidityProvision } from 'common/liquidity-provision'
|
||||||
import { UserLink } from 'web/components/user-link'
|
import { UserLink } from 'web/components/user-link'
|
||||||
import {
|
|
||||||
DEV_HOUSE_LIQUIDITY_PROVIDER_ID,
|
|
||||||
HOUSE_LIQUIDITY_PROVIDER_ID,
|
|
||||||
} from 'common/antes'
|
|
||||||
|
|
||||||
export function FeedLiquidity(props: {
|
export function FeedLiquidity(props: {
|
||||||
className?: string
|
className?: string
|
||||||
liquidity: LiquidityProvision
|
liquidity: LiquidityProvision
|
||||||
}) {
|
}) {
|
||||||
const { liquidity } = props
|
const { liquidity } = props
|
||||||
const { userId, createdTime, isAnte } = liquidity
|
const { userId, createdTime } = liquidity
|
||||||
|
|
||||||
const isBeforeJune2022 = dayjs(createdTime).isBefore('2022-06-01')
|
const isBeforeJune2022 = dayjs(createdTime).isBefore('2022-06-01')
|
||||||
// eslint-disable-next-line react-hooks/rules-of-hooks
|
// eslint-disable-next-line react-hooks/rules-of-hooks
|
||||||
|
@ -28,13 +24,6 @@ export function FeedLiquidity(props: {
|
||||||
const user = useUser()
|
const user = useUser()
|
||||||
const isSelf = user?.id === userId
|
const isSelf = user?.id === userId
|
||||||
|
|
||||||
if (
|
|
||||||
isAnte ||
|
|
||||||
userId === HOUSE_LIQUIDITY_PROVIDER_ID ||
|
|
||||||
userId === DEV_HOUSE_LIQUIDITY_PROVIDER_ID
|
|
||||||
)
|
|
||||||
return <></>
|
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<Row className="items-center gap-2 pt-3">
|
<Row className="items-center gap-2 pt-3">
|
||||||
{isSelf ? (
|
{isSelf ? (
|
||||||
|
|
Loading…
Reference in New Issue
Block a user