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

Merge pull request #1578 from visuddhinanda/agile

支持术语翻译
visuddhinanda 2 лет назад
Родитель
Сommit
dba28c820b

+ 121 - 76
dashboard/src/components/article/Article.tsx

@@ -20,6 +20,8 @@ import {
   IRecentResponse,
 } from "../../pages/studio/recent/list";
 import { ITocPathNode } from "../corpus/TocPath";
+import { useSearchParams } from "react-router-dom";
+import { ITermResponse } from "../api/Term";
 
 export type ArticleMode = "read" | "edit" | "wbw";
 export type ArticleType =
@@ -91,6 +93,7 @@ const ArticleWidget = ({
   const [showSkeleton, setShowSkeleton] = useState(true);
   const [unauthorized, setUnauthorized] = useState(false);
   const [remains, setRemains] = useState(false);
+  const [searchParams] = useSearchParams();
 
   const channels = channelId?.split("_");
 
@@ -135,7 +138,9 @@ const ArticleWidget = ({
     if (!active) {
       return;
     }
+
     if (typeof type !== "undefined") {
+      const debug = searchParams.get("debug");
       let url = "";
       switch (type) {
         case "chapter":
@@ -186,6 +191,12 @@ const ArticleWidget = ({
             );
           }
           break;
+        case "term":
+          if (typeof articleId !== "undefined") {
+            url = `/v2/terms/${articleId}?mode=${srcDataMode}`;
+            url += channelId ? `&channel=${channelId}` : "";
+          }
+          break;
         default:
           if (typeof articleId !== "undefined") {
             url = `/v2/corpus/${type}/${articleId}/${srcDataMode}?mode=${srcDataMode}`;
@@ -193,6 +204,9 @@ const ArticleWidget = ({
           }
           break;
       }
+      if (debug) {
+        url += `&debug=${debug}`;
+      }
       console.log("article url", url);
       setShowSkeleton(true);
       if (typeof articleId !== "undefined") {
@@ -211,87 +225,118 @@ const ArticleWidget = ({
         });
       }
 
-      get<IArticleResponse>(url)
-        .then((json) => {
-          console.log("article", json);
-          if (json.ok) {
-            setArticleData(json.data);
-            if (json.data.html) {
-              setArticleHtml([json.data.html]);
-            } else if (json.data.content) {
-              setArticleHtml([json.data.content]);
-            }
-            if (json.data.from) {
-              setRemains(true);
+      if (type === "term") {
+        get<ITermResponse>(url)
+          .then((json) => {
+            if (json.ok) {
+              setArticleData({
+                uid: json.data.guid,
+                title: json.data.meaning,
+                subtitle: json.data.word,
+                summary: json.data.note,
+                content: json.data.note ? json.data.note : "",
+                content_type: "markdown",
+                html: json.data.html,
+                path: [],
+                status: 30,
+                lang: json.data.language,
+                created_at: json.data.created_at,
+                updated_at: json.data.updated_at,
+              });
+              if (json.data.html) {
+                setArticleHtml([json.data.html]);
+              } else if (json.data.note) {
+                setArticleHtml([json.data.note]);
+              }
+              setShowSkeleton(false);
             }
-            setShowSkeleton(false);
+          })
+          .catch((error) => {
+            console.error(error);
+          });
+      } else {
+        get<IArticleResponse>(url)
+          .then((json) => {
+            console.log("article", json);
+            if (json.ok) {
+              setArticleData(json.data);
+              if (json.data.html) {
+                setArticleHtml([json.data.html]);
+              } else if (json.data.content) {
+                setArticleHtml([json.data.content]);
+              }
+              if (json.data.from) {
+                setRemains(true);
+              }
+              setShowSkeleton(false);
 
-            setExtra(
-              <TocTree
-                treeData={json.data.toc?.map((item) => {
-                  const strTitle = item.title ? item.title : item.pali_title;
-                  const key = item.key
-                    ? item.key
-                    : `${item.book}-${item.paragraph}`;
-                  const progress = item.progress?.map((item, id) => (
-                    <Tag key={id}>{Math.round(item * 100) + "%"}</Tag>
-                  ));
-                  return {
-                    key: key,
-                    title: (
-                      <Space>
-                        <PaliText
-                          text={strTitle === "" ? "[unnamed]" : strTitle}
-                        />
-                        {progress}
-                      </Space>
-                    ),
-                    level: item.level,
-                  };
-                })}
-                onSelect={(keys: string[]) => {
-                  console.log(keys);
-                  if (
-                    typeof onArticleChange !== "undefined" &&
-                    keys.length > 0
-                  ) {
-                    onArticleChange(keys[0]);
-                  }
-                }}
-              />
-            );
+              setExtra(
+                <TocTree
+                  treeData={json.data.toc?.map((item) => {
+                    const strTitle = item.title ? item.title : item.pali_title;
+                    const key = item.key
+                      ? item.key
+                      : `${item.book}-${item.paragraph}`;
+                    const progress = item.progress?.map((item, id) => (
+                      <Tag key={id}>{Math.round(item * 100) + "%"}</Tag>
+                    ));
+                    return {
+                      key: key,
+                      title: (
+                        <Space>
+                          <PaliText
+                            text={strTitle === "" ? "[unnamed]" : strTitle}
+                          />
+                          {progress}
+                        </Space>
+                      ),
+                      level: item.level,
+                    };
+                  })}
+                  onSelect={(keys: string[]) => {
+                    console.log(keys);
+                    if (
+                      typeof onArticleChange !== "undefined" &&
+                      keys.length > 0
+                    ) {
+                      onArticleChange(keys[0]);
+                    }
+                  }}
+                />
+              );
 
-            switch (type) {
-              case "chapter":
-                if (typeof articleId === "string" && channelId) {
-                  const [book, para] = articleId?.split("-");
-                  post<IViewRequest, IViewStoreResponse>("/v2/view", {
-                    target_type: type,
-                    book: parseInt(book),
-                    para: parseInt(para),
-                    channel: channelId,
-                    mode: srcDataMode,
-                  }).then((json) => {
-                    console.log("view", json.data);
-                  });
-                }
-                break;
-              default:
-                break;
-            }
+              switch (type) {
+                case "chapter":
+                  if (typeof articleId === "string" && channelId) {
+                    const [book, para] = articleId?.split("-");
+                    post<IViewRequest, IViewStoreResponse>("/v2/view", {
+                      target_type: type,
+                      book: parseInt(book),
+                      para: parseInt(para),
+                      channel: channelId,
+                      mode: srcDataMode,
+                    }).then((json) => {
+                      console.log("view", json.data);
+                    });
+                  }
+                  break;
+                default:
+                  break;
+              }
 
-            if (typeof onLoad !== "undefined") {
-              onLoad(json.data);
+              if (typeof onLoad !== "undefined") {
+                onLoad(json.data);
+              }
+            } else {
+              setShowSkeleton(false);
+              setUnauthorized(true);
+              message.error(json.message);
             }
-          } else {
-            setShowSkeleton(false);
-            setUnauthorized(true);
-            message.error(json.message);
-          }
-        })
-        .catch((e) => {
-          console.error(e);
-        });
+          })
+          .catch((e) => {
+            console.error(e);
+          });
+      }
     }
   }, [
     active,

+ 20 - 17
dashboard/src/components/discussion/DiscussionListCard.tsx

@@ -79,20 +79,19 @@ const DiscussionListCardWidget = ({
           title: {
             render(dom, entity, index, action, schema) {
               return (
-                <>
-                  <Button
-                    size="small"
-                    type="link"
-                    icon={entity.newTpl ? <TemplateOutlinedIcon /> : undefined}
-                    onClick={(event) => {
-                      if (typeof onSelect !== "undefined") {
-                        onSelect(event, entity);
-                      }
-                    }}
-                  >
-                    {entity.title}
-                  </Button>
-                </>
+                <Button
+                  key={index}
+                  size="small"
+                  type="link"
+                  icon={entity.newTpl ? <TemplateOutlinedIcon /> : undefined}
+                  onClick={(event) => {
+                    if (typeof onSelect !== "undefined") {
+                      onSelect(event, entity);
+                    }
+                  }}
+                >
+                  {entity.title}
+                </Button>
               );
             },
           },
@@ -100,15 +99,19 @@ const DiscussionListCardWidget = ({
             dataIndex: "content",
             search: false,
             render(dom, entity, index, action, schema) {
-              return entity.summary ? entity.summary : entity.content;
+              return (
+                <span key={index}>
+                  {entity.summary ? entity.summary : entity.content}
+                </span>
+              );
             },
           },
           actions: {
             render: (text, row, index, action) => [
               row.childrenCount ? (
                 <Space key={index}>
-                  <CommentOutlinedIcon />
-                  {row.childrenCount}
+                  <CommentOutlinedIcon key={"icon"} />
+                  <span key={"count"}>{row.childrenCount}</span>
                 </Space>
               ) : (
                 <></>

+ 12 - 3
dashboard/src/components/term/TermItem.tsx

@@ -1,5 +1,9 @@
 import { Button, Card, Dropdown, Space, Typography } from "antd";
-import { MoreOutlined, EditOutlined } from "@ant-design/icons";
+import {
+  MoreOutlined,
+  EditOutlined,
+  TranslationOutlined,
+} from "@ant-design/icons";
 
 import { ITermDataResponse } from "../api/Term";
 import MdView from "../template/MdView";
@@ -8,6 +12,7 @@ import TimeShow from "../general/TimeShow";
 import TermModal from "./TermModal";
 import { useState } from "react";
 import StudioName from "../auth/StudioName";
+import { useNavigate } from "react-router-dom";
 
 const { Text } = Typography;
 
@@ -16,6 +21,8 @@ interface IWidget {
 }
 const TermItemWidget = ({ data }: IWidget) => {
   const [openTermModal, setOpenTermModal] = useState(false);
+  const navigate = useNavigate();
+
   return (
     <>
       <Card
@@ -49,7 +56,7 @@ const TermItemWidget = ({ data }: IWidget) => {
                 {
                   key: "translate",
                   label: "translate",
-                  icon: <EditOutlined />,
+                  icon: <TranslationOutlined />,
                 },
               ],
               onClick: (e) => {
@@ -58,7 +65,9 @@ const TermItemWidget = ({ data }: IWidget) => {
                   case "edit":
                     setOpenTermModal(true);
                     break;
-
+                  case "translate":
+                    navigate(`/article/term/${data?.guid}`);
+                    break;
                   default:
                     break;
                 }