manifold/web/components/feed/activity-feed.tsx

64 lines
1.7 KiB
TypeScript
Raw Normal View History

import _ from 'lodash'
2022-04-11 21:13:26 +00:00
import { Contract } from '../../lib/firebase/contracts'
import { Comment } from '../../lib/firebase/comments'
import { Col } from '../layout/col'
import { Bet } from '../../../common/bet'
import { useUser } from '../../hooks/use-user'
import { ContractActivity } from './contract-activity'
export function ActivityFeed(props: {
contracts: Contract[]
recentBets: Bet[]
recentComments: Comment[]
mode: 'only-recent' | 'abbreviated' | 'all'
2022-04-11 21:13:26 +00:00
getContractPath?: (contract: Contract) => string
}) {
2022-04-11 21:13:26 +00:00
const { contracts, recentBets, recentComments, mode, getContractPath } = props
const user = useUser()
const groupedBets = _.groupBy(recentBets, (bet) => bet.contractId)
const groupedComments = _.groupBy(
recentComments,
(comment) => comment.contractId
)
return (
<FeedContainer
contracts={contracts}
renderContract={(contract) => (
<ContractActivity
user={user}
contract={contract}
bets={groupedBets[contract.id] ?? []}
comments={groupedComments[contract.id] ?? []}
mode={mode}
2022-04-11 21:13:26 +00:00
contractPath={getContractPath ? getContractPath(contract) : undefined}
/>
)}
/>
)
}
function FeedContainer(props: {
contracts: Contract[]
renderContract: (contract: Contract) => any
}) {
const { contracts, renderContract } = props
return (
<Col className="items-center">
<Col className="w-full max-w-3xl">
<Col className="w-full divide-y divide-gray-300 self-center bg-white">
{contracts.map((contract) => (
<div key={contract.id} className="py-6 px-2 sm:px-4">
{renderContract(contract)}
</div>
))}
</Col>
</Col>
</Col>
)
}