2022-05-09 13:04:36 +00:00
|
|
|
import { Contract } from 'web/lib/firebase/contracts'
|
|
|
|
import { Comment } from 'web/lib/firebase/comments'
|
|
|
|
import { Bet } from 'common/bet'
|
|
|
|
import { useBets } from 'web/hooks/use-bets'
|
|
|
|
import { useComments } from 'web/hooks/use-comments'
|
2022-03-14 20:29:32 +00:00
|
|
|
import {
|
|
|
|
getAllContractActivityItems,
|
|
|
|
getRecentContractActivityItems,
|
2022-04-26 21:08:50 +00:00
|
|
|
getSpecificContractActivityItems,
|
2022-03-14 20:29:32 +00:00
|
|
|
} from './activity-items'
|
|
|
|
import { FeedItems } from './feed-items'
|
2022-05-09 13:04:36 +00:00
|
|
|
import { User } from 'common/user'
|
2022-06-10 23:36:18 +00:00
|
|
|
import { useContractWithPreload } from 'web/hooks/use-contract'
|
2022-03-14 20:29:32 +00:00
|
|
|
|
|
|
|
export function ContractActivity(props: {
|
|
|
|
contract: Contract
|
|
|
|
bets: Bet[]
|
|
|
|
comments: Comment[]
|
|
|
|
user: User | null | undefined
|
2022-05-03 20:38:40 +00:00
|
|
|
mode:
|
|
|
|
| 'only-recent'
|
|
|
|
| 'abbreviated'
|
|
|
|
| 'all'
|
|
|
|
| 'comments'
|
|
|
|
| 'bets'
|
|
|
|
| 'free-response-comment-answer-groups'
|
2022-04-11 21:13:26 +00:00
|
|
|
contractPath?: string
|
2022-04-06 05:22:43 +00:00
|
|
|
className?: string
|
2022-03-14 20:29:32 +00:00
|
|
|
betRowClassName?: string
|
|
|
|
}) {
|
2022-05-12 15:07:10 +00:00
|
|
|
const { user, mode, contractPath, className, betRowClassName } = props
|
|
|
|
|
2022-06-10 23:36:18 +00:00
|
|
|
const contract = useContractWithPreload(props.contract) ?? props.contract
|
2022-03-14 20:29:32 +00:00
|
|
|
|
|
|
|
const updatedComments =
|
|
|
|
// eslint-disable-next-line react-hooks/rules-of-hooks
|
|
|
|
mode === 'only-recent' ? undefined : useComments(contract.id)
|
|
|
|
const comments = updatedComments ?? props.comments
|
|
|
|
|
2022-06-10 23:36:18 +00:00
|
|
|
const updatedBets =
|
|
|
|
// eslint-disable-next-line react-hooks/rules-of-hooks
|
|
|
|
mode === 'only-recent' ? undefined : useBets(contract.id)
|
2022-05-28 20:57:12 +00:00
|
|
|
const bets = (updatedBets ?? props.bets).filter((bet) => !bet.isRedemption)
|
2022-03-14 20:29:32 +00:00
|
|
|
const items =
|
|
|
|
mode === 'only-recent'
|
2022-04-11 21:13:26 +00:00
|
|
|
? getRecentContractActivityItems(contract, bets, comments, user, {
|
|
|
|
contractPath,
|
|
|
|
})
|
2022-05-03 20:38:40 +00:00
|
|
|
: mode === 'comments' ||
|
|
|
|
mode === 'bets' ||
|
|
|
|
mode === 'free-response-comment-answer-groups'
|
2022-04-26 21:08:50 +00:00
|
|
|
? getSpecificContractActivityItems(contract, bets, comments, user, {
|
|
|
|
mode,
|
|
|
|
})
|
|
|
|
: // only used in abbreviated mode with folds/communities, all mode isn't used
|
|
|
|
getAllContractActivityItems(contract, bets, comments, user, {
|
2022-04-19 01:54:31 +00:00
|
|
|
abbreviated: mode === 'abbreviated',
|
|
|
|
})
|
2022-03-14 20:29:32 +00:00
|
|
|
|
|
|
|
return (
|
|
|
|
<FeedItems
|
|
|
|
contract={contract}
|
|
|
|
items={items}
|
2022-04-06 05:22:43 +00:00
|
|
|
className={className}
|
2022-03-14 20:29:32 +00:00
|
|
|
betRowClassName={betRowClassName}
|
|
|
|
/>
|
|
|
|
)
|
|
|
|
}
|