BookViewer.tsx 1.6 KB

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