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

Merge pull request #1491 from visuddhinanda/agile

折叠修改记录#1487
visuddhinanda 2 лет назад
Родитель
Сommit
48ed1c60b5

+ 47 - 0
dashboard/src/components/corpus/SentHistoryGroup.tsx

@@ -0,0 +1,47 @@
+import { Button, Space } from "antd";
+import { useState } from "react";
+import { ISentHistoryData } from "./SentHistory";
+import SentHistoryItem from "./SentHistoryItem";
+
+interface IWidget {
+  data?: ISentHistoryData[];
+  oldContent?: string;
+}
+const SentHistoryGroupWidget = ({ data = [], oldContent }: IWidget) => {
+  const [compact, setCompact] = useState(true);
+  return (
+    <>
+      {data.length > 0 ? (
+        <div>
+          {data.length > 1 ? (
+            <Button type="link" onClick={() => setCompact(!compact)}>
+              {compact ? `显示全部修改记录-${data.length}` : "折叠"}
+            </Button>
+          ) : undefined}
+          {compact ? (
+            <SentHistoryItem
+              data={data[data.length - 1]}
+              oldContent={oldContent}
+            />
+          ) : (
+            <div>
+              {data.map((item, index) => {
+                return (
+                  <SentHistoryItem
+                    key={index}
+                    data={item}
+                    oldContent={
+                      index === 0 ? oldContent : data[index - 1].content
+                    }
+                  />
+                );
+              })}
+            </div>
+          )}
+        </div>
+      ) : undefined}
+    </>
+  );
+};
+
+export default SentHistoryGroupWidget;

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

@@ -40,7 +40,6 @@ const DiscussionItemWidget = ({
   const [edit, setEdit] = useState(false);
   const [currData, setCurrData] = useState<IComment>(data);
   useEffect(() => {
-    console.log("data", data);
     setCurrData(data);
   }, [data]);
   return (

+ 0 - 1
dashboard/src/components/discussion/DiscussionListCard.tsx

@@ -183,7 +183,6 @@ const DiscussionListCardWidget = ({
               },
             ],
             onChange(key) {
-              console.log("show course", key);
               setActiveKey(key);
               ref.current?.reload();
             },

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

@@ -8,6 +8,7 @@ import {
   ISentHistoryData,
   ISentHistoryListResponse,
 } from "../corpus/SentHistory";
+import SentHistoryGroup from "../corpus/SentHistoryGroup";
 import SentHistoryItemWidget from "../corpus/SentHistoryItem";
 import DiscussionCreate from "./DiscussionCreate";
 import DiscussionItem, { IComment } from "./DiscussionItem";
@@ -16,7 +17,7 @@ import { TResType } from "./DiscussionListCard";
 interface IItem {
   type: "comment" | "sent";
   comment?: IComment;
-  sent?: ISentHistoryData;
+  sent?: ISentHistoryData[];
   oldSent?: string;
   date: number;
 }
@@ -74,14 +75,52 @@ const DiscussionTopicChildrenWidget = ({
     const his: IItem[] = hisFiltered.map((item, index) => {
       return {
         type: "sent",
-        sent: item,
+        sent: [item],
         date: new Date(item.created_at ? item.created_at : "").getTime(),
         oldSent: index > 0 ? hisFiltered[index - 1].content : undefined,
       };
     });
     const mixItems = [...comment, ...his];
     mixItems.sort((a, b) => a.date - b.date);
-    setItems(mixItems);
+    console.log("mixItems", mixItems);
+    let newMixItems: IItem[] = [];
+    let currSent: ISentHistoryData[] = [];
+    let currOldSent: string | undefined;
+    let sentBegin = false;
+    mixItems.forEach((value, index, array) => {
+      if (value.type === "comment") {
+        if (sentBegin) {
+          sentBegin = false;
+          newMixItems.push({
+            type: "sent",
+            sent: currSent,
+            date: 0,
+            oldSent: currOldSent,
+          });
+        }
+        newMixItems.push(value);
+      } else {
+        if (value.sent && value.sent.length > 0) {
+          if (sentBegin) {
+            currSent.push(value.sent[0]);
+          } else {
+            sentBegin = true;
+            currSent = value.sent;
+            currOldSent = value.oldSent;
+          }
+        }
+      }
+    });
+    if (sentBegin) {
+      sentBegin = false;
+      newMixItems.push({
+        type: "sent",
+        sent: currSent,
+        date: 0,
+        oldSent: currOldSent,
+      });
+    }
+    setItems(newMixItems);
   }, [data, history, topic?.createdAt]);
 
   useEffect(() => {
@@ -164,7 +203,7 @@ const DiscussionTopicChildrenWidget = ({
                     />
                   ) : undefined
                 ) : (
-                  <SentHistoryItemWidget
+                  <SentHistoryGroup
                     data={item.sent}
                     oldContent={item.oldSent}
                   />