Prechádzať zdrojové kódy

Merge pull request #1452 from visuddhinanda/agile

查词后再次点击同一个单词可以再次查询
visuddhinanda 2 rokov pred
rodič
commit
513cf498e9

+ 12 - 3
dashboard/src/components/dict/DictComponent.tsx

@@ -1,7 +1,8 @@
 import { useState, useEffect } from "react";
 
 import { useAppSelector } from "../../hooks";
-import { lookupWord } from "../../reducers/command";
+import { lookup, lookupWord } from "../../reducers/command";
+import store from "../../store";
 import Dictionary from "./Dictionary";
 
 export interface IWidgetDict {
@@ -13,12 +14,20 @@ const DictComponentWidget = ({ word }: IWidgetDict) => {
   const searchWord = useAppSelector(lookupWord);
   useEffect(() => {
     console.log("get command", searchWord);
-    if (typeof searchWord === "string") {
+    if (typeof searchWord === "string" && searchWord !== wordSearch) {
       setWordSearch(searchWord);
     }
   }, [searchWord]);
 
-  return <Dictionary word={wordSearch} compact={true} />;
+  return (
+    <Dictionary
+      word={wordSearch}
+      compact={true}
+      onSearch={(value: string, isFactor?: boolean) => {
+        store.dispatch(lookup(value));
+      }}
+    />
+  );
 };
 
 export default DictComponentWidget;

+ 4 - 1
dashboard/src/components/dict/Dictionary.tsx

@@ -18,8 +18,11 @@ const DictionaryWidget = ({ word, compact = false, onSearch }: IWidget) => {
   const [container, setContainer] = useState<HTMLDivElement | null>(null);
 
   useEffect(() => {
-    setWordSearch(word?.toLowerCase());
+    if (word !== wordSearch) {
+      setWordSearch(word?.toLowerCase());
+    }
   }, [word]);
+
   const dictSearch = (value: string, isFactor?: boolean) => {
     console.log("onSearch", value);
     const word = value.toLowerCase();

+ 0 - 4
dashboard/src/components/term/TermCommunity.tsx

@@ -44,10 +44,8 @@ const TermCommunityWidget = ({ word }: IWidget) => {
     get<ITermListResponse>(url)
       .then((json) => {
         if (json.ok === false) {
-          console.log("dict community", json.message);
           return;
         }
-        console.log("count", json.data);
         let meaning = new Map<string, number>();
         let note = new Map<string, number>();
         let editorId = new Map<string, number>();
@@ -102,9 +100,7 @@ const TermCommunityWidget = ({ word }: IWidget) => {
         });
         _data.editor.sort((a, b) => b.score - a.score);
         setWordData(_data);
-        console.log("_data", _data);
         if (_data.editor.length > 0) {
-          console.log("show", _data.editor.length);
           setShow(true);
         }
       })