2022-05-17 15:55:26 +00:00
|
|
|
import { Answer } from 'common/answer'
|
2022-10-12 18:05:58 +00:00
|
|
|
import { Contract } from 'common/contract'
|
|
|
|
import React, { useEffect, useRef } from 'react'
|
2022-05-17 15:55:26 +00:00
|
|
|
import { Col } from 'web/components/layout/col'
|
|
|
|
import { Row } from 'web/components/layout/row'
|
|
|
|
import { Avatar } from 'web/components/avatar'
|
|
|
|
import { CopyLinkDateTimeComponent } from 'web/components/feed/copy-link-date-time'
|
|
|
|
import { useRouter } from 'next/router'
|
2022-08-30 15:38:59 +00:00
|
|
|
import { UserLink } from 'web/components/user-link'
|
2022-05-17 15:55:26 +00:00
|
|
|
|
2022-10-12 18:05:58 +00:00
|
|
|
export function CommentsAnswer(props: { answer: Answer; contract: Contract }) {
|
|
|
|
const { answer, contract } = props
|
2022-05-17 15:55:26 +00:00
|
|
|
const { username, avatarUrl, name, text } = answer
|
|
|
|
const answerElementId = `answer-${answer.id}`
|
2022-10-12 18:05:58 +00:00
|
|
|
const router = useRouter()
|
2022-09-22 19:58:40 +00:00
|
|
|
const highlighted = router.asPath.endsWith(`#${answerElementId}`)
|
|
|
|
const answerRef = useRef<HTMLDivElement>(null)
|
2022-06-08 23:09:49 +00:00
|
|
|
|
2022-05-17 15:55:26 +00:00
|
|
|
useEffect(() => {
|
2022-09-22 19:58:40 +00:00
|
|
|
if (highlighted && answerRef.current != null) {
|
|
|
|
answerRef.current.scrollIntoView(true)
|
2022-05-17 15:55:26 +00:00
|
|
|
}
|
2022-09-22 19:58:40 +00:00
|
|
|
}, [highlighted])
|
2022-05-17 15:55:26 +00:00
|
|
|
|
|
|
|
return (
|
2022-10-12 18:05:58 +00:00
|
|
|
<Col className="bg-greyscale-2 w-fit gap-1 rounded-t-xl rounded-bl-xl py-2 px-4">
|
|
|
|
<Row className="gap-2">
|
|
|
|
<Avatar username={username} avatarUrl={avatarUrl} size="xxs" />
|
|
|
|
<div className="text-greyscale-6 text-xs">
|
|
|
|
<UserLink username={username} name={name} /> answered
|
|
|
|
<CopyLinkDateTimeComponent
|
|
|
|
prefix={contract.creatorUsername}
|
|
|
|
slug={contract.slug}
|
|
|
|
createdTime={answer.createdTime}
|
|
|
|
elementId={answerElementId}
|
2022-05-17 15:55:26 +00:00
|
|
|
/>
|
|
|
|
</div>
|
2022-10-12 18:05:58 +00:00
|
|
|
</Row>
|
|
|
|
<div className="text-sm">{text}</div>
|
2022-05-17 15:55:26 +00:00
|
|
|
</Col>
|
|
|
|
)
|
|
|
|
}
|