Browse Source

add 在编辑器中打开

visuddhinanda 2 years ago
parent
commit
ed015b1f6b

+ 16 - 2
dashboard/src/components/discussion/DiscussionAnchor.tsx

@@ -3,17 +3,28 @@ import { useEffect, useState } from "react";
 import { get } from "../../request";
 import { IArticleResponse } from "../api/Article";
 import { ICommentAnchorResponse } from "../api/Comment";
-import { ISentenceResponse } from "../api/Corpus";
+import { ISentenceData, ISentenceResponse } from "../api/Corpus";
 import MdView from "../template/MdView";
 import AnchorCard from "./AnchorCard";
 import { TResType } from "./DiscussionListCard";
 
+export interface IAnchor {
+  type: TResType;
+  sentence?: ISentenceData;
+}
+
 interface IWidget {
   resId?: string;
   resType?: TResType;
   topicId?: string;
+  onLoad?: Function;
 }
-const DiscussionAnchorWidget = ({ resId, resType, topicId }: IWidget) => {
+const DiscussionAnchorWidget = ({
+  resId,
+  resType,
+  topicId,
+  onLoad,
+}: IWidget) => {
   const [content, setContent] = useState<string>();
   const [loading, setLoading] = useState(true);
   useEffect(() => {
@@ -46,6 +57,9 @@ const DiscussionAnchorWidget = ({ resId, resType, topicId }: IWidget) => {
                   setContent(json.data.content);
                 }
               });
+              if (typeof onLoad !== "undefined") {
+                onLoad({ type: resType, sentence: json.data });
+              }
             }
           })
           .finally(() => setLoading(false));

+ 28 - 3
dashboard/src/pages/library/discussion/topic.tsx

@@ -1,10 +1,12 @@
 import { useState } from "react";
-import { useNavigate } from "react-router-dom";
+import { Link, useNavigate } from "react-router-dom";
 import { Button, Card, Divider } from "antd";
 import { useParams } from "react-router-dom";
 import { ArrowLeftOutlined } from "@ant-design/icons";
 
-import CommentAnchor from "../../../components/discussion/DiscussionAnchor";
+import CommentAnchor, {
+  IAnchor,
+} from "../../../components/discussion/DiscussionAnchor";
 import { IComment } from "../../../components/discussion/DiscussionItem";
 import DiscussionTopic from "../../../components/discussion/DiscussionTopic";
 
@@ -12,12 +14,35 @@ const Widget = () => {
   const { id } = useParams(); //url 参数
   const navigate = useNavigate();
   const [discussion, setDiscussion] = useState<IComment>();
+  const [anchorInfo, setAnchorInfo] = useState<IAnchor>();
   const href = window.location.href.split("#");
   const anchor = href.length > 1 ? href[1] : undefined;
 
+  const book = anchorInfo?.sentence?.book;
+  const para = anchorInfo?.sentence?.paragraph;
+  let openPara: number[] = [];
+  if (para) {
+    openPara = [para - 1, para, para + 1];
+  }
+  const linkId = `${book}-${para}`;
+  const linkChannel = anchorInfo?.sentence?.channel.id;
+  let linkOpen = `/article/para/${linkId}?mode=edit&book=${book}&par=${openPara.join(
+    ","
+  )}&channel=${linkChannel}&topic=${id}&dis_type=sentence`;
+  if (anchor) {
+    linkOpen += `&comment=${anchor}`;
+  }
   return (
     <>
-      <CommentAnchor resId={discussion?.resId} resType={discussion?.resType} />
+      {anchorInfo ? <Link to={linkOpen}>在翻译界面中打开</Link> : undefined}
+
+      <CommentAnchor
+        resId={discussion?.resId}
+        resType={discussion?.resType}
+        onLoad={(value: IAnchor) => {
+          setAnchorInfo(value);
+        }}
+      />
       <Divider></Divider>
       <Card
         title={