|
|
@@ -1,7 +1,7 @@
|
|
|
import { useState, useEffect } from "react";
|
|
|
|
|
|
import { get } from "../../request";
|
|
|
-import { IApiResponsePaliChapterList } from "../api/Corpus";
|
|
|
+import { IPaliChapterListResponse } from "../api/Corpus";
|
|
|
import { IPaliChapterData } from "./PaliChapterCard";
|
|
|
import PaliChapterList, { IChapterClickEvent } from "./PaliChapterList";
|
|
|
|
|
|
@@ -9,27 +9,31 @@ interface IWidgetPaliChapterListByTag {
|
|
|
tag: string[];
|
|
|
onChapterClick?: Function;
|
|
|
}
|
|
|
-const defaultData: IPaliChapterData[] = [];
|
|
|
+
|
|
|
const Widget = (prop: IWidgetPaliChapterListByTag) => {
|
|
|
- const [tableData, setTableData] = useState(defaultData);
|
|
|
+ const [tableData, setTableData] = useState<IPaliChapterData[]>([]);
|
|
|
|
|
|
useEffect(() => {
|
|
|
console.log("palichapterlist useEffect");
|
|
|
let url = `/v2/palitext?view=chapter&tags=${prop.tag.join()}`;
|
|
|
console.log("tag url", url);
|
|
|
- get<IApiResponsePaliChapterList>(url).then((json) => {
|
|
|
- let newTree: IPaliChapterData[] = json.data.rows.map((item) => {
|
|
|
- return {
|
|
|
- Title: item.title,
|
|
|
- PaliTitle: item.title,
|
|
|
- level: item.level,
|
|
|
- Path: item.path,
|
|
|
- Book: item.book,
|
|
|
- Paragraph: item.paragraph,
|
|
|
- progressLine: item.progress_line,
|
|
|
- };
|
|
|
- });
|
|
|
- setTableData(newTree);
|
|
|
+ get<IPaliChapterListResponse>(url).then((json) => {
|
|
|
+ if (json.ok) {
|
|
|
+ let newTree: IPaliChapterData[] = json.data.rows.map((item) => {
|
|
|
+ return {
|
|
|
+ Title: item.title,
|
|
|
+ PaliTitle: item.title,
|
|
|
+ level: item.level,
|
|
|
+ Path: item.path,
|
|
|
+ Book: item.book,
|
|
|
+ Paragraph: item.paragraph,
|
|
|
+ progressLine: item.progress_line,
|
|
|
+ };
|
|
|
+ });
|
|
|
+ setTableData(newTree);
|
|
|
+ } else {
|
|
|
+ console.error(json.message);
|
|
|
+ }
|
|
|
});
|
|
|
}, [prop.tag]);
|
|
|
|