mirror of https://gitee.com/answerdev/answer.git
fix: add `commentId` for query target comment
This commit is contained in:
parent
9af3067e8f
commit
3ed4b58980
|
@ -24,7 +24,7 @@ import { Form, ActionBar, Reply } from './components';
|
||||||
|
|
||||||
import './index.scss';
|
import './index.scss';
|
||||||
|
|
||||||
const Comment = ({ objectId, mode }) => {
|
const Comment = ({ objectId, mode, commentId }) => {
|
||||||
const pageUsers = usePageUsers();
|
const pageUsers = usePageUsers();
|
||||||
const [pageIndex, setPageIndex] = useState(0);
|
const [pageIndex, setPageIndex] = useState(0);
|
||||||
const [comments, setComments] = useState<any>([]);
|
const [comments, setComments] = useState<any>([]);
|
||||||
|
@ -32,6 +32,7 @@ const Comment = ({ objectId, mode }) => {
|
||||||
const pageSize = pageIndex === 0 ? 3 : 15;
|
const pageSize = pageIndex === 0 ? 3 : 15;
|
||||||
const { data, mutate } = useQueryComments({
|
const { data, mutate } = useQueryComments({
|
||||||
object_id: objectId,
|
object_id: objectId,
|
||||||
|
commentId,
|
||||||
page: pageIndex,
|
page: pageIndex,
|
||||||
page_size: pageSize,
|
page_size: pageSize,
|
||||||
});
|
});
|
||||||
|
|
|
@ -1,7 +1,7 @@
|
||||||
import { memo, FC, useEffect, useRef } from 'react';
|
import { memo, FC, useEffect, useRef } from 'react';
|
||||||
import { Row, Col, Button } from 'react-bootstrap';
|
import { Row, Col, Button } from 'react-bootstrap';
|
||||||
import { useTranslation } from 'react-i18next';
|
import { useTranslation } from 'react-i18next';
|
||||||
import { Link } from 'react-router-dom';
|
import { Link, useSearchParams } from 'react-router-dom';
|
||||||
|
|
||||||
import {
|
import {
|
||||||
Actions,
|
Actions,
|
||||||
|
@ -37,6 +37,7 @@ const Index: FC<Props> = ({
|
||||||
const { t } = useTranslation('translation', {
|
const { t } = useTranslation('translation', {
|
||||||
keyPrefix: 'question_detail',
|
keyPrefix: 'question_detail',
|
||||||
});
|
});
|
||||||
|
const [searchParams] = useSearchParams();
|
||||||
const answerRef = useRef<HTMLDivElement>(null);
|
const answerRef = useRef<HTMLDivElement>(null);
|
||||||
const acceptAnswer = () => {
|
const acceptAnswer = () => {
|
||||||
acceptanceAnswer({
|
acceptanceAnswer({
|
||||||
|
@ -152,7 +153,11 @@ const Index: FC<Props> = ({
|
||||||
</Col>
|
</Col>
|
||||||
</Row>
|
</Row>
|
||||||
|
|
||||||
<Comment objectId={data.id} mode="answer" />
|
<Comment
|
||||||
|
objectId={data.id}
|
||||||
|
mode="answer"
|
||||||
|
commentId={searchParams.get('commentId')}
|
||||||
|
/>
|
||||||
</div>
|
</div>
|
||||||
);
|
);
|
||||||
};
|
};
|
||||||
|
|
|
@ -1,5 +1,5 @@
|
||||||
import { memo, FC, useState, useEffect, useRef } from 'react';
|
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 { useTranslation } from 'react-i18next';
|
||||||
import { Row, Col, Button } from 'react-bootstrap';
|
import { Row, Col, Button } from 'react-bootstrap';
|
||||||
|
|
||||||
|
@ -26,6 +26,7 @@ const Index: FC<Props> = ({ data, initPage, hasAnswer, isLogged }) => {
|
||||||
const { t } = useTranslation('translation', {
|
const { t } = useTranslation('translation', {
|
||||||
keyPrefix: 'question_detail',
|
keyPrefix: 'question_detail',
|
||||||
});
|
});
|
||||||
|
const [searchParams] = useSearchParams();
|
||||||
const [followed, setFollowed] = useState(data?.is_followed);
|
const [followed, setFollowed] = useState(data?.is_followed);
|
||||||
const ref = useRef<HTMLDivElement>(null);
|
const ref = useRef<HTMLDivElement>(null);
|
||||||
|
|
||||||
|
@ -164,7 +165,11 @@ const Index: FC<Props> = ({ data, initPage, hasAnswer, isLogged }) => {
|
||||||
</Col>
|
</Col>
|
||||||
</Row>
|
</Row>
|
||||||
|
|
||||||
<Comment objectId={data?.id} mode="question" />
|
<Comment
|
||||||
|
objectId={data?.id}
|
||||||
|
mode="question"
|
||||||
|
commentId={searchParams.get('commentId')}
|
||||||
|
/>
|
||||||
</div>
|
</div>
|
||||||
);
|
);
|
||||||
};
|
};
|
||||||
|
|
|
@ -38,6 +38,9 @@ export const useQueryComments = (params) => {
|
||||||
if (params.page === 0) {
|
if (params.page === 0) {
|
||||||
params.query_cond = 'vote';
|
params.query_cond = 'vote';
|
||||||
params.page = 1;
|
params.page = 1;
|
||||||
|
} else {
|
||||||
|
// only first page need commentId
|
||||||
|
delete params.commentId;
|
||||||
}
|
}
|
||||||
return useSWR<Type.ListResult>(
|
return useSWR<Type.ListResult>(
|
||||||
`/answer/api/v1/comment/page?${qs.stringify(params, {
|
`/answer/api/v1/comment/page?${qs.stringify(params, {
|
||||||
|
|
Loading…
Reference in New Issue