BookViewer.tsx 1.6 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364
  1. import { useState, useEffect } from "react";
  2. import PaliChapterChannelList from "./PaliChapterChannelList";
  3. import PaliChapterListByPara from "./PaliChapterListByPara";
  4. import PaliChapterHead from "./PaliChapterHead";
  5. import { IChapterClickEvent } from "./PaliChapterList";
  6. import { Tabs } from "antd";
  7. export interface IChapter {
  8. book: number;
  9. para: number;
  10. }
  11. interface IWidget {
  12. chapter: IChapter;
  13. onChange?: Function;
  14. }
  15. const BookViewerWidget = ({ chapter, onChange }: IWidget) => {
  16. const [currChapter, setCurrChapter] = useState(chapter);
  17. useEffect(() => {
  18. if (typeof onChange !== "undefined") {
  19. onChange(currChapter);
  20. }
  21. }, [currChapter, onChange]);
  22. useEffect(() => {
  23. setCurrChapter(chapter);
  24. }, [chapter]);
  25. return (
  26. <>
  27. <PaliChapterHead
  28. onChange={(e: IChapter) => {
  29. setCurrChapter(e);
  30. }}
  31. para={currChapter}
  32. />
  33. <Tabs
  34. size="small"
  35. items={[
  36. {
  37. label: `目录`,
  38. key: "toc",
  39. children: (
  40. <PaliChapterListByPara
  41. chapter={currChapter}
  42. onChapterClick={(e: IChapterClickEvent) => {
  43. setCurrChapter({ book: e.para.Book, para: e.para.Paragraph });
  44. console.log("PaliChapterListByPara", "onchange", e);
  45. }}
  46. />
  47. ),
  48. },
  49. {
  50. label: `资源`,
  51. key: "res",
  52. children: <PaliChapterChannelList para={currChapter} />,
  53. },
  54. ]}
  55. />
  56. </>
  57. );
  58. };
  59. export default BookViewerWidget;