Quellcode durchsuchen

数据提交后 更新 state

visuddhinanda vor 1 Jahr
Ursprung
Commit
6c916a3853
1 geänderte Dateien mit 10 neuen und 12 gelöschten Zeilen
  1. 10 12
      dashboard/src/components/template/WbwSent.tsx

+ 10 - 12
dashboard/src/components/template/WbwSent.tsx

@@ -124,7 +124,7 @@ interface IWbwXml {
 interface IWbwUpdateResponse {
   ok: boolean;
   message: string;
-  data: { rows?: IWbwXml[]; count: number };
+  data: { rows: IWbw[]; count: number };
 }
 interface IWbwWord {
   words: IWbwXml[];
@@ -408,15 +408,21 @@ export const WbwSentCtl = ({
       }),
     };
 
-    post<IWbwRequest, IWbwUpdateResponse>(`/v2/wbw`, postParam).then((json) => {
+    postWord(postParam);
+  };
+  const postWord = (postParam: IWbwRequest) => {
+    const url = `/v2/wbw`;
+    console.info("wbw api request", url, postParam);
+    post<IWbwRequest, IWbwUpdateResponse>(url, postParam).then((json) => {
+      console.info("wbw api response", json);
       if (json.ok) {
         message.info(json.data.count + " updated");
+        setWordData(paraMark(json.data.rows));
       } else {
         message.error(json.message);
       }
     });
   };
-
   const saveWord = (wbwData: IWbw[], sn: number) => {
     if (channelType === "nissaya") {
     } else {
@@ -435,15 +441,7 @@ export const WbwSentCtl = ({
         ],
       };
 
-      post<IWbwRequest, IWbwUpdateResponse>(`/v2/wbw`, postParam).then(
-        (json) => {
-          if (json.ok) {
-            message.info(json.data.count + " updated");
-          } else {
-            message.error(json.message);
-          }
-        }
-      );
+      postWord(postParam);
     }
   };