Просмотр исходного кода

Merge pull request #1534 from visuddhinanda/agile

add onTopicCreated #1527
visuddhinanda 2 лет назад
Родитель
Сommit
851d7cc1e7

+ 17 - 15
dashboard/src/components/discussion/DiscussionCreate.tsx

@@ -23,6 +23,20 @@ import MDEditor from "@uiw/react-md-editor";
 
 export type TContentType = "text" | "markdown" | "html" | "json";
 
+export const toIComment = (value: ICommentApiData): IComment => {
+  return {
+    id: value.id,
+    resId: value.res_id,
+    resType: value.res_type,
+    user: value.editor,
+    title: value.title,
+    parent: value.parent,
+    tplId: value.tpl_id,
+    content: value.content,
+    createdAt: value.created_at,
+    updatedAt: value.updated_at,
+  };
+};
 interface IWidget {
   resId?: string;
   resType?: string;
@@ -46,21 +60,6 @@ const DiscussionCreateWidget = ({
   const _currUser = useAppSelector(_currentUser);
   const [currParent, setCurrParent] = useState(parent);
 
-  const toIComment = (value: ICommentApiData): IComment => {
-    return {
-      id: value.id,
-      resId: value.res_id,
-      resType: value.res_type,
-      user: value.editor,
-      title: value.title,
-      parent: value.parent,
-      tplId: value.tpl_id,
-      content: value.content,
-      createdAt: value.created_at,
-      updatedAt: value.updated_at,
-    };
-  };
-
   if (typeof _currUser === "undefined") {
     return <></>;
   } else {
@@ -93,6 +92,9 @@ const DiscussionCreateWidget = ({
                   if (newTopic.ok) {
                     setCurrParent(newTopic.data.id);
                     newParent = newTopic.data.id;
+                    if (typeof onTopicCreated !== "undefined") {
+                      onTopicCreated(toIComment(newTopic.data));
+                    }
                   } else {
                     console.error("no parent id");
                     return;

+ 6 - 1
dashboard/src/components/discussion/DiscussionTopic.tsx

@@ -25,6 +25,7 @@ const DiscussionTopicWidget = ({
 }: IWidget) => {
   const [count, setCount] = useState<number>();
   const [currResId, setCurrResId] = useState<string>();
+  const [currTopicId, setCurrTopicId] = useState(topicId);
   const [currTopic, setCurrTopic] = useState<IComment | undefined>(topic);
   useEffect(() => {
     setCurrTopic(topic);
@@ -32,7 +33,7 @@ const DiscussionTopicWidget = ({
   return (
     <>
       <DiscussionTopicInfo
-        topicId={topicId}
+        topicId={currTopicId}
         topic={currTopic}
         childrenCount={count}
         onReady={(value: IComment) => {
@@ -62,6 +63,10 @@ const DiscussionTopicWidget = ({
             onItemCountChange(count, e);
           }
         }}
+        onTopicCreate={(value: IComment) => {
+          console.log("onTopicCreate", value);
+          setCurrTopicId(value.id);
+        }}
       />
     </>
   );

+ 11 - 4
dashboard/src/components/discussion/DiscussionTopicChildren.tsx

@@ -1,4 +1,5 @@
 import { List, message, Skeleton } from "antd";
+import { IconType } from "antd/lib/notification";
 import { useEffect, useState } from "react";
 import { useIntl } from "react-intl";
 
@@ -9,7 +10,6 @@ import {
   ISentHistoryListResponse,
 } from "../corpus/SentHistory";
 import SentHistoryGroup from "../corpus/SentHistoryGroup";
-import SentHistoryItemWidget from "../corpus/SentHistoryItem";
 import DiscussionCreate from "./DiscussionCreate";
 import DiscussionItem, { IComment } from "./DiscussionItem";
 import { TResType } from "./DiscussionListCard";
@@ -29,6 +29,7 @@ interface IWidget {
   topicId?: string;
   focus?: string;
   onItemCountChange?: Function;
+  onTopicCreate?: Function;
 }
 const DiscussionTopicChildrenWidget = ({
   topic,
@@ -37,6 +38,7 @@ const DiscussionTopicChildrenWidget = ({
   topicId,
   focus,
   onItemCountChange,
+  onTopicCreate,
 }: IWidget) => {
   const intl = useIntl();
   const [data, setData] = useState<IComment[]>([]);
@@ -227,11 +229,16 @@ const DiscussionTopicChildrenWidget = ({
         contentType="markdown"
         parent={topicId}
         topic={currTopic}
-        onCreated={(e: IComment) => {
-          const newData = JSON.parse(JSON.stringify(e));
+        onCreated={(value: IComment) => {
+          const newData = JSON.parse(JSON.stringify(value));
           setData([...data, newData]);
           if (typeof onItemCountChange !== "undefined") {
-            onItemCountChange(data.length + 1, e.parent);
+            onItemCountChange(data.length + 1, value.parent);
+          }
+        }}
+        onTopicCreated={(value: IconType) => {
+          if (typeof onTopicCreate !== "undefined") {
+            onTopicCreate(value);
           }
         }}
       />