mirror of https://gitee.com/answerdev/answer.git
Merge branch 'feat/ui-0.5.0' into 'test'
fix(review): add anwer edit summery and auto rollback review item See merge request opensource/answer!301
This commit is contained in:
commit
9dcf2505f4
|
@ -69,6 +69,7 @@ export interface AnswerParams {
|
|||
html: string;
|
||||
question_id: string;
|
||||
id: string;
|
||||
edit_summary?: string;
|
||||
}
|
||||
|
||||
export interface LoginReqParams {
|
||||
|
|
|
@ -62,6 +62,13 @@ const Ask = () => {
|
|||
...formData,
|
||||
answer: { ...formData.answer, value },
|
||||
});
|
||||
const handleSummaryChange = (evt) => {
|
||||
const v = evt.currentTarget.value;
|
||||
setFormData({
|
||||
...formData,
|
||||
description: { ...formData.description, value: v },
|
||||
});
|
||||
};
|
||||
|
||||
const checkValidated = (): boolean => {
|
||||
let bol = true;
|
||||
|
@ -100,6 +107,7 @@ const Ask = () => {
|
|||
html: editorRef.current.getHtml(),
|
||||
question_id: qid,
|
||||
id: aid,
|
||||
edit_summary: formData.description.value,
|
||||
};
|
||||
modifyAnswer(params).then(() => {
|
||||
navigate(`/questions/${qid}/${aid}`);
|
||||
|
@ -198,6 +206,7 @@ const Ask = () => {
|
|||
<Form.Label>{t('form.fields.edit_summary.label')}</Form.Label>
|
||||
<Form.Control
|
||||
type="text"
|
||||
onChange={handleSummaryChange}
|
||||
defaultValue={formData.description.value}
|
||||
isInvalid={formData.description.isInvalid}
|
||||
placeholder={t('form.fields.edit_summary.placeholder')}
|
||||
|
|
|
@ -4,7 +4,7 @@ import { Link } from 'react-router-dom';
|
|||
import { useTranslation } from 'react-i18next';
|
||||
|
||||
import { BaseUserCard, FormatTime, Empty, DiffContent } from '@/components';
|
||||
import { useReviewList, revisionAudit } from '@/services';
|
||||
import { getReviewList, revisionAudit } from '@/services';
|
||||
import { pathFactory } from '@/router/pathFactory';
|
||||
import type * as Type from '@/common/interface';
|
||||
|
||||
|
@ -13,24 +13,46 @@ const Index: FC = () => {
|
|||
const [isLoading, setIsLoading] = useState(false);
|
||||
const [noTasks, setNoTasks] = useState(false);
|
||||
const [page, setPage] = useState(1);
|
||||
const { data: reviewResp, mutate: mutateList } = useReviewList(page);
|
||||
const [reviewResp, setReviewResp] = useState<Type.ReviewResp>();
|
||||
const ro = reviewResp?.list[0];
|
||||
const { info, type, unreviewed_info } = ro || {
|
||||
info: null,
|
||||
type: '',
|
||||
unreviewed_info: null,
|
||||
};
|
||||
const reviewInfo = unreviewed_info?.content;
|
||||
const mutateNextPage = () => {
|
||||
const count = reviewResp?.count;
|
||||
if (count && page < count) {
|
||||
setPage(page + 1);
|
||||
} else {
|
||||
const resolveNextOne = (resp, pageNumber) => {
|
||||
const { count, list = [] } = resp;
|
||||
// auto rollback
|
||||
if (!list.length && count && page !== 1) {
|
||||
pageNumber = 1;
|
||||
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);
|
||||
}
|
||||
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 = () => {
|
||||
mutateNextPage();
|
||||
queryNextOne(page + 1);
|
||||
};
|
||||
const handlingApprove = () => {
|
||||
if (!unreviewed_info) {
|
||||
|
@ -39,7 +61,7 @@ const Index: FC = () => {
|
|||
setIsLoading(true);
|
||||
revisionAudit(unreviewed_info.id, 'approve')
|
||||
.then(() => {
|
||||
mutateList();
|
||||
queryNextOne(page);
|
||||
})
|
||||
.catch((ex) => {
|
||||
console.log('ex: ', ex);
|
||||
|
@ -55,7 +77,7 @@ const Index: FC = () => {
|
|||
setIsLoading(true);
|
||||
revisionAudit(unreviewed_info.id, 'reject')
|
||||
.then(() => {
|
||||
mutateList();
|
||||
queryNextOne(page);
|
||||
})
|
||||
.catch((ex) => {
|
||||
console.log('ex: ', ex);
|
||||
|
@ -93,14 +115,8 @@ const Index: FC = () => {
|
|||
editSummary ||= t('edit_tag');
|
||||
}
|
||||
useEffect(() => {
|
||||
if (!reviewResp) {
|
||||
return;
|
||||
}
|
||||
window.scrollTo({ top: 0 });
|
||||
if (!reviewResp.list || !reviewResp.list.length) {
|
||||
setNoTasks(true);
|
||||
}
|
||||
}, [reviewResp]);
|
||||
queryNextOne(page);
|
||||
}, []);
|
||||
return (
|
||||
<Container className="pt-2 mt-4 mb-5">
|
||||
<Row>
|
||||
|
|
|
@ -1,5 +1,3 @@
|
|||
import useSWR from 'swr';
|
||||
|
||||
import request from '@/utils/request';
|
||||
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 { data, error, mutate } = useSWR<Type.ReviewResp, Error>(
|
||||
apiUrl,
|
||||
request.instance.get,
|
||||
);
|
||||
return {
|
||||
data,
|
||||
isLoading: !data && !error,
|
||||
error,
|
||||
mutate,
|
||||
};
|
||||
return request.get<Type.ReviewResp>(apiUrl);
|
||||
};
|
||||
|
|
Loading…
Reference in New Issue