Forráskód Böngészése

Merge pull request #1964 from visuddhinanda/agile

添加课本目录树
visuddhinanda 2 éve
szülő
commit
96c890a7cd

+ 50 - 0
dashboard/src/components/anthology/TextBookToc.tsx

@@ -0,0 +1,50 @@
+import { useEffect, useState } from "react";
+import AnthologyTocTree from "./AnthologyTocTree";
+import { get } from "../../request";
+import { ICourseResponse } from "../api/Course";
+
+interface IWidget {
+  courseId?: string | null;
+  channels?: string[];
+  onSelect?: Function;
+  onClick?: Function;
+  onArticleSelect?: Function;
+}
+const TextBookTocWidget = ({
+  courseId,
+  channels,
+  onSelect,
+  onClick,
+  onArticleSelect,
+}: IWidget) => {
+  const [anthologyId, setAnthologyId] = useState<string>();
+
+  useEffect(() => {
+    if (!courseId) {
+      return;
+    }
+    const url = `/v2/course/${courseId}`;
+    console.debug("course url", url);
+    get<ICourseResponse>(url).then((json) => {
+      console.debug("course data", json.data);
+      if (json.ok) {
+        setAnthologyId(json.data.anthology_id);
+      }
+    });
+  }, [courseId]);
+
+  return (
+    <AnthologyTocTree
+      anthologyId={anthologyId}
+      channels={channels}
+      onClick={(anthology: string, article: string, target: string) => {
+        console.debug("AnthologyTocTree onClick", article);
+        if (typeof onClick !== "undefined") {
+          onClick(article, target);
+        }
+      }}
+    />
+  );
+};
+
+export default TextBookTocWidget;

+ 16 - 0
dashboard/src/components/article/ToolButtonToc.tsx

@@ -5,11 +5,13 @@ import { ArticleType } from "./Article";
 
 
 import PaliTextToc from "./PaliTextToc";
 import PaliTextToc from "./PaliTextToc";
 import ToolButton from "./ToolButton";
 import ToolButton from "./ToolButton";
+import TextBookToc from "../anthology/TextBookToc";
 
 
 interface IWidget {
 interface IWidget {
   type?: ArticleType;
   type?: ArticleType;
   articleId?: string;
   articleId?: string;
   anthologyId?: string | null;
   anthologyId?: string | null;
+  courseId?: string | null;
   channels?: string[];
   channels?: string[];
   onSelect?: Function;
   onSelect?: Function;
 }
 }
@@ -17,6 +19,7 @@ const ToolButtonTocWidget = ({
   type,
   type,
   articleId,
   articleId,
   anthologyId,
   anthologyId,
+  courseId,
   channels,
   channels,
   onSelect,
   onSelect,
 }: IWidget) => {
 }: IWidget) => {
@@ -53,6 +56,19 @@ const ToolButtonTocWidget = ({
         />
         />
       );
       );
     }
     }
+  } else if (type === "textbook") {
+    tocWidget = (
+      <TextBookToc
+        courseId={courseId}
+        channels={channels}
+        onClick={(article: string, target: string) => {
+          console.debug("TextBookToc onClick", article);
+          if (typeof onSelect !== "undefined") {
+            onSelect(article, target);
+          }
+        }}
+      />
+    );
   }
   }
 
 
   return (
   return (

+ 2 - 1
dashboard/src/pages/library/article/show.tsx

@@ -307,8 +307,9 @@ const Widget = () => {
                   articleId={id}
                   articleId={id}
                   channels={searchParams.get("channel")?.split("_")}
                   channels={searchParams.get("channel")?.split("_")}
                   anthologyId={searchParams.get("anthology")}
                   anthologyId={searchParams.get("anthology")}
+                  courseId={searchParams.get("course")}
                   onSelect={(key: Key, target?: string) => {
                   onSelect={(key: Key, target?: string) => {
-                    console.log("toc click", key);
+                    console.debug("toc click", key);
                     const newType = type === "para" ? "chapter" : type;
                     const newType = type === "para" ? "chapter" : type;
                     let url = `/article/${newType}/${key}?`;
                     let url = `/article/${newType}/${key}?`;
                     let param: string[] = [];
                     let param: string[] = [];