feat: delete content can recover

This commit is contained in:
shuai
2023-09-26 14:06:28 +08:00
parent ab602ed001
commit 7cdc4c8c62
6 changed files with 66 additions and 14 deletions
+1
View File
@@ -56,6 +56,7 @@ export interface TagInfo extends TagBase {
updated_at?;
main_tag_slug_name?: string;
excerpt?;
status: string;
}
export interface QuestionParams extends ImgCodeReq {
title: string;
+5 -5
View File
@@ -13,8 +13,8 @@ import {
editCheck,
reopenQuestion,
questionOpetation,
changeQuestionStatus,
changeAnswerStatus,
unDeleteAnswer,
unDeleteQuestion,
} from '@/services';
import { tryNormalLogged } from '@/utils/guard';
import { floppyNavigation } from '@/utils';
@@ -151,13 +151,13 @@ const Index: FC<IProps> = ({
confirmText: t('undelete', { keyPrefix: 'btns' }),
onConfirm: () => {
if (type === 'question') {
changeQuestionStatus(qid, 'available').then(() => {
callback?.('all');
unDeleteQuestion(qid).then(() => {
callback?.('default');
});
}
if (type === 'answer') {
changeAnswerStatus(aid, 'available').then(() => {
unDeleteAnswer(aid).then(() => {
callback?.('all');
});
}
+1 -1
View File
@@ -47,7 +47,7 @@ const Index: FC = () => {
const { data: tagResp, isLoading } = useTagInfo({ name: curTagName });
const { data: listData, isLoading: listLoading } = useQuestionList(reqParams);
const { data: followResp } = useFollow(tagFollow);
const { data: synonymsRes } = useQuerySynonymsTags(tagInfo?.tag_id);
const { data: synonymsRes } = useQuerySynonymsTags(tagInfo?.tag_id, '');
const toggleFollow = () => {
if (!guard.tryNormalLogged(true)) {
return;
+32 -5
View File
@@ -1,5 +1,5 @@
import { useState, useEffect } from 'react';
import { Row, Col, Button, Card } from 'react-bootstrap';
import { Alert, Row, Col, Button, Card } from 'react-bootstrap';
import { useParams, useNavigate, Link, useLocation } from 'react-router-dom';
import { useTranslation } from 'react-i18next';
@@ -13,6 +13,7 @@ import {
saveSynonymsTags,
deleteTag,
editCheck,
unDeleteTag,
} from '@/services';
import { pathFactory } from '@/router/pathFactory';
import { loggedUserInfoStore, toastStore } from '@/stores';
@@ -23,10 +24,15 @@ const TagIntroduction = () => {
const isLogged = Boolean(userInfo?.access_token);
const [isEdit, setEditState] = useState(false);
const { tagName } = useParams();
const { data: tagInfo } = useTagInfo({ name: tagName });
const { data: tagInfo, mutate: refreshTagInfo } = useTagInfo({
name: tagName,
});
const { t } = useTranslation('translation', { keyPrefix: 'tag_info' });
const navigate = useNavigate();
const { data: synonymsData, mutate } = useQuerySynonymsTags(tagInfo?.tag_id);
const { data: synonymsData, mutate } = useQuerySynonymsTags(
tagInfo?.tag_id,
tagInfo?.status,
);
let pageTitle = '';
if (tagInfo) {
pageTitle = `'${tagInfo.display_name}' ${t('tag_wiki', {
@@ -118,7 +124,7 @@ const TagIntroduction = () => {
confirmBtnVariant: 'danger',
onConfirm: () => {
deleteTag(tagInfo.tag_id).then(() => {
navigate('/tags', { replace: true });
// navigate('/tags', { replace: true });
});
},
});
@@ -126,14 +132,35 @@ const TagIntroduction = () => {
const onAction = (params) => {
if (params.action === 'edit') {
handleEditTag();
} else if (params.action === 'delete') {
}
if (params.action === 'delete') {
handleDeleteTag();
}
if (params.action === 'undelete') {
Modal.confirm({
title: t('undelete_title', { keyPrefix: 'delete' }),
content: t('undelete_desc', { keyPrefix: 'delete' }),
cancelBtnVariant: 'link',
confirmBtnVariant: 'danger',
confirmText: t('undelete', { keyPrefix: 'btns' }),
onConfirm: () => {
unDeleteTag(tagInfo.tag_id).then(() => {
// undo
refreshTagInfo();
});
},
});
}
};
return (
<Row className="pt-4 mb-5">
<Col className="page-main flex-auto">
{tagInfo?.status === 'deleted' && (
<Alert variant="danger" className="mb-4">
{t('post_deleted', { keyPrefix: 'messages' })}
</Alert>
)}
<h3 className="mb-3">
<Link
to={pathFactory.tagLanding(tagInfo.slug_name)}
+12
View File
@@ -73,3 +73,15 @@ export const putInviteUser = (
...imgCode,
});
};
export const unDeleteAnswer = (id) => {
return request.post('/answer/api/v1/answer/recover', {
answer_id: id,
});
};
export const unDeleteQuestion = (qid) => {
return request.post('/answer/api/v1/question/recover', {
question_id: qid,
});
};
+15 -3
View File
@@ -13,8 +13,13 @@ export const modifyTag = (params) => {
return request.put('/answer/api/v1/tag', params);
};
export const useQuerySynonymsTags = (tagId) => {
const apiUrl = tagId ? `/answer/api/v1/tag/synonyms?tag_id=${tagId}` : '';
export const useQuerySynonymsTags = (tagId, status) => {
const apiUrl =
status === 'deleted'
? ''
: tagId
? `/answer/api/v1/tag/synonyms?tag_id=${tagId}`
: '';
return useSWR<{
synonyms: Type.SynonymsTag[];
member_actions?: Type.MemberActionItem[];
@@ -47,10 +52,11 @@ export const useTagInfo = ({ id = '', name = '' }) => {
name = encodeURIComponent(name);
apiUrl = `/answer/api/v1/tag?name=${name}`;
}
const { data, error } = useSWR<Type.TagInfo>(apiUrl, (url) =>
const { data, error, mutate } = useSWR<Type.TagInfo>(apiUrl, (url) =>
request.get(url, { allow404: true }),
);
return {
mutate,
data,
isLoading: !data && !error,
error,
@@ -70,3 +76,9 @@ export const createTag = (params: Type.TagBase) => {
const apiUrl = '/answer/api/v1/tag';
return request.post<Type.TagInfo>(apiUrl, params);
};
export const unDeleteTag = (id) => {
return request.post('/answer/api/v1/tag/recover', {
tag_id: id,
});
};