Ver Fonte

获取article

visuddhinanda há 2 anos atrás
pai
commit
5ca92a163e
1 ficheiros alterados com 28 adições e 4 exclusões
  1. 28 4
      dashboard/src/components/discussion/DiscussionAnchor.tsx

+ 28 - 4
dashboard/src/components/discussion/DiscussionAnchor.tsx

@@ -7,6 +7,7 @@ import { ISentenceData, ISentenceResponse } from "../api/Corpus";
 import MdView from "../template/MdView";
 import MdView from "../template/MdView";
 import AnchorCard from "./AnchorCard";
 import AnchorCard from "./AnchorCard";
 import { TResType } from "./DiscussionListCard";
 import { TResType } from "./DiscussionListCard";
+import { Link } from "react-router-dom";
 
 
 export interface IAnchor {
 export interface IAnchor {
   type: TResType;
   type: TResType;
@@ -25,8 +26,10 @@ const DiscussionAnchorWidget = ({
   topicId,
   topicId,
   onLoad,
   onLoad,
 }: IWidget) => {
 }: IWidget) => {
+  const [title, setTitle] = useState<React.ReactNode>();
   const [content, setContent] = useState<string>();
   const [content, setContent] = useState<string>();
-  const [loading, setLoading] = useState(true);
+  const [loading, setLoading] = useState(false);
+
   useEffect(() => {
   useEffect(() => {
     if (typeof topicId === "string") {
     if (typeof topicId === "string") {
       get<ICommentAnchorResponse>(`/v2/discussion-anchor/${topicId}`).then(
       get<ICommentAnchorResponse>(`/v2/discussion-anchor/${topicId}`).then(
@@ -41,10 +44,12 @@ const DiscussionAnchorWidget = ({
   }, [topicId]);
   }, [topicId]);
 
 
   useEffect(() => {
   useEffect(() => {
+    let url: string;
     switch (resType) {
     switch (resType) {
       case "sentence":
       case "sentence":
-        const url = `/v2/sentence/${resId}`;
+        url = `/v2/sentence/${resId}`;
         console.log("url", url);
         console.log("url", url);
+        setLoading(true);
         get<ISentenceResponse>(url)
         get<ISentenceResponse>(url)
           .then((json) => {
           .then((json) => {
             if (json.ok) {
             if (json.ok) {
@@ -64,16 +69,35 @@ const DiscussionAnchorWidget = ({
           })
           })
           .finally(() => setLoading(false));
           .finally(() => setLoading(false));
         break;
         break;
+      case "article":
+        url = `/v2/article/${resId}`;
+        console.info("url", url);
+        setLoading(true);
+
+        get<IArticleResponse>(url)
+          .then((json) => {
+            if (json.ok) {
+              setTitle(
+                <Link to={`/article/article/${resId}`}>{json.data.title}</Link>
+              );
+              setContent(json.data.content?.substring(0, 200));
+            }
+          })
+          .finally(() => setLoading(false));
+        break;
       default:
       default:
         break;
         break;
     }
     }
   }, [resId, resType]);
   }, [resId, resType]);
+
   return (
   return (
-    <AnchorCard>
+    <AnchorCard title={title}>
       {loading ? (
       {loading ? (
         <Skeleton title={{ width: 200 }} paragraph={{ rows: 4 }} active />
         <Skeleton title={{ width: 200 }} paragraph={{ rows: 4 }} active />
       ) : (
       ) : (
-        <MdView html={content} />
+        <div>
+          <MdView html={content} />
+        </div>
       )}
       )}
     </AnchorCard>
     </AnchorCard>
   );
   );