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

68 lines
1.6 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: {
2022-04-28 17:28:52 +00:00
feed: {
contract: Contract
recentBets: Bet[]
recentComments: Comment[]
}[]
mode: 'only-recent' | 'abbreviated' | 'all'
2022-04-11 21:13:26 +00:00
getContractPath?: (contract: Contract) => string
}) {
2022-04-28 17:28:52 +00:00
const { feed, mode, getContractPath } = props
const user = useUser()
return (
<FeedContainer
2022-04-28 17:28:52 +00:00
feed={feed}
renderItem={({ contract, recentBets, recentComments }) => (
<ContractActivity
user={user}
contract={contract}
2022-04-28 17:28:52 +00:00
bets={recentBets}
comments={recentComments}
mode={mode}
2022-04-11 21:13:26 +00:00
contractPath={getContractPath ? getContractPath(contract) : undefined}
/>
)}
/>
)
}
function FeedContainer(props: {
2022-04-28 17:28:52 +00:00
feed: {
contract: Contract
recentBets: Bet[]
recentComments: Comment[]
}[]
renderItem: (item: {
contract: Contract
recentBets: Bet[]
recentComments: Comment[]
}) => any
}) {
2022-04-28 17:28:52 +00:00
const { feed, renderItem } = 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">
2022-04-28 17:28:52 +00:00
{feed.map((item) => (
<div key={item.contract.id} className="py-6 px-2 sm:px-4">
{renderItem(item)}
</div>
))}
</Col>
</Col>
</Col>
)
}