Merge branch 'feat/ui-0.5.0' of git.backyard.segmentfault.com:opensource/answer into feat/ui-0.5.0

This commit is contained in:
shuai 2022-11-29 11:21:00 +08:00
commit 4a93a59c56
4 changed files with 19 additions and 5 deletions

View File

@ -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,
comment_id: commentId,
page: pageIndex,
page_size: pageSize,
});

View File

@ -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>
);
};

View File

@ -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>
);
};

View File

@ -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.comment_id;
}
return useSWR<Type.ListResult>(
`/answer/api/v1/comment/page?${qs.stringify(params, {