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

按照topic创建时间过滤历史记录

visuddhinanda 2 лет назад
Родитель
Сommit
fac75d46dc

+ 3 - 0
dashboard/src/components/discussion/DiscussionTopic.tsx

@@ -21,6 +21,7 @@ const DiscussionTopicWidget = ({
 }: IWidget) => {
   const [count, setCount] = useState<number>();
   const [currResId, setCurrResId] = useState<string>();
+  const [topic, setTopic] = useState<IComment>();
   return (
     <>
       <DiscussionTopicInfo
@@ -28,6 +29,7 @@ const DiscussionTopicWidget = ({
         childrenCount={count}
         onReady={(value: IComment) => {
           setCurrResId(value.resId);
+          setTopic(value);
           console.log("onReady", value);
           if (typeof onTopicReady !== "undefined") {
             onTopicReady(value);
@@ -35,6 +37,7 @@ const DiscussionTopicWidget = ({
         }}
       />
       <DiscussionTopicChildren
+        topic={topic}
         resId={currResId}
         resType={resType}
         focus={focus}

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

@@ -22,6 +22,7 @@ interface IItem {
 }
 
 interface IWidget {
+  topic?: IComment;
   resId?: string;
   resType?: TResType;
   topicId?: string;
@@ -29,6 +30,7 @@ interface IWidget {
   onItemCountChange?: Function;
 }
 const DiscussionTopicChildrenWidget = ({
+  topic,
   resId,
   resType,
   topicId,
@@ -50,18 +52,15 @@ const DiscussionTopicChildrenWidget = ({
   });
 
   useEffect(() => {
-    let first = new Date().getTime();
     const comment: IItem[] = data.map((item) => {
       const date = new Date(item.createdAt ? item.createdAt : "").getTime();
-      if (date < first) {
-        first = date;
-      }
       return {
         type: "comment",
         comment: item,
         date: date,
       };
     });
+    const first = new Date(topic?.createdAt ? topic?.createdAt : "").getTime();
     const hisFiltered = history.filter(
       (value) =>
         new Date(value.created_at ? value.created_at : "").getTime() > first
@@ -77,7 +76,7 @@ const DiscussionTopicChildrenWidget = ({
     const mixItems = [...comment, ...his];
     mixItems.sort((a, b) => a.date - b.date);
     setItems(mixItems);
-  }, [data, history]);
+  }, [data, history, topic?.createdAt]);
 
   useEffect(() => {
     if (resType === "sentence" && resId) {