浏览代码

术语用fetch note

visuddhinanda 2 年之前
父节点
当前提交
3f8024ba6c
共有 1 个文件被更改,包括 44 次插入3 次删除
  1. 44 3
      dashboard/src/components/template/Term.tsx

+ 44 - 3
dashboard/src/components/template/Term.tsx

@@ -1,4 +1,4 @@
-import { Button, Popover } from "antd";
+import { Button, Popover, Skeleton } from "antd";
 import { Typography } from "antd";
 import { Typography } from "antd";
 import { SearchOutlined, EditOutlined } from "@ant-design/icons";
 import { SearchOutlined, EditOutlined } from "@ant-design/icons";
 import { ProCard } from "@ant-design/pro-components";
 import { ProCard } from "@ant-design/pro-components";
@@ -10,9 +10,16 @@ import { useEffect, useState } from "react";
 import { ITermDataResponse } from "../api/Term";
 import { ITermDataResponse } from "../api/Term";
 import { changedTerm, refresh } from "../../reducers/term-change";
 import { changedTerm, refresh } from "../../reducers/term-change";
 import { useAppSelector } from "../../hooks";
 import { useAppSelector } from "../../hooks";
+import { get } from "../../request";
 
 
 const { Text, Link } = Typography;
 const { Text, Link } = Typography;
 
 
+interface ITermSummary {
+  ok: boolean;
+  message: string;
+  data: string;
+}
+
 interface IWidgetTermCtl {
 interface IWidgetTermCtl {
   id?: string;
   id?: string;
   word?: string;
   word?: string;
@@ -22,6 +29,7 @@ interface IWidgetTermCtl {
   parentChannelId?: string;
   parentChannelId?: string;
   parentStudioId?: string;
   parentStudioId?: string;
   summary?: string;
   summary?: string;
+  isCommunity?: string;
 }
 }
 const TermCtl = ({
 const TermCtl = ({
   id,
   id,
@@ -32,9 +40,12 @@ const TermCtl = ({
   parentChannelId,
   parentChannelId,
   parentStudioId,
   parentStudioId,
   summary,
   summary,
+  isCommunity,
 }: IWidgetTermCtl) => {
 }: IWidgetTermCtl) => {
   const [openPopover, setOpenPopover] = useState(false);
   const [openPopover, setOpenPopover] = useState(false);
   const [termData, setTermData] = useState<ITerm>();
   const [termData, setTermData] = useState<ITerm>();
+  const [content, setContent] = useState<string>();
+
   const newTerm: ITermDataResponse | undefined = useAppSelector(changedTerm);
   const newTerm: ITermDataResponse | undefined = useAppSelector(changedTerm);
 
 
   useEffect(() => {
   useEffect(() => {
@@ -73,6 +84,26 @@ const TermCtl = ({
           open={openPopover}
           open={openPopover}
           onOpenChange={(visible) => {
           onOpenChange={(visible) => {
             setOpenPopover(visible);
             setOpenPopover(visible);
+            if (
+              visible &&
+              typeof content === "undefined" &&
+              typeof id !== "undefined"
+            ) {
+              const value = sessionStorage.getItem(`term/summary/${id}`);
+              if (value !== null) {
+                setContent(value);
+                return;
+              } else {
+                const url = `/v2/term-summary/${id}`;
+                console.log("url", url);
+                get<ITermSummary>(url).then((json) => {
+                  if (json.ok) {
+                    setContent(json.data !== "" ? json.data : " ");
+                    sessionStorage.setItem(`term/summary/${id}`, json.data);
+                  }
+                });
+              }
+            }
           }}
           }}
           content={
           content={
             <ProCard
             <ProCard
@@ -113,12 +144,22 @@ const TermCtl = ({
                 />,
                 />,
               ]}
               ]}
             >
             >
-              <div>{termData.summary}</div>
+              <div>
+                {content ? (
+                  content
+                ) : (
+                  <Skeleton
+                    title={{ width: 200 }}
+                    paragraph={{ rows: 4 }}
+                    active
+                  />
+                )}
+              </div>
             </ProCard>
             </ProCard>
           }
           }
           placement="bottom"
           placement="bottom"
         >
         >
-          <Link>
+          <Link style={{ color: isCommunity ? "green" : undefined }}>
             {termData?.meaning
             {termData?.meaning
               ? termData?.meaning
               ? termData?.meaning
               : termData?.word
               : termData?.word