Eliminate needless state/effects to highlight comments
This commit is contained in:
parent
7704de6904
commit
0228f26a6e
|
@ -1,7 +1,7 @@
|
||||||
import { Answer } from 'common/answer'
|
import { Answer } from 'common/answer'
|
||||||
import { FreeResponseContract } from 'common/contract'
|
import { FreeResponseContract } from 'common/contract'
|
||||||
import { ContractComment } from 'common/comment'
|
import { ContractComment } from 'common/comment'
|
||||||
import React, { useEffect, useState } from 'react'
|
import React, { useState } from 'react'
|
||||||
import { Col } from 'web/components/layout/col'
|
import { Col } from 'web/components/layout/col'
|
||||||
import { Row } from 'web/components/layout/row'
|
import { Row } from 'web/components/layout/row'
|
||||||
import { Avatar } from 'web/components/avatar'
|
import { Avatar } from 'web/components/avatar'
|
||||||
|
@ -27,15 +27,9 @@ export function FeedAnswerCommentGroup(props: {
|
||||||
const { username, avatarUrl, name, text } = answer
|
const { username, avatarUrl, name, text } = answer
|
||||||
|
|
||||||
const [replyTo, setReplyTo] = useState<ReplyTo>()
|
const [replyTo, setReplyTo] = useState<ReplyTo>()
|
||||||
const [highlighted, setHighlighted] = useState(false)
|
|
||||||
const router = useRouter()
|
const router = useRouter()
|
||||||
const answerElementId = `answer-${answer.id}`
|
const answerElementId = `answer-${answer.id}`
|
||||||
|
const highlighted = router.asPath.endsWith(`#${answerElementId}`)
|
||||||
useEffect(() => {
|
|
||||||
if (router.asPath.endsWith(`#${answerElementId}`)) {
|
|
||||||
setHighlighted(true)
|
|
||||||
}
|
|
||||||
}, [answerElementId, router.asPath])
|
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<Col className="relative flex-1 items-stretch gap-3">
|
<Col className="relative flex-1 items-stretch gap-3">
|
||||||
|
|
|
@ -1,6 +1,6 @@
|
||||||
import { ContractComment } from 'common/comment'
|
import { ContractComment } from 'common/comment'
|
||||||
import { Contract } from 'common/contract'
|
import { Contract } from 'common/contract'
|
||||||
import React, { useEffect, useState } from 'react'
|
import React, { useState } from 'react'
|
||||||
import { useUser } from 'web/hooks/use-user'
|
import { useUser } from 'web/hooks/use-user'
|
||||||
import { formatMoney } from 'common/util/format'
|
import { formatMoney } from 'common/util/format'
|
||||||
import { useRouter } from 'next/router'
|
import { useRouter } from 'next/router'
|
||||||
|
@ -94,13 +94,8 @@ export function FeedComment(props: {
|
||||||
money = formatMoney(Math.abs(comment.betAmount))
|
money = formatMoney(Math.abs(comment.betAmount))
|
||||||
}
|
}
|
||||||
|
|
||||||
const [highlighted, setHighlighted] = useState(false)
|
|
||||||
const router = useRouter()
|
const router = useRouter()
|
||||||
useEffect(() => {
|
const highlighted = router.asPath.endsWith(`#${comment.id}`)
|
||||||
if (router.asPath.endsWith(`#${comment.id}`)) {
|
|
||||||
setHighlighted(true)
|
|
||||||
}
|
|
||||||
}, [comment.id, router.asPath])
|
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<Row
|
<Row
|
||||||
|
|
Loading…
Reference in New Issue
Block a user