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

在翻译界面加载时打开topic

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

+ 19 - 6
dashboard/src/components/discussion/DiscussionBox.tsx

@@ -1,4 +1,4 @@
-import { useState } from "react";
+import { useEffect, useState } from "react";
 import { ArrowLeftOutlined } from "@ant-design/icons";
 
 import DiscussionTopic from "./DiscussionTopic";
@@ -16,14 +16,22 @@ export interface IAnswerCount {
 
 const DiscussionBoxWidget = () => {
   const [childrenDrawer, setChildrenDrawer] = useState(false);
-  const [topicComment, setTopicComment] = useState<IComment>();
+  const [topicId, setTopicId] = useState<string>();
   const [answerCount, setAnswerCount] = useState<IAnswerCount>();
+  const [currTopic, setCurrTopic] = useState<IComment>();
 
   const discussionMessage = useAppSelector(message);
 
+  useEffect(() => {
+    if (discussionMessage?.topic) {
+      setChildrenDrawer(true);
+      setTopicId(discussionMessage?.topic);
+    }
+  }, [discussionMessage]);
+
   const showChildrenDrawer = (comment: IComment) => {
     setChildrenDrawer(true);
-    setTopicComment(comment);
+    setTopicId(comment.id);
   };
 
   return (
@@ -34,7 +42,9 @@ const DiscussionBoxWidget = () => {
           store.dispatch(
             showAnchor({
               type: "discussion",
-              resId: discussionMessage?.resId,
+              resId: discussionMessage?.resId
+                ? discussionMessage?.resId
+                : currTopic?.resId,
               resType: discussionMessage?.resType,
             })
           );
@@ -50,12 +60,15 @@ const DiscussionBoxWidget = () => {
             onClick={() => setChildrenDrawer(false)}
           />
           <DiscussionTopic
-            resId={discussionMessage?.resId}
             resType={discussionMessage?.resType}
-            topicId={topicComment?.id}
+            topicId={topicId}
+            focus={discussionMessage?.comment}
             onItemCountChange={(count: number, parent: string) => {
               setAnswerCount({ id: parent, count: count });
             }}
+            onTopicReady={(value: IComment) => {
+              setCurrTopic(value);
+            }}
           />
         </div>
       ) : (

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

@@ -6,7 +6,6 @@ import { IComment } from "./DiscussionItem";
 import { TResType } from "./DiscussionListCard";
 
 interface IWidget {
-  resId?: string;
   resType?: TResType;
   topicId?: string;
   focus?: string;
@@ -14,7 +13,6 @@ interface IWidget {
   onTopicReady?: Function;
 }
 const DiscussionTopicWidget = ({
-  resId,
   resType,
   topicId,
   focus,
@@ -22,19 +20,22 @@ const DiscussionTopicWidget = ({
   onItemCountChange,
 }: IWidget) => {
   const [count, setCount] = useState<number>();
+  const [currResId, setCurrResId] = useState<string>();
   return (
     <>
       <DiscussionTopicInfo
         topicId={topicId}
         childrenCount={count}
         onReady={(value: IComment) => {
+          setCurrResId(value.resId);
+          console.log("onReady", value);
           if (typeof onTopicReady !== "undefined") {
             onTopicReady(value);
           }
         }}
       />
       <DiscussionTopicChildren
-        resId={resId}
+        resId={currResId}
         resType={resType}
         focus={focus}
         topicId={topicId}

+ 17 - 1
dashboard/src/pages/library/article/show.tsx

@@ -38,6 +38,9 @@ import store from "../../../store";
 import { IRecent } from "../../../components/recent/RecentList";
 import { convertToPlain, fullUrl } from "../../../utils";
 import ThemeSelect from "../../../components/general/ThemeSelect";
+import { show } from "../../../reducers/discussion";
+import { openPanel } from "../../../reducers/right-panel";
+import { TResType } from "../../../components/discussion/DiscussionListCard";
 
 /**
  * type:
@@ -306,8 +309,21 @@ const Widget = () => {
               }}
               onLoad={(article: IArticleDataResponse) => {
                 setLoadedArticleData(article);
-
                 document.title = convertToPlain(article.title).slice(0, 128);
+                const paramTopic = searchParams.get("topic");
+                const paramComment = searchParams.get("comment");
+                const paramType = searchParams.get("dis_type");
+                if (paramTopic !== null && paramType !== null) {
+                  store.dispatch(
+                    show({
+                      type: "discussion",
+                      topic: paramTopic,
+                      resType: paramType as TResType,
+                      comment: paramComment ? paramComment : undefined,
+                    })
+                  );
+                  store.dispatch(openPanel("discussion"));
+                }
               }}
               onAnthologySelect={(id: string) => {
                 let output: any = { anthology: id };

+ 2 - 0
dashboard/src/reducers/discussion.ts

@@ -13,6 +13,8 @@ export interface IShowDiscussion {
   type: "discussion" | "pr";
   resType?: TResType;
   resId?: string;
+  topic?: string;
+  comment?: string;
 }
 export interface ICount {
   count: number;