A Q&A platform software for teams at any scales. Whether it's a community forum, help center, or knowledge management platform, you can always count on Apache Answer.
fix(Question): Fix the problem that the captcha is not displayed correctly when saving questions, adding answers, and adding comments.
haitaood7e4c347e668
diff --git a/ui/src/components/Comment/index.tsx b/ui/src/components/Comment/index.tsxindex da3f5d84..f9b8d75e 100644--- a/ui/src/components/Comment/index.tsx+++ b/ui/src/components/Comment/index.tsx@@ -164,28 +164,40 @@ const Comment = ({ objectId, mode, commentId }) => {};addCaptcha.resolveCaptchaReq(req);- return addComment(req).then((res) => {- if (item.type === 'reply') {- const index = comments.findIndex(- (comment) => comment.comment_id === item.comment_id,- );- comments[index].showReply = false;- comments.splice(index + 1, 0, res);- setComments([...comments]);- } else {- setComments([- ...comments.map((comment) => {- if (comment.comment_id === item.comment_id) {- comment.showReply = false;- }- return comment;- }),- res,- ]);- }+ return addComment(req)+ .then(async (res) => {+ await addCaptcha.close();+ if (item.type === 'reply') {+ const index = comments.findIndex(+ (comment) => comment.comment_id === item.comment_id,+ );+ comments[index].showReply = false;+ comments.splice(index + 1, 0, res);+ setComments([...comments]);+ } else {+ setComments([+ ...comments.map((comment) => {+ if (comment.comment_id === item.comment_id) {+ comment.showReply = false;+ }+ return comment;+ }),+ res,+ ]);+ }- setVisibleComment(false);- });+ setVisibleComment(false);+ })+ .catch((ex) => {+ if (ex.isError) {+ const captchaErr = addCaptcha.handleCaptchaError(ex.list);+ // If it is not a CAPTCHA error, leave it to the subsequent error handling logic to continue processing.+ if (!captchaErr || captchaErr.error_msg !== ex.msg) {+ return Promise.reject(ex);+ }+ }+ return Promise.resolve();+ });});};diff --git a/ui/src/hooks/useCaptchaModal/index.tsx b/ui/src/hooks/useCaptchaModal/index.tsxindex 034240e6..b8748665 100644--- a/ui/src/hooks/useCaptchaModal/index.tsx+++ b/ui/src/hooks/useCaptchaModal/index.tsx@@ -82,7 +82,7 @@ const Index = (captchaKey: CaptchaKey) => {resetCapture();}const p = new Promise<void>((resolve) => {- setTimeout(resolve);+ setTimeout(resolve, 50);});return p;};@@ -116,6 +116,8 @@ const Index = (captchaKey: CaptchaKey) => {});close();}+ // Assist business logic in filtering CAPTCHA error messages when necessary+ return captchaErr;};const handleChange = (evt) => {diff --git a/ui/src/pages/Questions/Ask/index.tsx b/ui/src/pages/Questions/Ask/index.tsxindex 03b2cda6..cde53f73 100644--- a/ui/src/pages/Questions/Ask/index.tsx+++ b/ui/src/pages/Questions/Ask/index.tsx@@ -253,6 +253,7 @@ const Ask = () => {content: formData.content.value,tags: formData.tags.value,};+if (isEdit) {editCaptcha.check(() => {const ep = {@@ -294,6 +295,7 @@ const Ask = () => {answer_content: formData.answer_content.value,}).catch((err) => {if (err.isError) {+ saveCaptcha.handleCaptchaError(err.list);const data = handleFormError(err, formData);setFormData({ ...data });}@@ -301,6 +303,7 @@ const Ask = () => {} else {res = await saveQuestion(params).catch((err) => {if (err.isError) {+ saveCaptcha.handleCaptchaError(err.list);const data = handleFormError(err, formData);setFormData({ ...data });}@@ -309,6 +312,7 @@ const Ask = () => {const id = res?.id || res?.question?.id;if (id) {+ await saveCaptcha.close();if (checked) {navigate(pathFactory.questionLanding(id, res?.question?.url_title));} else {