visuddhinanda %!s(int64=2) %!d(string=hai) anos
pai
achega
6cae19eb75
Modificáronse 1 ficheiros con 50 adicións e 0 borrados
  1. 50 0
      dashboard/src/components/anthology/TextBookToc.tsx

+ 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;