瀏覽代碼

把 onClose 搬到组件里面

visuddhinanda 2 年之前
父節點
當前提交
99b2a323ad
共有 1 個文件被更改,包括 16 次插入18 次删除
  1. 16 18
      dashboard/src/components/comment/CommentBox.tsx

+ 16 - 18
dashboard/src/components/comment/CommentBox.tsx

@@ -25,17 +25,6 @@ const CommentBoxWidget = ({
   const [topicComment, setTopicComment] = useState<IComment>();
   const [topicComment, setTopicComment] = useState<IComment>();
   const [answerCount, setAnswerCount] = useState<IAnswerCount>();
   const [answerCount, setAnswerCount] = useState<IAnswerCount>();
 
 
-  const showDrawer = () => {
-    setOpen(true);
-  };
-
-  const onClose = () => {
-    setOpen(false);
-    if (document.getElementsByTagName("body")[0].hasAttribute("style")) {
-      document.getElementsByTagName("body")[0].removeAttribute("style");
-    }
-  };
-
   const showChildrenDrawer = (
   const showChildrenDrawer = (
     e: React.MouseEvent<HTMLSpanElement, MouseEvent>,
     e: React.MouseEvent<HTMLSpanElement, MouseEvent>,
     comment: IComment
     comment: IComment
@@ -44,17 +33,24 @@ const CommentBoxWidget = ({
     setTopicComment(comment);
     setTopicComment(comment);
   };
   };
 
 
-  const onChildrenDrawerClose = () => {
-    setChildrenDrawer(false);
-  };
-
   return (
   return (
     <>
     <>
-      <span onClick={showDrawer}>{trigger}</span>
+      <span
+        onClick={() => {
+          setOpen(true);
+        }}
+      >
+        {trigger}
+      </span>
       <Drawer
       <Drawer
         title="Discussion"
         title="Discussion"
         width={520}
         width={520}
-        onClose={onClose}
+        onClose={() => {
+          setOpen(false);
+          if (document.getElementsByTagName("body")[0].hasAttribute("style")) {
+            document.getElementsByTagName("body")[0].removeAttribute("style");
+          }
+        }}
         open={open}
         open={open}
         maskClosable={false}
         maskClosable={false}
       >
       >
@@ -72,7 +68,9 @@ const CommentBoxWidget = ({
         <Drawer
         <Drawer
           title="回答"
           title="回答"
           width={480}
           width={480}
-          onClose={onChildrenDrawerClose}
+          onClose={() => {
+            setChildrenDrawer(false);
+          }}
           open={childrenDrawer}
           open={childrenDrawer}
         >
         >
           <CommentTopic
           <CommentTopic