2
0
Эх сурвалжийг харах

onSearch 发送查词消息

visuddhinanda 2 жил өмнө
parent
commit
86ad000179

+ 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;