fix(review): add anwer edit summery and auto rollback review item

This commit is contained in:
haitao(lj) 2022-12-01 11:57:57 +08:00
parent b5955316d9
commit a12a60b3b2
4 changed files with 47 additions and 32 deletions

View File

@ -69,6 +69,7 @@ export interface AnswerParams {
html: string; html: string;
question_id: string; question_id: string;
id: string; id: string;
edit_summary?: string;
} }
export interface LoginReqParams { export interface LoginReqParams {

View File

@ -62,6 +62,13 @@ const Ask = () => {
...formData, ...formData,
answer: { ...formData.answer, value }, answer: { ...formData.answer, value },
}); });
const handleSummaryChange = (evt) => {
const v = evt.currentTarget.value;
setFormData({
...formData,
description: { ...formData.description, value: v },
});
};
const checkValidated = (): boolean => { const checkValidated = (): boolean => {
let bol = true; let bol = true;
@ -100,6 +107,7 @@ const Ask = () => {
html: editorRef.current.getHtml(), html: editorRef.current.getHtml(),
question_id: qid, question_id: qid,
id: aid, id: aid,
edit_summary: formData.description.value,
}; };
modifyAnswer(params).then(() => { modifyAnswer(params).then(() => {
navigate(`/questions/${qid}/${aid}`); navigate(`/questions/${qid}/${aid}`);
@ -198,6 +206,7 @@ const Ask = () => {
<Form.Label>{t('form.fields.edit_summary.label')}</Form.Label> <Form.Label>{t('form.fields.edit_summary.label')}</Form.Label>
<Form.Control <Form.Control
type="text" type="text"
onChange={handleSummaryChange}
defaultValue={formData.description.value} defaultValue={formData.description.value}
isInvalid={formData.description.isInvalid} isInvalid={formData.description.isInvalid}
placeholder={t('form.fields.edit_summary.placeholder')} placeholder={t('form.fields.edit_summary.placeholder')}

View File

@ -4,7 +4,7 @@ import { Link } from 'react-router-dom';
import { useTranslation } from 'react-i18next'; import { useTranslation } from 'react-i18next';
import { BaseUserCard, FormatTime, Empty, DiffContent } from '@/components'; import { BaseUserCard, FormatTime, Empty, DiffContent } from '@/components';
import { useReviewList, revisionAudit } from '@/services'; import { getReviewList, revisionAudit } from '@/services';
import { pathFactory } from '@/router/pathFactory'; import { pathFactory } from '@/router/pathFactory';
import type * as Type from '@/common/interface'; import type * as Type from '@/common/interface';
@ -13,24 +13,46 @@ const Index: FC = () => {
const [isLoading, setIsLoading] = useState(false); const [isLoading, setIsLoading] = useState(false);
const [noTasks, setNoTasks] = useState(false); const [noTasks, setNoTasks] = useState(false);
const [page, setPage] = useState(1); const [page, setPage] = useState(1);
const { data: reviewResp, mutate: mutateList } = useReviewList(page); const [reviewResp, setReviewResp] = useState<Type.ReviewResp>();
const ro = reviewResp?.list[0]; const ro = reviewResp?.list[0];
const { info, type, unreviewed_info } = ro || { const { info, type, unreviewed_info } = ro || {
info: null, info: null,
type: '', type: '',
unreviewed_info: null, unreviewed_info: null,
}; };
const reviewInfo = unreviewed_info?.content; const resolveNextOne = (resp, pageNumber) => {
const mutateNextPage = () => { const { count, list = [] } = resp;
const count = reviewResp?.count; // auto rollback
if (count && page < count) { if (!list.length && count && page !== 1) {
setPage(page + 1); pageNumber = 1;
} else { setPage(pageNumber);
// eslint-disable-next-line @typescript-eslint/no-use-before-define
queryNextOne(pageNumber);
return;
}
if (pageNumber !== page) {
setPage(pageNumber);
}
setReviewResp(resp);
if (!list.length) {
setNoTasks(true); setNoTasks(true);
} }
setTimeout(() => {
window.scrollTo({ top: 0 });
}, 150);
}; };
const queryNextOne = (pageNumber) => {
getReviewList(pageNumber)
.then((resp) => {
resolveNextOne(resp, pageNumber);
})
.catch((ex) => {
console.log('ex: ', ex);
});
};
const reviewInfo = unreviewed_info?.content;
const handlingSkip = () => { const handlingSkip = () => {
mutateNextPage(); queryNextOne(page + 1);
}; };
const handlingApprove = () => { const handlingApprove = () => {
if (!unreviewed_info) { if (!unreviewed_info) {
@ -39,7 +61,7 @@ const Index: FC = () => {
setIsLoading(true); setIsLoading(true);
revisionAudit(unreviewed_info.id, 'approve') revisionAudit(unreviewed_info.id, 'approve')
.then(() => { .then(() => {
mutateList(); queryNextOne(page);
}) })
.catch((ex) => { .catch((ex) => {
console.log('ex: ', ex); console.log('ex: ', ex);
@ -55,7 +77,7 @@ const Index: FC = () => {
setIsLoading(true); setIsLoading(true);
revisionAudit(unreviewed_info.id, 'reject') revisionAudit(unreviewed_info.id, 'reject')
.then(() => { .then(() => {
mutateList(); queryNextOne(page);
}) })
.catch((ex) => { .catch((ex) => {
console.log('ex: ', ex); console.log('ex: ', ex);
@ -93,14 +115,8 @@ const Index: FC = () => {
editSummary ||= t('edit_tag'); editSummary ||= t('edit_tag');
} }
useEffect(() => { useEffect(() => {
if (!reviewResp) { queryNextOne(page);
return; }, []);
}
window.scrollTo({ top: 0 });
if (!reviewResp.list || !reviewResp.list.length) {
setNoTasks(true);
}
}, [reviewResp]);
return ( return (
<Container className="pt-2 mt-4 mb-5"> <Container className="pt-2 mt-4 mb-5">
<Row> <Row>

View File

@ -1,5 +1,3 @@
import useSWR from 'swr';
import request from '@/utils/request'; import request from '@/utils/request';
import * as Type from '@/common/interface'; import * as Type from '@/common/interface';
@ -16,16 +14,7 @@ export const revisionAudit = (id: string, operation: 'approve' | 'reject') => {
}); });
}; };
export const useReviewList = (page: number) => { export const getReviewList = (page: number) => {
const apiUrl = `/answer/api/v1/revisions/unreviewed?page=${page}`; const apiUrl = `/answer/api/v1/revisions/unreviewed?page=${page}`;
const { data, error, mutate } = useSWR<Type.ReviewResp, Error>( return request.get<Type.ReviewResp>(apiUrl);
apiUrl,
request.instance.get,
);
return {
data,
isLoading: !data && !error,
error,
mutate,
};
}; };