A Q&A platform software for teams at any scales. Whether it's a community forum, help center, or knowledge management platform, you can always count on Apache Answer.
fix: add `commentId` for query target comment
haitao(lj)3ed4b5898017
diff --git a/ui/src/components/Comment/index.tsx b/ui/src/components/Comment/index.tsxindex d76f94d6..f96ca77e 100644--- a/ui/src/components/Comment/index.tsx+++ b/ui/src/components/Comment/index.tsx@@ -24,7 +24,7 @@ import { Form, ActionBar, Reply } from './components';import './index.scss';-const Comment = ({ objectId, mode }) => {+const Comment = ({ objectId, mode, commentId }) => {const pageUsers = usePageUsers();const [pageIndex, setPageIndex] = useState(0);const [comments, setComments] = useState<any>([]);@@ -32,6 +32,7 @@ const Comment = ({ objectId, mode }) => {const pageSize = pageIndex === 0 ? 3 : 15;const { data, mutate } = useQueryComments({object_id: objectId,+ commentId,page: pageIndex,page_size: pageSize,});diff --git a/ui/src/pages/Questions/Detail/components/Answer/index.tsx b/ui/src/pages/Questions/Detail/components/Answer/index.tsxindex 43e8627b..d1b76be7 100644--- a/ui/src/pages/Questions/Detail/components/Answer/index.tsx+++ b/ui/src/pages/Questions/Detail/components/Answer/index.tsx@@ -1,7 +1,7 @@import { memo, FC, useEffect, useRef } from 'react';import { Row, Col, Button } from 'react-bootstrap';import { useTranslation } from 'react-i18next';-import { Link } from 'react-router-dom';+import { Link, useSearchParams } from 'react-router-dom';import {Actions,@@ -37,6 +37,7 @@ const Index: FC<Props> = ({const { t } = useTranslation('translation', {keyPrefix: 'question_detail',});+ const [searchParams] = useSearchParams();const answerRef = useRef<HTMLDivElement>(null);const acceptAnswer = () => {acceptanceAnswer({@@ -152,7 +153,11 @@ const Index: FC<Props> = ({</Col></Row>- <Comment objectId={data.id} mode="answer" />+ <Comment+ objectId={data.id}+ mode="answer"+ commentId={searchParams.get('commentId')}+ /></div>);};diff --git a/ui/src/pages/Questions/Detail/components/Question/index.tsx b/ui/src/pages/Questions/Detail/components/Question/index.tsxindex 812cb306..92bdd235 100644--- a/ui/src/pages/Questions/Detail/components/Question/index.tsx+++ b/ui/src/pages/Questions/Detail/components/Question/index.tsx@@ -1,5 +1,5 @@import { memo, FC, useState, useEffect, useRef } from 'react';-import { Link } from 'react-router-dom';+import { Link, useSearchParams } from 'react-router-dom';import { useTranslation } from 'react-i18next';import { Row, Col, Button } from 'react-bootstrap';@@ -26,6 +26,7 @@ const Index: FC<Props> = ({ data, initPage, hasAnswer, isLogged }) => {const { t } = useTranslation('translation', {keyPrefix: 'question_detail',});+ const [searchParams] = useSearchParams();const [followed, setFollowed] = useState(data?.is_followed);const ref = useRef<HTMLDivElement>(null);@@ -164,7 +165,11 @@ const Index: FC<Props> = ({ data, initPage, hasAnswer, isLogged }) => {</Col></Row>- <Comment objectId={data?.id} mode="question" />+ <Comment+ objectId={data?.id}+ mode="question"+ commentId={searchParams.get('commentId')}+ /></div>);};diff --git a/ui/src/services/common.ts b/ui/src/services/common.tsindex 43437d6e..54ea69dc 100644--- a/ui/src/services/common.ts+++ b/ui/src/services/common.ts@@ -38,6 +38,9 @@ export const useQueryComments = (params) => {if (params.page === 0) {params.query_cond = 'vote';params.page = 1;+ } else {+ // only first page need commentId+ delete params.commentId;}return useSWR<Type.ListResult>(`/answer/api/v1/comment/page?${qs.stringify(params, {