visuddhinanda преди 2 години
родител
ревизия
c0de9193fc
променени са 2 файла, в които са добавени 23 реда и са изтрити 3 реда
  1. 12 0
      dashboard/src/components/discussion/DiscussionItem.tsx
  2. 11 3
      dashboard/src/components/discussion/DiscussionListCard.tsx

+ 12 - 0
dashboard/src/components/discussion/DiscussionItem.tsx

@@ -4,11 +4,13 @@ import { IUser } from "../auth/User";
 import DiscussionShow from "./DiscussionShow";
 import DiscussionShow from "./DiscussionShow";
 import DiscussionEdit from "./DiscussionEdit";
 import DiscussionEdit from "./DiscussionEdit";
 import { TResType } from "./DiscussionListCard";
 import { TResType } from "./DiscussionListCard";
+import { TDiscussionType } from "./Discussion";
 
 
 export interface IComment {
 export interface IComment {
   id?: string; //id未提供为新建
   id?: string; //id未提供为新建
   resId?: string;
   resId?: string;
   resType?: TResType;
   resType?: TResType;
+  type: TDiscussionType;
   tplId?: string;
   tplId?: string;
   user: IUser;
   user: IUser;
   parent?: string | null;
   parent?: string | null;
@@ -26,20 +28,24 @@ export interface IComment {
 interface IWidget {
 interface IWidget {
   data: IComment;
   data: IComment;
   isFocus?: boolean;
   isFocus?: boolean;
+  hideTitle?: boolean;
   onSelect?: Function;
   onSelect?: Function;
   onCreated?: Function;
   onCreated?: Function;
   onDelete?: Function;
   onDelete?: Function;
   onReply?: Function;
   onReply?: Function;
   onClose?: Function;
   onClose?: Function;
+  onConvert?: Function;
 }
 }
 const DiscussionItemWidget = ({
 const DiscussionItemWidget = ({
   data,
   data,
   isFocus = false,
   isFocus = false,
+  hideTitle = false,
   onSelect,
   onSelect,
   onCreated,
   onCreated,
   onDelete,
   onDelete,
   onReply,
   onReply,
   onClose,
   onClose,
+  onConvert,
 }: IWidget) => {
 }: IWidget) => {
   const [edit, setEdit] = useState(false);
   const [edit, setEdit] = useState(false);
   const [currData, setCurrData] = useState<IComment>(data);
   const [currData, setCurrData] = useState<IComment>(data);
@@ -78,6 +84,7 @@ const DiscussionItemWidget = ({
         ) : (
         ) : (
           <DiscussionShow
           <DiscussionShow
             data={currData}
             data={currData}
+            hideTitle={hideTitle}
             onEdit={() => {
             onEdit={() => {
               setEdit(true);
               setEdit(true);
             }}
             }}
@@ -101,6 +108,11 @@ const DiscussionItemWidget = ({
                 onClose(value);
                 onClose(value);
               }
               }
             }}
             }}
+            onConvert={(value: TDiscussionType) => {
+              if (typeof onConvert !== "undefined") {
+                onConvert(value);
+              }
+            }}
           />
           />
         )}
         )}
       </div>
       </div>

+ 11 - 3
dashboard/src/components/discussion/DiscussionListCard.tsx

@@ -1,6 +1,5 @@
 import { useEffect, useRef, useState } from "react";
 import { useEffect, useRef, useState } from "react";
 import { Button, Space, Typography } from "antd";
 import { Button, Space, Typography } from "antd";
-import { CommentOutlined } from "@ant-design/icons";
 
 
 import { get } from "../../request";
 import { get } from "../../request";
 import { ICommentListResponse } from "../api/Comment";
 import { ICommentListResponse } from "../api/Comment";
@@ -15,6 +14,7 @@ import { useAppSelector } from "../../hooks";
 import { currentUser as _currentUser } from "../../reducers/current-user";
 import { currentUser as _currentUser } from "../../reducers/current-user";
 import { CommentOutlinedIcon, TemplateOutlinedIcon } from "../../assets/icon";
 import { CommentOutlinedIcon, TemplateOutlinedIcon } from "../../assets/icon";
 import { ISentenceResponse } from "../api/Corpus";
 import { ISentenceResponse } from "../api/Corpus";
+import { TDiscussionType } from "./Discussion";
 
 
 export type TResType =
 export type TResType =
   | "article"
   | "article"
@@ -29,6 +29,7 @@ interface IWidget {
   resType?: TResType;
   resType?: TResType;
   topicId?: string;
   topicId?: string;
   changedAnswerCount?: IAnswerCount;
   changedAnswerCount?: IAnswerCount;
+  type?: TDiscussionType;
   onSelect?: Function;
   onSelect?: Function;
   onItemCountChange?: Function;
   onItemCountChange?: Function;
   onReply?: Function;
   onReply?: Function;
@@ -40,6 +41,7 @@ const DiscussionListCardWidget = ({
   topicId,
   topicId,
   onSelect,
   onSelect,
   changedAnswerCount,
   changedAnswerCount,
+  type = "discussion",
   onItemCountChange,
   onItemCountChange,
   onReply,
   onReply,
   onReady,
   onReady,
@@ -49,6 +51,8 @@ const DiscussionListCardWidget = ({
   const [activeNumber, setActiveNumber] = useState<number>(0);
   const [activeNumber, setActiveNumber] = useState<number>(0);
   const [closeNumber, setCloseNumber] = useState<number>(0);
   const [closeNumber, setCloseNumber] = useState<number>(0);
   const [count, setCount] = useState<number>(0);
   const [count, setCount] = useState<number>(0);
+  const [canCreate, setCanCreate] = useState(false);
+
   const user = useAppSelector(_currentUser);
   const user = useAppSelector(_currentUser);
 
 
   useEffect(() => {
   useEffect(() => {
@@ -126,7 +130,7 @@ const DiscussionListCardWidget = ({
           },
           },
         }}
         }}
         request={async (params = {}, sorter, filter) => {
         request={async (params = {}, sorter, filter) => {
-          let url: string = "/v2/discussion?";
+          let url: string = `/v2/discussion?type=${type}&res_type=${resType}&`;
           if (typeof topicId !== "undefined") {
           if (typeof topicId !== "undefined") {
             url += `view=question-by-topic&id=${topicId}`;
             url += `view=question-by-topic&id=${topicId}`;
           } else if (typeof resId !== "undefined") {
           } else if (typeof resId !== "undefined") {
@@ -146,11 +150,13 @@ const DiscussionListCardWidget = ({
           console.log("url", url);
           console.log("url", url);
           const res = await get<ICommentListResponse>(url);
           const res = await get<ICommentListResponse>(url);
           setCount(res.data.active);
           setCount(res.data.active);
+          setCanCreate(res.data.can_create);
           const items: IComment[] = res.data.rows.map((item, id) => {
           const items: IComment[] = res.data.rows.map((item, id) => {
             return {
             return {
               id: item.id,
               id: item.id,
               resId: item.res_id,
               resId: item.res_id,
               resType: item.res_type,
               resType: item.res_type,
+              type: item.type,
               user: item.editor,
               user: item.editor,
               title: item.title,
               title: item.title,
               parent: item.parent,
               parent: item.parent,
@@ -190,6 +196,7 @@ const DiscussionListCardWidget = ({
                     tplId: item.uid,
                     tplId: item.uid,
                     resId: resId,
                     resId: resId,
                     resType: resType,
                     resType: resType,
+                    type: "discussion",
                     user: item.editor
                     user: item.editor
                       ? item.editor
                       ? item.editor
                       : { id: "", userName: "", nickName: "" },
                       : { id: "", userName: "", nickName: "" },
@@ -260,11 +267,12 @@ const DiscussionListCardWidget = ({
         }}
         }}
       />
       />
 
 
-      {resId && resType ? (
+      {canCreate && resId && resType ? (
         <DiscussionCreate
         <DiscussionCreate
           contentType="markdown"
           contentType="markdown"
           resId={resId}
           resId={resId}
           resType={resType}
           resType={resType}
+          type={type}
           onCreated={(e: IComment) => {
           onCreated={(e: IComment) => {
             if (typeof onItemCountChange !== "undefined") {
             if (typeof onItemCountChange !== "undefined") {
               onItemCountChange(count + 1);
               onItemCountChange(count + 1);