added scroll to comment

This commit is contained in:
ingawei 2022-10-11 19:19:22 -07:00
parent b8a095d853
commit 141856fd1f
4 changed files with 15 additions and 24 deletions

View File

@ -158,7 +158,7 @@ export function CommentInputTextArea(props: {
attrs: { label: replyTo.username, id: replyTo.id }, attrs: { label: replyTo.username, id: replyTo.id },
}) })
.insertContent(' ') .insertContent(' ')
.focus() .focus(undefined, { scrollIntoView: false })
.run() .run()
} }
// eslint-disable-next-line react-hooks/exhaustive-deps // eslint-disable-next-line react-hooks/exhaustive-deps

View File

@ -107,7 +107,6 @@ const CommentsTabContent = memo(function CommentsTabContent(props: {
onCancelAnswerResponse?: () => void onCancelAnswerResponse?: () => void
}) { }) {
const { contract, answerResponse, onCancelAnswerResponse } = props const { contract, answerResponse, onCancelAnswerResponse } = props
console.log(answerResponse)
const tips = useTipTxns({ contractId: contract.id }) const tips = useTipTxns({ contractId: contract.id })
const comments = useComments(contract.id) ?? props.comments const comments = useComments(contract.id) ?? props.comments
const [sort, setSort] = usePersistentState<'Newest' | 'Best'>('Newest', { const [sort, setSort] = usePersistentState<'Newest' | 'Best'>('Newest', {
@ -175,16 +174,6 @@ const CommentsTabContent = memo(function CommentsTabContent(props: {
</Row> </Row>
) )
// console.log('answer response:: ', answerResponse)
// sortedComments.map((comment, index) =>
// console.log(
// index,
// ',',
// comment.content.content[0].content[0].text,
// ':',
// dayjs(comment.createdTime).format('MM/DD/YY H:mm')
// )
// )
if (contract.outcomeType === 'FREE_RESPONSE') { if (contract.outcomeType === 'FREE_RESPONSE') {
return ( return (
<> <>

View File

@ -1,6 +1,6 @@
import clsx from 'clsx' import clsx from 'clsx'
import { useRouter, NextRouter } from 'next/router' import { useRouter, NextRouter } from 'next/router'
import { ReactNode, useState } from 'react' import { ReactNode, useEffect, useState } from 'react'
import { track } from '@amplitude/analytics-browser' import { track } from '@amplitude/analytics-browser'
import { Col } from './col' import { Col } from './col'
import { Tooltip } from 'web/components/tooltip' import { Tooltip } from 'web/components/tooltip'

View File

@ -1,4 +1,4 @@
import React, { memo, useEffect, useMemo, useState } from 'react' import React, { memo, useEffect, useMemo, useRef, useState } from 'react'
import { ArrowLeftIcon } from '@heroicons/react/outline' import { ArrowLeftIcon } from '@heroicons/react/outline'
import dayjs from 'dayjs' import dayjs from 'dayjs'
@ -209,11 +209,11 @@ export function ContractPageContent(
const [answerResponse, setAnswerResponse] = useState<Answer | undefined>( const [answerResponse, setAnswerResponse] = useState<Answer | undefined>(
undefined undefined
) )
const onAnswerCommentClick = useEvent((answer: Answer) => { const onAnswerCommentClick = useEvent((answer: Answer) => {
setAnswerResponse(answer) setAnswerResponse(answer)
answerRef.current.scrollIntoView({ behavior: 'smooth' })
}) })
const answerRef = useRef(null)
const onCancelAnswerResponse = useEvent(() => setAnswerResponse(undefined)) const onCancelAnswerResponse = useEvent(() => setAnswerResponse(undefined))
return ( return (
@ -293,14 +293,16 @@ export function ContractPageContent(
userBets={userBets} userBets={userBets}
/> />
<ContractTabs <div ref={answerRef}>
contract={contract} <ContractTabs
bets={bets} contract={contract}
userBets={userBets} bets={bets}
comments={comments} userBets={userBets}
answerResponse={answerResponse} comments={comments}
onCancelAnswerResponse={onCancelAnswerResponse} answerResponse={answerResponse}
/> onCancelAnswerResponse={onCancelAnswerResponse}
/>
</div>
</Col> </Col>
{!isCreator && <RecommendedContractsWidget contract={contract} />} {!isCreator && <RecommendedContractsWidget contract={contract} />}
<ScrollToTopButton className="fixed bottom-16 right-2 z-20 lg:bottom-2 xl:hidden" /> <ScrollToTopButton className="fixed bottom-16 right-2 z-20 lg:bottom-2 xl:hidden" />