Parcourir la source

:fire: magicDict

visuddhinanda il y a 2 ans
Parent
commit
ca90258c80
1 fichiers modifiés avec 35 ajouts et 37 suppressions
  1. 35 37
      dashboard/src/components/template/WbwSent.tsx

+ 35 - 37
dashboard/src/components/template/WbwSent.tsx

@@ -144,7 +144,6 @@ interface IWidget {
   display?: TWbwDisplayMode;
   display?: TWbwDisplayMode;
   fields?: IWbwFields;
   fields?: IWbwFields;
   layoutDirection?: "h" | "v";
   layoutDirection?: "h" | "v";
-  magicDict?: string;
   refreshable?: boolean;
   refreshable?: boolean;
   mode?: ArticleMode;
   mode?: ArticleMode;
   wbwProgress?: boolean;
   wbwProgress?: boolean;
@@ -164,7 +163,6 @@ export const WbwSentCtl = ({
   fields,
   fields,
   layoutDirection = "h",
   layoutDirection = "h",
   mode,
   mode,
-  magicDict,
   refreshable = false,
   refreshable = false,
   wbwProgress = false,
   wbwProgress = false,
   onChange,
   onChange,
@@ -175,7 +173,6 @@ export const WbwSentCtl = ({
   const [wbwMode, setWbwMode] = useState(display);
   const [wbwMode, setWbwMode] = useState(display);
   const [fieldDisplay, setFieldDisplay] = useState(fields);
   const [fieldDisplay, setFieldDisplay] = useState(fields);
   const [displayMode, setDisplayMode] = useState<ArticleMode>();
   const [displayMode, setDisplayMode] = useState<ArticleMode>();
-  const [magic, setMagic] = useState<string>();
   const [loading, setLoading] = useState(false);
   const [loading, setLoading] = useState(false);
   const [progress, setProgress] = useState(0);
   const [progress, setProgress] = useState(0);
   const [showProgress, setShowProgress] = useState(false);
   const [showProgress, setShowProgress] = useState(false);
@@ -221,10 +218,6 @@ export const WbwSentCtl = ({
     setProgress(progress);
     setProgress(progress);
   }, [wordData]);
   }, [wordData]);
 
 
-  useEffect(() => {
-    setMagic(magicDict);
-  }, [magicDict]);
-
   const newMode = useAppSelector(_mode);
   const newMode = useAppSelector(_mode);
 
 
   const update = (data: IWbw[]) => {
   const update = (data: IWbw[]) => {
@@ -308,10 +301,7 @@ export const WbwSentCtl = ({
     }
     }
   }, [newMode, mode]);
   }, [newMode, mode]);
 
 
-  useEffect(() => {
-    if (typeof magic === "undefined") {
-      return;
-    }
+  const magicDictLookup = () => {
     let _lang = GetUserSetting("setting.dict.lang", settings);
     let _lang = GetUserSetting("setting.dict.lang", settings);
     const url = `/v2/wbwlookup`;
     const url = `/v2/wbwlookup`;
     console.log("magic dict url", url);
     console.log("magic dict url", url);
@@ -330,19 +320,20 @@ export const WbwSentCtl = ({
         if (json.ok) {
         if (json.ok) {
           console.log("magic dict result", json.data);
           console.log("magic dict result", json.data);
           update(json.data);
           update(json.data);
-          updateWbwAll(json.data);
+          if (channelType !== "nissaya") {
+            saveWbwAll(json.data);
+          }
         } else {
         } else {
           console.error(json.message);
           console.error(json.message);
         }
         }
       })
       })
       .finally(() => {
       .finally(() => {
-        setMagic(undefined);
         setLoading(false);
         setLoading(false);
         if (typeof onMagicDictDone !== "undefined") {
         if (typeof onMagicDictDone !== "undefined") {
           onMagicDictDone();
           onMagicDictDone();
         }
         }
       });
       });
-  }, [magic]);
+  };
 
 
   const wbwToXml = (item: IWbw) => {
   const wbwToXml = (item: IWbw) => {
     return {
     return {
@@ -373,7 +364,7 @@ export const WbwSentCtl = ({
     };
     };
   };
   };
 
 
-  const updateWbwAll = (wbwData: IWbw[]) => {
+  const saveWbwAll = (wbwData: IWbw[]) => {
     let arrSn: number[] = [];
     let arrSn: number[] = [];
     wbwData.forEach((value) => {
     wbwData.forEach((value) => {
       if (!arrSn.includes(value.sn[0])) {
       if (!arrSn.includes(value.sn[0])) {
@@ -483,25 +474,30 @@ export const WbwSentCtl = ({
     let wordData: IDictRequest[] = [];
     let wordData: IDictRequest[] = [];
 
 
     wbwData.forEach((data) => {
     wbwData.forEach((data) => {
-      const [wordType, wordGrammar] = data.case?.value
-        ? data.case?.value?.split("#")
-        : ["", ""];
-      let conf = data.confidence * 100;
-      if (data.confidence.toString() === "0.5") {
-        conf = 100;
+      if (
+        typeof data.meaning?.value === "string" &&
+        data.meaning?.value.trim().length > 0
+      ) {
+        const [wordType, wordGrammar] = data.case?.value
+          ? data.case?.value?.split("#")
+          : ["", ""];
+        let conf = data.confidence * 100;
+        if (data.confidence.toString() === "0.5") {
+          conf = 100;
+        }
+        wordData.push({
+          word: data.real.value ? data.real.value : "",
+          type: wordType,
+          grammar: wordGrammar,
+          mean: data.meaning?.value,
+          parent: data.parent?.value,
+          factors: data.factors?.value,
+          factormean: data.factorMeaning?.value,
+          note: data.note?.value,
+          confidence: conf,
+          language: channelLang,
+        });
       }
       }
-      wordData.push({
-        word: data.real.value ? data.real.value : "",
-        type: wordType,
-        grammar: wordGrammar,
-        mean: data.meaning?.value,
-        parent: data.parent?.value,
-        factors: data.factors?.value,
-        factormean: data.factorMeaning?.value,
-        note: data.note?.value,
-        confidence: conf,
-        language: channelLang,
-      });
     });
     });
 
 
     UserWbwPost(wordData, "wbw")
     UserWbwPost(wordData, "wbw")
@@ -647,11 +643,11 @@ export const WbwSentCtl = ({
     });
     });
     message.info(`已经重置${count}个`);
     message.info(`已经重置${count}个`);
     update(newData);
     update(newData);
-    updateWbwAll(newData);
+    saveWbwAll(newData);
   };
   };
 
 
   return (
   return (
-    <div>
+    <div style={{ width: "100%" }}>
       <div
       <div
         className="progress"
         className="progress"
         style={{ display: showProgress ? "block" : "none" }}
         style={{ display: showProgress ? "block" : "none" }}
@@ -664,7 +660,9 @@ export const WbwSentCtl = ({
             items: [
             items: [
               {
               {
                 key: "magic-dict-current",
                 key: "magic-dict-current",
-                label: "神奇字典",
+                label: intl.formatMessage({
+                  id: "buttons.magic-dict",
+                }),
               },
               },
               {
               {
                 key: "progress",
                 key: "progress",
@@ -696,7 +694,7 @@ export const WbwSentCtl = ({
               switch (key) {
               switch (key) {
                 case "magic-dict-current":
                 case "magic-dict-current":
                   setLoading(true);
                   setLoading(true);
-                  setMagic("curr");
+                  magicDictLookup();
                   break;
                   break;
                 case "wbw-dict-publish-all":
                 case "wbw-dict-publish-all":
                   wbwPublish(wordData);
                   wbwPublish(wordData);