shuashuai commented on code in PR #668:
URL: https://github.com/apache/incubator-answer/pull/668#discussion_r1423327310


##########
ui/src/pages/Admin/Write/index.tsx:
##########
@@ -56,6 +62,12 @@ const Index: FC = () => {
     },
   };
   const uiSchema: UISchema = {
+    restrict_answer: {
+      'ui:widget': 'switch',
+      'ui:options': {
+        label: t('required_tag.label'),

Review Comment:
   This should be
   ```
   label: t('restrict_answer.label')
   ```



##########
ui/src/pages/Questions/Detail/index.tsx:
##########
@@ -28,7 +28,7 @@ import {
 import { useTranslation } from 'react-i18next';
 
 import { Pagination, CustomSidebar } from '@/components';
-import { loggedUserInfoStore, toastStore } from '@/stores';
+import { loggedUserInfoStore, toastStore, writeSettingStore } from '@/stores';

Review Comment:
   The outer layer does not use writeSettingStore logic, so there is no need to 
adopt a transparent transmission method, just move the relevant logic directly 
to the inside of the WriteAnswer component.



##########
ui/src/pages/Admin/Write/index.tsx:
##########
@@ -92,13 +104,15 @@ const Index: FC = () => {
       recommend_tags,
       reserved_tags,
       required_tag: formData.required_tag.value,
+      restrict_answer: formData.restrict_answer.value,
     };
     postRequireAndReservedTag(reqParams)
       .then(() => {
         Toast.onShow({
           msg: t('update', { keyPrefix: 'toast' }),
           variant: 'success',
         });
+        writeSettingStore.getState().update(reqParams);
       })

Review Comment:
   Useless parameters do not need to be saved. Just need to save restrict_answer
   
   eg: writeSettingStore.getState().update({ restrict_answer: 
formData.restrict_answer.value  });
   



##########
ui/src/pages/Questions/Detail/index.tsx:
##########
@@ -194,6 +195,7 @@ const Index = () => {
       setQuestion({
         ...question,
         answered: true,
+        answer_ids: [...question.answer_ids, obj.id],

Review Comment:
   For users who have already answered many times before when limit answer is 
turned on, the answer_ids of the seat need to be adjusted to first_answer_id. 
Edit my existing answer button to edit the earliest answer, the answer_ids 
should be adjusted, we suggest to change it to first_answer_id.



##########
ui/src/pages/Questions/Detail/components/WriteAnswer/index.tsx:
##########
@@ -195,6 +198,11 @@ const Index: FC<Props> = ({ visible = false, data, 
callback }) => {
     if (!guard.tryNormalLogged(true)) {
       return;
     }
+    if (data?.answered && !showEditor && data?.restrictAnswer) {
+      setShowEditor(true);
+      return;
+    }
+

Review Comment:
   The logic here is not needed, the judgment has been added to the UI
   
   



##########
ui/src/pages/Questions/Detail/index.tsx:
##########
@@ -279,7 +281,9 @@ const Index = () => {
               data={{
                 qid,
                 answered: question?.answered,
+                restrictAnswer: writeInfo.restrict_answer,

Review Comment:
   There is no need to transparently transmit this parameter. After the store 
is moved internally, it can be used directly.



##########
ui/src/utils/guard.ts:
##########
@@ -398,6 +399,7 @@ export const initAppSettingsStore = async () => {
     customizeStore.getState().update(appSettings.custom_css_html);
     themeSettingStore.getState().update(appSettings.theme);
     seoSettingStore.getState().update(appSettings.site_seo);
+    writeSettingStore.getState().update(appSettings.site_write);

Review Comment:
   site_write only returns the required information
   
   



##########
ui/src/pages/Questions/Detail/index.tsx:
##########
@@ -74,6 +74,7 @@ const Index = () => {
   });
   const { setUsers } = usePageUsers();
   const userInfo = loggedUserInfoStore((state) => state.user);
+  const writeInfo = writeSettingStore((state) => state.write);

Review Comment:
   just move the relevant logic directly to the inside of the WriteAnswer 
component.



-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: [email protected]

For queries about this service, please contact Infrastructure at:
[email protected]

Reply via email to