Clean up a bunch of crufty stuff on user comments list (#693)

This commit is contained in:
Marshall Polaris 2022-07-26 00:10:11 -07:00 committed by GitHub
parent 0c2bcceae2
commit 7e4f4b9a87
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -17,46 +17,45 @@ export function UserCommentsList(props: {
contractsById: { [id: string]: Contract } contractsById: { [id: string]: Contract }
}) { }) {
const { comments, contractsById } = props const { comments, contractsById } = props
const commentsByContract = groupBy(comments, 'contractId')
const contractCommentPairs = Object.entries(commentsByContract) // we don't show comments in groups here atm, just comments on contracts
.map( const contractComments = comments.filter((c) => c.contractId)
([contractId, comments]) => [contractsById[contractId], comments] as const const commentsByContract = groupBy(contractComments, 'contractId')
)
.filter(([contract]) => contract)
return ( return (
<Col className={'bg-white'}> <Col className={'bg-white'}>
{contractCommentPairs.map(([contract, comments]) => ( {Object.entries(commentsByContract).map(([contractId, comments]) => {
<div key={contract.id} className={'border-width-1 border-b p-5'}> const contract = contractsById[contractId]
<div className={'mb-2 text-sm text-indigo-700'}> return (
<SiteLink href={contractPath(contract)}> <div key={contractId} className={'border-width-1 border-b p-5'}>
<SiteLink
className={'mb-2 block text-sm text-indigo-700'}
href={contractPath(contract)}
>
{contract.question} {contract.question}
</SiteLink> </SiteLink>
</div>
{comments.map((comment) => ( {comments.map((comment) => (
<div key={comment.id} className={'relative pb-6'}> <ProfileComment
<div className="relative flex items-start space-x-3"> key={comment.id}
<ProfileComment comment={comment} /> comment={comment}
</div> className="relative flex items-start space-x-3 pb-6"
</div> />
))} ))}
</div> </div>
))} )
})}
</Col> </Col>
) )
} }
function ProfileComment(props: { comment: Comment }) { function ProfileComment(props: { comment: Comment; className?: string }) {
const { comment } = props const { comment, className } = props
const { text, userUsername, userName, userAvatarUrl, createdTime } = comment const { text, userUsername, userName, userAvatarUrl, createdTime } = comment
// TODO: find and attach relevant bets by comment betId at some point // TODO: find and attach relevant bets by comment betId at some point
return ( return (
<div> <Row className={className}>
<Row className={'gap-4'}>
<Avatar username={userUsername} avatarUrl={userAvatarUrl} /> <Avatar username={userUsername} avatarUrl={userAvatarUrl} />
<div className="min-w-0 flex-1"> <div className="min-w-0 flex-1">
<div>
<p className="mt-0.5 text-sm text-gray-500"> <p className="mt-0.5 text-sm text-gray-500">
<UserLink <UserLink
className="text-gray-500" className="text-gray-500"
@ -65,10 +64,8 @@ function ProfileComment(props: { comment: Comment }) {
/>{' '} />{' '}
<RelativeTimestamp time={createdTime} /> <RelativeTimestamp time={createdTime} />
</p> </p>
</div>
<Linkify text={text} /> <Linkify text={text} />
</div> </div>
</Row> </Row>
</div>
) )
} }