diff --git a/i18n/en_US.yaml b/i18n/en_US.yaml index 535fddf8..5dd61252 100644 --- a/i18n/en_US.yaml +++ b/i18n/en_US.yaml @@ -713,6 +713,10 @@ ui:

Are you sure you want to add another answer?

You could use the edit link to refine and improve your existing answer, instead.

empty: Answer cannot be empty. + reopen: + title: Reopen this post + content: Are you sure you want to reopen? + success: This post has been reopened delete: title: Delete this post question: >- diff --git a/ui/src/components/Operate/index.tsx b/ui/src/components/Operate/index.tsx index da27b7f4..846db738 100644 --- a/ui/src/components/Operate/index.tsx +++ b/ui/src/components/Operate/index.tsx @@ -6,7 +6,12 @@ import { useTranslation } from 'react-i18next'; import { Modal } from '@/components'; import { useReportModal, useToast } from '@/hooks'; import Share from '../Share'; -import { deleteQuestion, deleteAnswer, editCheck } from '@/services'; +import { + deleteQuestion, + deleteAnswer, + editCheck, + reopenQuestion, +} from '@/services'; import { tryNormalLogged } from '@/utils/guard'; interface IProps { @@ -32,7 +37,11 @@ const Index: FC = ({ const { t } = useTranslation('translation', { keyPrefix: 'delete' }); const toast = useToast(); const reportModal = useReportModal(); - const closeModal = useReportModal(); + + const refershQuestion = () => { + callback?.('default'); + }; + const closeModal = useReportModal(refershQuestion); const editUrl = type === 'answer' ? `/posts/${qid}/${aid}/edit` : `/posts/${qid}/edit`; @@ -106,6 +115,25 @@ const Index: FC = ({ }); }; + const handleReopen = () => { + Modal.confirm({ + title: t('title', { keyPrefix: 'question_detail.reopen' }), + content: t('content', { keyPrefix: 'question_detail.reopen' }), + cancelBtnVariant: 'link', + onConfirm: () => { + reopenQuestion({ + question_id: qid, + }).then(() => { + toast.onShow({ + msg: t('success', { keyPrefix: 'question_detail.reopen' }), + variant: 'success', + }); + refershQuestion(); + }); + }, + }); + }; + const handleAction = (action) => { if (!tryNormalLogged(true)) { return; @@ -121,6 +149,10 @@ const Index: FC = ({ if (action === 'close') { handleClose(); } + + if (action === 'reopen') { + handleReopen(); + } }; return ( diff --git a/ui/src/pages/Questions/Detail/index.tsx b/ui/src/pages/Questions/Detail/index.tsx index 2cdc40c0..8be1cbe8 100644 --- a/ui/src/pages/Questions/Detail/index.tsx +++ b/ui/src/pages/Questions/Detail/index.tsx @@ -89,6 +89,12 @@ const Index = () => { }, 1000); return; } + + if (type === 'default') { + window.scrollTo(0, 0); + getDetail(); + return; + } requestAnswers(); }; diff --git a/ui/src/services/common.ts b/ui/src/services/common.ts index 903c7aec..18e46490 100644 --- a/ui/src/services/common.ts +++ b/ui/src/services/common.ts @@ -248,3 +248,7 @@ export const changeEmailVerify = (params: { code: string }) => { export const getAppSettings = () => { return request.get('/answer/api/v1/siteinfo'); }; + +export const reopenQuestion = (params: { question_id: string }) => { + return request.put('/answer/api/v1/question/reopen', params); +};