Browse Source

resType?: TResType;

visuddhinanda 3 years ago
parent
commit
1956bd08ff

+ 3 - 3
dashboard/src/components/comment/CommentBox.tsx

@@ -1,7 +1,7 @@
 import { useState } from "react";
 import { Drawer } from "antd";
 import CommentTopic from "./CommentTopic";
-import CommentListCard from "./CommentListCard";
+import CommentListCard, { TResType } from "./CommentListCard";
 import { IComment } from "./CommentItem";
 
 export interface IAnswerCount {
@@ -11,7 +11,7 @@ export interface IAnswerCount {
 interface IWidget {
   trigger?: JSX.Element;
   resId?: string;
-  resType?: string;
+  resType?: TResType;
   onCommentCountChange?: Function;
 }
 const Widget = ({ trigger, resId, resType, onCommentCountChange }: IWidget) => {
@@ -19,7 +19,7 @@ const Widget = ({ trigger, resId, resType, onCommentCountChange }: IWidget) => {
   const [childrenDrawer, setChildrenDrawer] = useState(false);
   const [topicComment, setTopicComment] = useState<IComment>();
   const [answerCount, setAnswerCount] = useState<IAnswerCount>();
-  //console.log(resId, resType);
+
   const showDrawer = () => {
     setOpen(true);
   };

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

@@ -9,9 +9,10 @@ import { IComment } from "./CommentItem";
 import CommentList from "./CommentList";
 import { IAnswerCount } from "./CommentBox";
 
+export type TResType = "article" | "channel" | "chapter" | "sentence" | "wbw";
 interface IWidget {
   resId?: string;
-  resType?: string;
+  resType?: TResType;
   topicId?: string;
   changedAnswerCount?: IAnswerCount;
   onSelect?: Function;
@@ -89,18 +90,21 @@ const Widget = ({
 
   return (
     <div>
-      <Card title="问题列表" extra={<a href="#">More</a>}>
-        <CommentList
-          onSelect={(
-            e: React.MouseEvent<HTMLSpanElement, MouseEvent>,
-            comment: IComment
-          ) => {
-            if (typeof onSelect !== "undefined") {
-              onSelect(e, comment);
-            }
-          }}
-          data={data}
-        />
+      <Card title="问答" extra={<a href="#">More</a>}>
+        {data.length > 0 ? (
+          <CommentList
+            onSelect={(
+              e: React.MouseEvent<HTMLSpanElement, MouseEvent>,
+              comment: IComment
+            ) => {
+              if (typeof onSelect !== "undefined") {
+                onSelect(e, comment);
+              }
+            }}
+            data={data}
+          />
+        ) : undefined}
+
         {resId && resType ? (
           <CommentCreate
             resId={resId}
@@ -114,9 +118,7 @@ const Widget = ({
               setData([...data, newData]);
             }}
           />
-        ) : (
-          <></>
-        )}
+        ) : undefined}
       </Card>
     </div>
   );