visuddhinanda 2 лет назад
Родитель
Сommit
c64f73bd85

+ 5 - 0
dashboard/src/components/template/SentEdit.tsx

@@ -70,6 +70,7 @@ export const SentEditInner = ({
   simNum,
 }: IWidgetSentEditInner) => {
   const [wbwData, setWbwData] = useState<IWbw[]>();
+  const [magicDict, setMagicDict] = useState<string>();
 
   useEffect(() => {
     const content = origin?.find(
@@ -91,6 +92,7 @@ export const SentEditInner = ({
         origin={origin}
         translation={translation}
         layout={layout}
+        magicDict={magicDict}
         onWbwChange={(data: IWbw[]) => {
           setWbwData(data);
         }}
@@ -108,6 +110,9 @@ export const SentEditInner = ({
         originNum={originNum}
         simNum={simNum}
         wbwData={wbwData}
+        onMagicDict={(type: string) => {
+          setMagicDict(type);
+        }}
       />
     </Card>
   );

+ 5 - 0
dashboard/src/components/template/SentEdit/SentContent.tsx

@@ -22,6 +22,7 @@ interface IWidgetSentContent {
   origin?: ISentence[];
   translation?: ISentence[];
   layout?: TDirection;
+  magicDict?: string;
   onWbwChange?: Function;
 }
 const Widget = ({
@@ -33,6 +34,7 @@ const Widget = ({
   origin,
   translation,
   layout = "column",
+  magicDict,
   onWbwChange,
 }: IWidgetSentContent) => {
   const [layoutDirection, setLayoutDirection] = useState<TDirection>(layout);
@@ -89,6 +91,9 @@ const Widget = ({
                 key={id}
                 book={book}
                 para={para}
+                wordStart={wordStart}
+                wordEnd={wordEnd}
+                magicDict={magicDict}
                 channelId={item.channel.id}
                 data={JSON.parse(item.content)}
                 onChange={(data: IWbw[]) => {

+ 11 - 1
dashboard/src/components/template/SentEdit/SentTab.tsx

@@ -30,6 +30,7 @@ interface IWidget {
   originNum: number;
   simNum?: number;
   wbwData?: IWbw[];
+  onMagicDict?: Function;
 }
 const Widget = ({
   id,
@@ -44,6 +45,7 @@ const Widget = ({
   originNum,
   simNum = 0,
   wbwData,
+  onMagicDict,
 }: IWidget) => {
   const intl = useIntl();
 
@@ -68,7 +70,15 @@ const Widget = ({
               }
             />
             <Text copyable={{ text: sentId[0] }}>{sentId[0]}</Text>
-            <SentMenu book={book} para={para} />
+            <SentMenu
+              book={book}
+              para={para}
+              onMagicDict={(type: string) => {
+                if (typeof onMagicDict !== "undefined") {
+                  onMagicDict(type);
+                }
+              }}
+            />
           </Space>
         }
         items={[

+ 44 - 1
dashboard/src/components/template/WbwSent.tsx

@@ -7,6 +7,20 @@ import { post } from "../../request";
 import { ArticleMode } from "../article/Article";
 import WbwWord, { IWbw, IWbwFields, WbwElement } from "./Wbw/WbwWord";
 
+interface IMagicDictRequest {
+  book: number;
+  para: number;
+  word_start: number;
+  word_end: number;
+  data: IWbw[];
+  channel_id: string;
+}
+interface IMagicDictResponse {
+  ok: boolean;
+  message: string;
+  data: IWbw[];
+}
+
 interface IWbwXml {
   id: string;
   pali: WbwElement<string>;
@@ -42,9 +56,13 @@ interface IWidget {
   data: IWbw[];
   book: number;
   para: number;
+  wordStart: number;
+  wordEnd: number;
   channelId: string;
   display?: "block" | "inline";
   fields?: IWbwFields;
+  magicDict?: string;
+
   onChange?: Function;
 }
 export const WbwSentCtl = ({
@@ -52,8 +70,11 @@ export const WbwSentCtl = ({
   channelId,
   book,
   para,
+  wordStart,
+  wordEnd,
   display = "inline",
   fields,
+  magicDict,
   onChange,
 }: IWidget) => {
   const [wordData, setWordData] = useState<IWbw[]>(data);
@@ -86,6 +107,28 @@ export const WbwSentCtl = ({
     }
   }, [newMode]);
 
+  useEffect(() => {
+    if (typeof magicDict === "undefined") {
+      return;
+    }
+    const url = `/v2/wbwlookup`;
+    console.log("magic dict url", url);
+    post<IMagicDictRequest, IMagicDictResponse>(url, {
+      book: book,
+      para: para,
+      word_start: wordStart,
+      word_end: wordEnd,
+      data: wordData,
+      channel_id: channelId,
+    }).then((json) => {
+      if (json.ok) {
+        console.log("magic dict result", json.data);
+        setWordData(json.data);
+      } else {
+        console.error(json.message);
+      }
+    });
+  }, [magicDict]);
   return (
     <div style={{ display: "flex", flexWrap: "wrap" }}>
       {wordData.map((item, id) => {
@@ -123,7 +166,7 @@ export const WbwSentCtl = ({
                     gramma: item.type,
                     mean: item.meaning
                       ? {
-                          value: item.meaning?.value.join("$"),
+                          value: item.meaning.value,
                           status: item.meaning?.status,
                         }
                       : undefined,