Prechádzať zdrojové kódy

:sparkles: 提交新纪录成功reload list

visuddhinanda 3 rokov pred
rodič
commit
03f1859131

+ 13 - 3
dashboard/src/components/template/SentEdit/SuggestionBox.tsx

@@ -16,6 +16,7 @@ interface IWidget {
 }
 }
 const Widget = ({ trigger, data }: IWidget) => {
 const Widget = ({ trigger, data }: IWidget) => {
   const [open, setOpen] = useState(false);
   const [open, setOpen] = useState(false);
+  const [reload, setReload] = useState(false);
   const [openNotification, setOpenNotification] = useState(false);
   const [openNotification, setOpenNotification] = useState(false);
 
 
   useEffect(() => {
   useEffect(() => {
@@ -43,7 +44,7 @@ const Widget = ({ trigger, data }: IWidget) => {
         open={open}
         open={open}
         maskClosable={false}
         maskClosable={false}
       >
       >
-        <Space direction="vertical">
+        <Space direction="vertical" style={{ width: "100%" }}>
           <Card
           <Card
             title="温馨提示"
             title="温馨提示"
             size="small"
             size="small"
@@ -67,8 +68,17 @@ const Widget = ({ trigger, data }: IWidget) => {
               </Button>
               </Button>
             </p>
             </p>
           </Card>
           </Card>
-          <SuggestionAdd data={data} />
-          <SuggestionList {...data} />
+          <SuggestionAdd
+            data={data}
+            onCreate={() => {
+              setReload(true);
+            }}
+          />
+          <SuggestionList
+            {...data}
+            reload={reload}
+            onReload={() => setReload(false)}
+          />
         </Space>
         </Space>
       </Drawer>
       </Drawer>
     </>
     </>

+ 51 - 21
dashboard/src/components/template/SentEdit/SuggestionList.tsx

@@ -1,3 +1,4 @@
+import { message } from "antd";
 import { useEffect, useState } from "react";
 import { useEffect, useState } from "react";
 
 
 import { get } from "../../../request";
 import { get } from "../../../request";
@@ -11,37 +12,66 @@ interface IWidget {
   wordStart: number;
   wordStart: number;
   wordEnd: number;
   wordEnd: number;
   channel: IChannel;
   channel: IChannel;
+  reload?: boolean;
+  onReload?: Function;
 }
 }
-const Widget = ({ book, para, wordStart, wordEnd, channel }: IWidget) => {
+const Widget = ({
+  book,
+  para,
+  wordStart,
+  wordEnd,
+  channel,
+  reload = false,
+  onReload,
+}: IWidget) => {
   const [sentData, setSentData] = useState<ISentence[]>([]);
   const [sentData, setSentData] = useState<ISentence[]>([]);
 
 
-  useEffect(() => {
+  const load = () => {
     get<ISuggestionListResponse>(
     get<ISuggestionListResponse>(
       `/v2/sentpr?view=sent-info&book=${book}&para=${para}&start=${wordStart}&end=${wordEnd}&channel=${channel.id}`
       `/v2/sentpr?view=sent-info&book=${book}&para=${para}&start=${wordStart}&end=${wordEnd}&channel=${channel.id}`
-    ).then((json) => {
-      const newData: ISentence[] = json.data.rows.map((item) => {
-        return {
-          id: item.id,
-          content: item.content,
-          html: item.html,
-          book: item.book,
-          para: item.paragraph,
-          wordStart: item.word_start,
-          wordEnd: item.word_end,
-          editor: item.editor,
-          channel: { name: item.channel.name, id: item.channel.id },
-          updateAt: item.updated_at,
-        };
+    )
+      .then((json) => {
+        if (json.ok) {
+          console.log("pr load", json.data.rows);
+          const newData: ISentence[] = json.data.rows.map((item) => {
+            return {
+              id: item.id,
+              content: item.content,
+              html: item.html,
+              book: item.book,
+              para: item.paragraph,
+              wordStart: item.word_start,
+              wordEnd: item.word_end,
+              editor: item.editor,
+              channel: { name: item.channel.name, id: item.channel.id },
+              updateAt: item.updated_at,
+            };
+          });
+          setSentData(newData);
+        } else {
+          message.error(json.message);
+        }
+      })
+      .finally(() => {
+        if (reload && typeof onReload !== "undefined") {
+          onReload();
+        }
       });
       });
-      setSentData(newData);
-    });
-  }, [book, para, wordStart, wordEnd, channel]);
+  };
+  useEffect(() => {
+    load();
+  }, []);
+  useEffect(() => {
+    if (reload) {
+      load();
+    }
+  }, [reload]);
   return (
   return (
-    <div>
+    <>
       {sentData.map((item, id) => {
       {sentData.map((item, id) => {
         return <SentCell data={item} key={id} isPr={true} />;
         return <SentCell data={item} key={id} isPr={true} />;
       })}
       })}
-    </div>
+    </>
   );
   );
 };
 };