2022-05-09 13:04:36 +00:00
|
|
|
import { Comment } from 'common/comment'
|
|
|
|
import { Contract } from 'common/contract'
|
|
|
|
import { contractPath } from 'web/lib/firebase/contracts'
|
2022-05-05 22:30:30 +00:00
|
|
|
import { SiteLink } from './site-link'
|
|
|
|
import { Row } from './layout/row'
|
|
|
|
import { Avatar } from './avatar'
|
|
|
|
import { RelativeTimestamp } from './relative-timestamp'
|
|
|
|
import { UserLink } from './user-page'
|
2022-05-09 13:04:36 +00:00
|
|
|
import { User } from 'common/user'
|
2022-05-05 22:30:30 +00:00
|
|
|
import { Col } from './layout/col'
|
2022-08-04 23:49:59 +00:00
|
|
|
import { Linkify } from './linkify'
|
2022-07-11 00:19:35 +00:00
|
|
|
import { groupBy } from 'lodash'
|
2022-05-05 22:30:30 +00:00
|
|
|
|
|
|
|
export function UserCommentsList(props: {
|
|
|
|
user: User
|
2022-07-11 00:19:35 +00:00
|
|
|
comments: Comment[]
|
|
|
|
contractsById: { [id: string]: Contract }
|
2022-05-05 22:30:30 +00:00
|
|
|
}) {
|
2022-07-11 00:19:35 +00:00
|
|
|
const { comments, contractsById } = props
|
|
|
|
|
2022-07-26 07:10:11 +00:00
|
|
|
// we don't show comments in groups here atm, just comments on contracts
|
|
|
|
const contractComments = comments.filter((c) => c.contractId)
|
|
|
|
const commentsByContract = groupBy(contractComments, 'contractId')
|
2022-05-05 22:30:30 +00:00
|
|
|
|
|
|
|
return (
|
|
|
|
<Col className={'bg-white'}>
|
2022-07-26 07:10:11 +00:00
|
|
|
{Object.entries(commentsByContract).map(([contractId, comments]) => {
|
|
|
|
const contract = contractsById[contractId]
|
|
|
|
return (
|
|
|
|
<div key={contractId} className={'border-width-1 border-b p-5'}>
|
|
|
|
<SiteLink
|
|
|
|
className={'mb-2 block text-sm text-indigo-700'}
|
|
|
|
href={contractPath(contract)}
|
|
|
|
>
|
2022-05-05 22:30:30 +00:00
|
|
|
{contract.question}
|
|
|
|
</SiteLink>
|
2022-07-26 07:10:11 +00:00
|
|
|
{comments.map((comment) => (
|
|
|
|
<ProfileComment
|
|
|
|
key={comment.id}
|
|
|
|
comment={comment}
|
|
|
|
className="relative flex items-start space-x-3 pb-6"
|
|
|
|
/>
|
|
|
|
))}
|
2022-05-05 22:30:30 +00:00
|
|
|
</div>
|
2022-07-26 07:10:11 +00:00
|
|
|
)
|
|
|
|
})}
|
2022-05-05 22:30:30 +00:00
|
|
|
</Col>
|
|
|
|
)
|
|
|
|
}
|
|
|
|
|
2022-07-26 07:10:11 +00:00
|
|
|
function ProfileComment(props: { comment: Comment; className?: string }) {
|
|
|
|
const { comment, className } = props
|
2022-08-04 23:49:59 +00:00
|
|
|
const { text, userUsername, userName, userAvatarUrl, createdTime } = comment
|
2022-05-05 22:30:30 +00:00
|
|
|
// TODO: find and attach relevant bets by comment betId at some point
|
|
|
|
return (
|
2022-07-26 07:10:11 +00:00
|
|
|
<Row className={className}>
|
|
|
|
<Avatar username={userUsername} avatarUrl={userAvatarUrl} />
|
|
|
|
<div className="min-w-0 flex-1">
|
|
|
|
<p className="mt-0.5 text-sm text-gray-500">
|
|
|
|
<UserLink
|
|
|
|
className="text-gray-500"
|
|
|
|
username={userUsername}
|
|
|
|
name={userName}
|
|
|
|
/>{' '}
|
|
|
|
<RelativeTimestamp time={createdTime} />
|
|
|
|
</p>
|
2022-08-04 23:49:59 +00:00
|
|
|
<Linkify text={text} />
|
2022-07-26 07:10:11 +00:00
|
|
|
</div>
|
|
|
|
</Row>
|
2022-05-05 22:30:30 +00:00
|
|
|
)
|
|
|
|
}
|