You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@answer.apache.org by sh...@apache.org on 2024/03/18 03:03:40 UTC

(incubator-answer) branch test updated: Feat/1.3.0/UI (#856)

This is an automated email from the ASF dual-hosted git repository.

shuai pushed a commit to branch test
in repository https://gitbox.apache.org/repos/asf/incubator-answer.git


The following commit(s) were added to refs/heads/test by this push:
     new 212a59a1 Feat/1.3.0/UI (#856)
212a59a1 is described below

commit 212a59a1128be8d02b29e8da66b2b7b57c1d6069
Author: dashuai <li...@sifou.com>
AuthorDate: Mon Mar 18 11:03:32 2024 +0800

    Feat/1.3.0/UI (#856)
---
 ui/src/components/Editor/ToolBars/image.tsx          | 20 ++++++++++++++++----
 ui/src/i18n/init.ts                                  |  8 ++++----
 .../pages/Review/components/EditPostModal/index.tsx  |  1 +
 3 files changed, 21 insertions(+), 8 deletions(-)

diff --git a/ui/src/components/Editor/ToolBars/image.tsx b/ui/src/components/Editor/ToolBars/image.tsx
index 95737db6..1bc429a0 100644
--- a/ui/src/components/Editor/ToolBars/image.tsx
+++ b/ui/src/components/Editor/ToolBars/image.tsx
@@ -167,17 +167,29 @@ const Image = ({ editorInstance }) => {
     }
     event.preventDefault();
 
-    const newHtml = new DOMParser()
+    let innerText = '';
+    const allPTag = new DOMParser()
       .parseFromString(
         htmlStr.replace(
           /<img([\s\S]*?) src\s*=\s*(['"])([\s\S]*?)\2([^>]*)>/gi,
-          `<p>\n![${t('image.text')}]($3)\n</p>`,
+          `<p>![${t('image.text')}]($3)\n\n</p>`,
         ),
         'text/html',
       )
-      .querySelector('body')?.innerText as string;
+      .querySelectorAll('body p');
+
+    allPTag.forEach((p, index) => {
+      const text = p.textContent || '';
+      if (text !== '') {
+        if (index === allPTag.length - 1) {
+          innerText += `${p.textContent}`;
+        } else {
+          innerText += `${p.textContent}${text.endsWith('\n') ? '' : '\n\n'}`;
+        }
+      }
+    });
 
-    editor.replaceSelection(newHtml);
+    editor.replaceSelection(innerText);
   };
   const handleClick = () => {
     if (!link.value) {
diff --git a/ui/src/i18n/init.ts b/ui/src/i18n/init.ts
index 66d9576e..03f775cb 100644
--- a/ui/src/i18n/init.ts
+++ b/ui/src/i18n/init.ts
@@ -21,7 +21,7 @@ import { initReactI18next } from 'react-i18next';
 
 import i18next from 'i18next';
 import en_US from '@i18n/en_US.yaml';
-// import zh_CN from '@i18n/zh_CN.yaml';
+import zh_CN from '@i18n/zh_CN.yaml';
 
 import { DEFAULT_LANG, LANG_RESOURCE_STORAGE_KEY } from '@/common/constants';
 import Storage from '@/utils/storage';
@@ -34,9 +34,9 @@ const initResources = {
   en_US: {
     translation: en_US.ui,
   },
-  // zh_CN: {
-  //   translation: zh_CN.ui,
-  // },
+  zh_CN: {
+    translation: zh_CN.ui,
+  },
 };
 
 const storageLang = Storage.get(LANG_RESOURCE_STORAGE_KEY);
diff --git a/ui/src/pages/Review/components/EditPostModal/index.tsx b/ui/src/pages/Review/components/EditPostModal/index.tsx
index e35a82ca..4190240c 100644
--- a/ui/src/pages/Review/components/EditPostModal/index.tsx
+++ b/ui/src/pages/Review/components/EditPostModal/index.tsx
@@ -76,6 +76,7 @@ const Index: FC<Props> = ({
     if (bol) {
       callback?.();
     }
+    setFormData(initFormData);
     handleClose();
     setLoaded(false);
   };