Explorar o código

创建时不查询

visuddhinanda %!s(int64=2) %!d(string=hai) anos
pai
achega
151281f724

+ 108 - 60
dashboard/src/components/template/SentEdit/SuggestionBox.tsx

@@ -6,46 +6,22 @@ import SuggestionAdd from "./SuggestionAdd";
 import { ISentence } from "../SentEdit";
 import Marked from "../../general/Marked";
 
-export interface IAnswerCount {
-  id: string;
-  count: number;
-}
-interface IWidget {
+interface ISuggestionWidget {
   data: ISentence;
-  trigger?: JSX.Element;
-  open?: boolean;
-  onClose?: Function;
+  openNotification: boolean;
+  enable?: boolean;
+  onNotificationChange?: Function;
+  onPrChange?: Function;
 }
-const SuggestionBoxWidget = ({
-  trigger,
+const Suggestion = ({
   data,
-  open = false,
-  onClose,
-}: IWidget) => {
-  const [isOpen, setIsOpen] = useState(open);
+  enable = true,
+  openNotification,
+  onNotificationChange,
+  onPrChange,
+}: ISuggestionWidget) => {
   const [reload, setReload] = useState(false);
-  const [openNotification, setOpenNotification] = useState(false);
-  const [prNumber, setPrNumber] = useState(data.suggestionCount?.suggestion);
-
-  useEffect(() => setIsOpen(open), [open]);
-  useEffect(() => {
-    if (localStorage.getItem("read_pr_Notification") === "ok") {
-      setOpenNotification(false);
-    } else {
-      setOpenNotification(true);
-    }
-  }, []);
-  const showDrawer = () => {
-    setIsOpen(true);
-  };
-
-  const onBoxClose = () => {
-    setIsOpen(false);
-    if (typeof onClose !== "undefined") {
-      onClose();
-    }
-  };
-  const suggestion = (
+  return (
     <Space direction="vertical" style={{ width: "100%" }}>
       <Card
         title="温馨提示"
@@ -57,13 +33,15 @@ const SuggestionBoxWidget = ({
       >
         <Marked
           text="此处专为提交修改建议译文。您输入的应该是**译文**
-    而不是评论和问题。其他内容,请在讨论页面提交。"
+  而不是评论和问题。其他内容,请在讨论页面提交。"
         />
         <p style={{ textAlign: "center" }}>
           <Button
             onClick={() => {
               localStorage.setItem("read_pr_Notification", "ok");
-              setOpenNotification(false);
+              if (typeof onNotificationChange !== "undefined") {
+                onNotificationChange(false);
+              }
             }}
           >
             知道了
@@ -78,38 +56,108 @@ const SuggestionBoxWidget = ({
       />
       <SuggestionList
         {...data}
+        enable={enable}
         reload={reload}
-        onReload={() => setReload(false)}
-        onChange={(count: number) => setPrNumber(count)}
+        onReload={() => {
+          setReload(false);
+        }}
+        onChange={(count: number) => {
+          if (typeof onPrChange !== "undefined") {
+            onPrChange(count);
+          }
+        }}
       />
     </Space>
   );
+};
+
+export interface IAnswerCount {
+  id: string;
+  count: number;
+}
+interface IWidget {
+  data: ISentence;
+  trigger?: JSX.Element;
+  open?: boolean;
+  openInDrawer?: boolean;
+  onClose?: Function;
+}
+const SuggestionBoxWidget = ({
+  trigger,
+  data,
+  open = false,
+  openInDrawer = false,
+  onClose,
+}: IWidget) => {
+  const [isOpen, setIsOpen] = useState(open);
+  const [openNotification, setOpenNotification] = useState(false);
+  const [prNumber, setPrNumber] = useState(data.suggestionCount?.suggestion);
+
+  useEffect(() => setIsOpen(open), [open]);
+  useEffect(() => {
+    if (localStorage.getItem("read_pr_Notification") === "ok") {
+      setOpenNotification(false);
+    } else {
+      setOpenNotification(true);
+    }
+  }, []);
+  const showDrawer = () => {
+    setIsOpen(true);
+  };
+
+  const onBoxClose = () => {
+    setIsOpen(false);
+    if (typeof onClose !== "undefined") {
+      onClose();
+    }
+  };
+
   return (
     <>
       <Space onClick={showDrawer}>
         {trigger}
         {prNumber}
       </Space>
-      <div
-        style={{
-          position: "absolute",
-          display: isOpen ? "none" : "none",
-          zIndex: 1030,
-          marginLeft: 300,
-          marginTop: -250,
-        }}
-      >
-        {suggestion}
-      </div>
-      <Drawer
-        title="修改建议"
-        width={520}
-        onClose={onBoxClose}
-        open={isOpen}
-        maskClosable={false}
-      >
-        {suggestion}
-      </Drawer>
+
+      {openInDrawer ? (
+        <Drawer
+          title="修改建议"
+          width={520}
+          onClose={onBoxClose}
+          open={isOpen}
+          maskClosable={false}
+        >
+          <Suggestion
+            data={data}
+            enable={isOpen}
+            openNotification={openNotification}
+            onNotificationChange={(value: boolean) =>
+              setOpenNotification(value)
+            }
+            onPrChange={(value: number) => setPrNumber(value)}
+          />
+        </Drawer>
+      ) : (
+        <div
+          style={{
+            position: "absolute",
+            display: isOpen ? "none" : "none",
+            zIndex: 1030,
+            marginLeft: 300,
+            marginTop: -250,
+          }}
+        >
+          <Suggestion
+            data={data}
+            enable={isOpen}
+            openNotification={openNotification}
+            onNotificationChange={(value: boolean) =>
+              setOpenNotification(value)
+            }
+            onPrChange={(value: number) => setPrNumber(value)}
+          />
+        </div>
+      )}
     </>
   );
 };

+ 8 - 4
dashboard/src/components/template/SentEdit/SuggestionList.tsx

@@ -12,6 +12,7 @@ interface IWidget {
   wordStart: number;
   wordEnd: number;
   channel: IChannel;
+  enable?: boolean;
   reload?: boolean;
   onReload?: Function;
   onChange?: Function;
@@ -23,18 +24,21 @@ const SuggestionListWidget = ({
   wordEnd,
   channel,
   reload = false,
+  enable = true,
   onReload,
   onChange,
 }: IWidget) => {
   const [sentData, setSentData] = useState<ISentence[]>([]);
 
   const load = () => {
-    get<ISuggestionListResponse>(
-      `/v2/sentpr?view=sent-info&book=${book}&para=${para}&start=${wordStart}&end=${wordEnd}&channel=${channel.id}`
-    )
+    if (!enable) {
+      return;
+    }
+    const url = `/v2/sentpr?view=sent-info&book=${book}&para=${para}&start=${wordStart}&end=${wordEnd}&channel=${channel.id}`;
+    console.log("url", url);
+    get<ISuggestionListResponse>(url)
       .then((json) => {
         if (json.ok) {
-          console.log("pr load", json.data.rows);
           const newData: ISentence[] = json.data.rows.map((item) => {
             return {
               id: item.id,