Browse Source

Merge pull request #1784 from visuddhinanda/agile

添加文章导航按钮
visuddhinanda 2 years ago
parent
commit
919cead415

+ 11 - 0
dashboard/src/components/api/Article.ts

@@ -178,6 +178,17 @@ export interface IDeleteResponse {
   message: string;
   data: number;
 }
+export interface IArticleNavResponse {
+  ok: boolean;
+  data: IArticleNavData;
+  message: string;
+}
+
+export interface IArticleNavData {
+  curr?: IArticleMapRequest;
+  prev?: IArticleMapRequest;
+  next?: IArticleMapRequest;
+}
 
 export interface IPageNavResponse {
   ok: boolean;

+ 34 - 1
dashboard/src/components/article/TypeArticle.tsx

@@ -2,7 +2,12 @@ import { useEffect, useState } from "react";
 import { Divider, message, Space, Tag } from "antd";
 
 import { get } from "../../request";
-import { IArticleDataResponse, IArticleResponse } from "../api/Article";
+import {
+  IArticleDataResponse,
+  IArticleNavData,
+  IArticleNavResponse,
+  IArticleResponse,
+} from "../api/Article";
 import ArticleView, { IFirstAnthology } from "./ArticleView";
 import TocTree from "./TocTree";
 import PaliText from "../template/Wbw/PaliText";
@@ -12,6 +17,7 @@ import "./article.css";
 import ArticleSkeleton from "./ArticleSkeleton";
 import ErrorResult from "../general/ErrorResult";
 import AnthologiesAtArticle from "./AnthologiesAtArticle";
+import NavigateButton from "./NavigateButton";
 
 interface IWidget {
   type?: ArticleType;
@@ -43,6 +49,7 @@ const TypeArticleWidget = ({
   const [loading, setLoading] = useState(false);
   const [errorCode, setErrorCode] = useState<number>();
   const [currPath, setCurrPath] = useState<ITocPathNode[]>();
+  const [nav, setNav] = useState<IArticleNavData>();
 
   const channels = channelId?.split("_");
 
@@ -125,6 +132,18 @@ const TypeArticleWidget = ({
       });
   }, [active, type, articleId, srcDataMode, channelId, anthologyId]);
 
+  useEffect(() => {
+    const url = `/v2/nav-article/${articleId}_${anthologyId}`;
+    get<IArticleNavResponse>(url)
+      .then((json) => {
+        if (json.ok) {
+          setNav(json.data);
+        }
+      })
+      .catch((e) => {
+        console.error(e);
+      });
+  }, [anthologyId, articleId]);
   let anthology: IFirstAnthology | undefined;
   if (articleData?.anthology_count && articleData.anthology_first) {
     anthology = {
@@ -195,6 +214,20 @@ const TypeArticleWidget = ({
           <Divider />
           {extra}
           <Divider />
+          <NavigateButton
+            prevTitle={nav?.prev?.title}
+            nextTitle={nav?.next?.title}
+            onNext={() => {
+              if (typeof onArticleChange !== "undefined") {
+                onArticleChange("article", nav?.next?.article_id);
+              }
+            }}
+            onPrev={() => {
+              if (typeof onArticleChange !== "undefined") {
+                onArticleChange("article", nav?.prev?.article_id);
+              }
+            }}
+          />
         </>
       )}
     </div>

+ 1 - 1
dashboard/src/components/template/ParaHandle.tsx

@@ -43,7 +43,7 @@ export const ParaHandleCtl = ({
     {
       key: "quote-link-tpl",
       label: intl.formatMessage({
-        id: "labels.curr.paragraph.quote.link.tpl",
+        id: "labels.curr.paragraph.copy.quote.link.tpl",
       }),
       children: [
         {

+ 2 - 1
dashboard/src/locales/zh-Hans/label.ts

@@ -27,8 +27,9 @@ const items = {
   "labels.page.number.type.para": "缅文段落",
   "labels.curr.paragraph.only": "仅显示此段",
   "labels.curr.paragraph.open": "在新标签页打开",
-  "labels.curr.paragraph.copy.tpl": "复制句子模版",
+  "labels.curr.paragraph.copy.tpl": "复制句子编号",
   "labels.curr.paragraph.quote.link.tpl": "引用链接模版",
+  "labels.curr.paragraph.copy.quote.link.tpl": "复制引用模版",
 };
 
 export default items;