Explorar o código

回答问题后更新问题后面的跟帖数

visuddhinanda %!s(int64=3) %!d(string=hai) anos
pai
achega
05d81ffc2a

+ 9 - 0
dashboard/src/components/comment/CommentBox.tsx

@@ -4,6 +4,10 @@ import CommentTopic from "./CommentTopic";
 import CommentListCard from "./CommentListCard";
 import { IComment } from "./CommentItem";
 
+export interface IAnswerCount {
+  id: string;
+  count: number;
+}
 interface IWidget {
   trigger?: JSX.Element;
   resId?: string;
@@ -14,6 +18,7 @@ const Widget = ({ trigger, resId, resType, onCommentCountChange }: IWidget) => {
   const [open, setOpen] = useState(false);
   const [childrenDrawer, setChildrenDrawer] = useState(false);
   const [topicComment, setTopicComment] = useState<IComment>();
+  const [answerCount, setAnswerCount] = useState<IAnswerCount>();
   console.log(resId, resType);
   const showDrawer = () => {
     setOpen(true);
@@ -49,6 +54,7 @@ const Widget = ({ trigger, resId, resType, onCommentCountChange }: IWidget) => {
           resId={resId}
           resType={resType}
           onSelect={showChildrenDrawer}
+          changedAnswerCount={answerCount}
           onItemCountChange={(count: number) => {
             if (typeof onCommentCountChange !== "undefined") {
               onCommentCountChange(count);
@@ -67,6 +73,9 @@ const Widget = ({ trigger, resId, resType, onCommentCountChange }: IWidget) => {
               comment={topicComment}
               resId={resId}
               resType={resType}
+              onItemCountChange={(count: number, parent: string) => {
+                setAnswerCount({ id: parent, count: count });
+              }}
             />
           ) : (
             <></>

+ 1 - 1
dashboard/src/components/comment/CommentCreate.tsx

@@ -57,7 +57,6 @@ const Widget = ({ resId, resType, parent, onCreated }: IWidget) => {
             .then((json) => {
               console.log("new discussion", json);
               if (json.ok) {
-                message.success(intl.formatMessage({ id: "flashes.success" }));
                 if (typeof onCreated !== "undefined") {
                   onCreated({
                     id: json.data.id,
@@ -76,6 +75,7 @@ const Widget = ({ resId, resType, parent, onCreated }: IWidget) => {
                         : "null",
                     },
                     title: json.data.title,
+                    parent: json.data.parent,
                     content: json.data.content,
                     createdAt: json.data.created_at,
                     updatedAt: json.data.updated_at,

+ 2 - 4
dashboard/src/components/comment/CommentEdit.tsx

@@ -36,7 +36,7 @@ const Widget = ({ data, onCreated }: IWidget) => {
         setSaving(false);
 
         if (json.ok) {
-          message.success(intl.formatMessage({ id: "flashes.success" }));
+          console.log(intl.formatMessage({ id: "flashes.success" }));
         } else {
           message.error(json.message);
         }
@@ -79,9 +79,7 @@ const Widget = ({ data, onCreated }: IWidget) => {
               .then((json) => {
                 console.log(json);
                 if (json.ok) {
-                  message.success(
-                    intl.formatMessage({ id: "flashes.success" })
-                  );
+                  console.log(intl.formatMessage({ id: "flashes.success" }));
                   if (typeof onCreated !== "undefined") {
                     onCreated(json.data);
                   }

+ 21 - 6
dashboard/src/components/comment/CommentListCard.tsx

@@ -2,32 +2,47 @@ import { useState, useEffect } from "react";
 import { useIntl } from "react-intl";
 import { Card, message } from "antd";
 
-import { useAppSelector } from "../../hooks";
-import { currentUser as _currentUser } from "../../reducers/current-user";
 import { get } from "../../request";
 import { ICommentListResponse } from "../api/Comment";
 import CommentCreate from "./CommentCreate";
 import { IComment } from "./CommentItem";
 import CommentList from "./CommentList";
+import { IAnswerCount } from "./CommentBox";
 
 interface IWidget {
   resId?: string;
   resType?: string;
+  changedAnswerCount?: IAnswerCount;
   onSelect?: Function;
   onItemCountChange?: Function;
 }
-const Widget = ({ resId, resType, onSelect, onItemCountChange }: IWidget) => {
+const Widget = ({
+  resId,
+  resType,
+  onSelect,
+  changedAnswerCount,
+  onItemCountChange,
+}: IWidget) => {
   const intl = useIntl();
   const [data, setData] = useState<IComment[]>([]);
-
-  const _currUser = useAppSelector(_currentUser);
+  useEffect(() => {
+    console.log("changedAnswerCount", changedAnswerCount);
+    const newData = data.map((item) => {
+      const newItem = item;
+      if (newItem.id && changedAnswerCount?.id === newItem.id) {
+        newItem.childrenCount = changedAnswerCount.count;
+      }
+      return newItem;
+    });
+    setData(newData);
+  }, [changedAnswerCount]);
 
   useEffect(() => {
     get<ICommentListResponse>(`/v2/discussion?view=question&id=${resId}`)
       .then((json) => {
         console.log(json);
         if (json.ok) {
-          message.success(intl.formatMessage({ id: "flashes.success" }));
+          console.log(intl.formatMessage({ id: "flashes.success" }));
           const discussions: IComment[] = json.data.rows.map((item) => {
             return {
               id: item.id,

+ 2 - 2
dashboard/src/components/comment/CommentTopic.tsx

@@ -39,7 +39,7 @@ const Widget = ({ resId, resType, comment, onItemCountChange }: IWidget) => {
       .then((json) => {
         console.log(json);
         if (json.ok) {
-          message.success(intl.formatMessage({ id: "flashes.success" }));
+          console.log(intl.formatMessage({ id: "flashes.success" }));
           const discussions: IComment[] = json.data.rows.map((item) => {
             return {
               id: item.id,
@@ -79,7 +79,7 @@ const Widget = ({ resId, resType, comment, onItemCountChange }: IWidget) => {
           console.log("create", e);
           const newData = JSON.parse(JSON.stringify(e));
           if (typeof onItemCountChange !== "undefined") {
-            onItemCountChange(childrenData.length + 1);
+            onItemCountChange(childrenData.length + 1, e.parent);
           }
           setChildrenData([...childrenData, newData]);
         }}