Просмотр исходного кода

Merge pull request #1988 from visuddhinanda/agile

字典拆分,输入改变,清空旧的显示
visuddhinanda 2 лет назад
Родитель
Сommit
0790a7ac7c

+ 3 - 1
dashboard/src/components/dict/Compound.tsx

@@ -64,6 +64,8 @@ const CompoundWidget = ({ word, add, split, onSearch }: IWidget) => {
   }, [add, compound]);
 
   useEffect(() => {
+    setMeaningData([]);
+    setFactors([]);
     if (typeof word === "undefined") {
       return;
     }
@@ -141,7 +143,7 @@ const CompoundWidget = ({ word, add, split, onSearch }: IWidget) => {
         onChange={onSelectChange}
         options={factors}
       />
-      {meaningData ? (
+      {meaningData && meaningData.length > 0 ? (
         <List
           size="small"
           dataSource={meaningData}

+ 9 - 9
dashboard/src/components/dict/Dictionary.tsx

@@ -23,7 +23,7 @@ const DictionaryWidget = ({ word, compact = false, onSearch }: IWidget) => {
 
   useEffect(() => {
     console.debug("param word change", word);
-    setWordInput(word);
+    wordInputChange(word);
   }, [word]);
 
   const wordChange = (value?: string) => {
@@ -57,22 +57,22 @@ const DictionaryWidget = ({ word, compact = false, onSearch }: IWidget) => {
     return currWord;
   };
 
-  useEffect(() => {
-    console.debug("wordInput change", wordInput);
-    if (wordInput !== wordSearch) {
-      const currWord = wordChange(wordInput);
+  const wordInputChange = (value: string | undefined) => {
+    setWordInput(value);
+    console.debug("wordInput change", value);
+    if (value !== wordSearch) {
+      const currWord = wordChange(value);
       setWordSearch(currWord);
     }
-  }, [wordInput]);
+  };
 
   const dictSearch = (value: string, isFactor?: boolean) => {
     console.info("onSearch", value);
     const currWord = wordChange(value);
     if (typeof onSearch !== "undefined" && !isFactor) {
       onSearch(currWord);
-    } else {
-      setWordSearch(currWord);
     }
+    setWordSearch(currWord);
   };
   return (
     <div ref={setContainer}>
@@ -127,7 +127,7 @@ const DictionaryWidget = ({ word, compact = false, onSearch }: IWidget) => {
                   if (typeof onSearch !== "undefined") {
                     onSearch(newInput);
                   } else {
-                    setWordInput(newInput);
+                    wordInputChange(newInput);
                   }
                 }}
               />