Forráskód Böngészése

更新后调用 discussionCountUpgrade

visuddhinanda 2 éve
szülő
commit
44f1e14de7

+ 7 - 0
dashboard/src/components/discussion/DiscussionCreate.tsx

@@ -21,6 +21,7 @@ import { currentUser as _currentUser } from "../../reducers/current-user";
 import { useEffect, useRef, useState } from "react";
 import { useEffect, useRef, useState } from "react";
 import MDEditor from "@uiw/react-md-editor";
 import MDEditor from "@uiw/react-md-editor";
 import { TDiscussionType } from "./Discussion";
 import { TDiscussionType } from "./Discussion";
+import { discussionCountUpgrade } from "./DiscussionCount";
 
 
 export type TContentType = "text" | "markdown" | "html" | "json";
 export type TContentType = "text" | "markdown" | "html" | "json";
 
 
@@ -85,6 +86,10 @@ const DiscussionCreateWidget = ({
               let newParent: string | undefined;
               let newParent: string | undefined;
               if (typeof currParent === "undefined") {
               if (typeof currParent === "undefined") {
                 if (typeof topic !== "undefined" && topic.tplId) {
                 if (typeof topic !== "undefined" && topic.tplId) {
+                  /**
+                   * 在模版下跟帖
+                   * 先建立模版topic,再建立跟帖
+                   */
                   const topicData: ICommentRequest = {
                   const topicData: ICommentRequest = {
                     res_id: resId,
                     res_id: resId,
                     res_type: resType,
                     res_type: resType,
@@ -101,6 +106,7 @@ const DiscussionCreateWidget = ({
                     ICommentResponse
                     ICommentResponse
                   >(url, topicData);
                   >(url, topicData);
                   if (newTopic.ok) {
                   if (newTopic.ok) {
+                    discussionCountUpgrade(resId);
                     setCurrParent(newTopic.data.id);
                     setCurrParent(newTopic.data.id);
                     newParent = newTopic.data.id;
                     newParent = newTopic.data.id;
                     if (typeof onTopicCreated !== "undefined") {
                     if (typeof onTopicCreated !== "undefined") {
@@ -129,6 +135,7 @@ const DiscussionCreateWidget = ({
                   console.debug("new discussion api response", json);
                   console.debug("new discussion api response", json);
                   if (json.ok) {
                   if (json.ok) {
                     formRef.current?.resetFields();
                     formRef.current?.resetFields();
+                    discussionCountUpgrade(resId);
                     if (typeof onCreated !== "undefined") {
                     if (typeof onCreated !== "undefined") {
                       onCreated(toIComment(json.data));
                       onCreated(toIComment(json.data));
                     }
                     }

+ 8 - 3
dashboard/src/components/discussion/DiscussionShow.tsx

@@ -33,6 +33,7 @@ import { ICommentRequest, ICommentResponse } from "../api/Comment";
 import { useState } from "react";
 import { useState } from "react";
 import MdView from "../template/MdView";
 import MdView from "../template/MdView";
 import { TDiscussionType } from "./Discussion";
 import { TDiscussionType } from "./Discussion";
+import { discussionCountUpgrade } from "./DiscussionCount";
 
 
 const { Text } = Typography;
 const { Text } = Typography;
 
 
@@ -58,7 +59,7 @@ const DiscussionShowWidget = ({
 }: IWidget) => {
 }: IWidget) => {
   const intl = useIntl();
   const intl = useIntl();
   const [closed, setClosed] = useState(data.status);
   const [closed, setClosed] = useState(data.status);
-  const showDeleteConfirm = (id: string, title: string) => {
+  const showDeleteConfirm = (id: string, resId: string, title: string) => {
     Modal.confirm({
     Modal.confirm({
       icon: <ExclamationCircleOutlined />,
       icon: <ExclamationCircleOutlined />,
       title:
       title:
@@ -85,6 +86,7 @@ const DiscussionShowWidget = ({
             console.debug("api response", json);
             console.debug("api response", json);
             if (json.ok) {
             if (json.ok) {
               message.success("删除成功");
               message.success("删除成功");
+              discussionCountUpgrade(resId);
               if (typeof onDelete !== "undefined") {
               if (typeof onDelete !== "undefined") {
                 onDelete(id);
                 onDelete(id);
               }
               }
@@ -109,9 +111,12 @@ const DiscussionShowWidget = ({
       console.log(json);
       console.log(json);
       if (json.ok) {
       if (json.ok) {
         setClosed(json.data.status);
         setClosed(json.data.status);
+        discussionCountUpgrade(data.resId);
         if (typeof onClose !== "undefined") {
         if (typeof onClose !== "undefined") {
           onClose(value);
           onClose(value);
         }
         }
+      } else {
+        message.error(json.message);
       }
       }
     });
     });
   };
   };
@@ -182,8 +187,8 @@ const DiscussionShowWidget = ({
         convert("discussion");
         convert("discussion");
         break;
         break;
       case "delete":
       case "delete":
-        if (data.id) {
-          showDeleteConfirm(data.id, data.title ? data.title : "");
+        if (data.id && data.resId) {
+          showDeleteConfirm(data.id, data.resId, data.title ?? "");
         }
         }
         break;
         break;
       default:
       default: