Browse Source

支持搜索other_meaning

visuddhinanda 1 year ago
parent
commit
101bd79bda
1 changed files with 28 additions and 21 deletions
  1. 28 21
      dashboard/src/components/term/GrammarBook.tsx

+ 28 - 21
dashboard/src/components/term/GrammarBook.tsx

@@ -62,6 +62,7 @@ const GrammarBookWidget = () => {
       }
     });
   }, []);
+
   useEffect(() => {
     console.debug("grammar book", searchWord);
     if (searchWord && searchWord.length > 0) {
@@ -135,7 +136,7 @@ const GrammarBookWidget = () => {
                     item.word.length - keyWord.length - wordBegin;
                   weight += (1 / (wordRemain + 1)) * 100;
                 }
-                const meaningBegin = item.meaning
+                const meaningBegin = (item.meaning + item.other_meaning)
                   .toLocaleLowerCase()
                   .indexOf(keyWord);
                 if (meaningBegin >= 0) {
@@ -213,26 +214,32 @@ const GrammarBookWidget = () => {
           <List
             size="small"
             dataSource={result}
-            renderItem={(item) => (
-              <List.Item
-                key={item.term.guid}
-                style={{ cursor: "pointer" }}
-                onClick={() => {
-                  setTermId(item.term.guid);
-                  setTermSearch(undefined);
-                  pushRecent({
-                    title: item.term.word,
-                    description: item.term.meaning,
-                    wordId: item.term.guid,
-                  });
-                }}
-              >
-                <List.Item.Meta
-                  title={item.term.word}
-                  description={item.term.meaning}
-                />
-              </List.Item>
-            )}
+            renderItem={(item) => {
+              const description =
+                item.term.meaning +
+                (item.term.other_meaning ? "," + item.term.other_meaning : "");
+
+              return (
+                <List.Item
+                  key={item.term.guid}
+                  style={{ cursor: "pointer" }}
+                  onClick={() => {
+                    setTermId(item.term.guid);
+                    setTermSearch(undefined);
+                    pushRecent({
+                      title: item.term.word,
+                      description: description,
+                      wordId: item.term.guid,
+                    });
+                  }}
+                >
+                  <List.Item.Meta
+                    title={item.term.word}
+                    description={description}
+                  />
+                </List.Item>
+              );
+            }}
           />
         )}
       </div>