ArticleView.tsx 2.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121
  1. import { Typography, Divider, Button, Skeleton } from "antd";
  2. import { ReloadOutlined } from "@ant-design/icons";
  3. import MdView from "../template/MdView";
  4. import TocPath, { ITocPathNode } from "../corpus/TocPath";
  5. import PaliChapterChannelList from "../corpus/PaliChapterChannelList";
  6. import { ArticleType } from "./Article";
  7. import VisibleObserver from "../general/VisibleObserver";
  8. const { Paragraph, Title, Text } = Typography;
  9. export interface IWidgetArticleData {
  10. id?: string;
  11. title?: string;
  12. subTitle?: string;
  13. summary?: string;
  14. content?: string;
  15. html?: string[];
  16. path?: ITocPathNode[];
  17. created_at?: string;
  18. updated_at?: string;
  19. channels?: string[];
  20. type?: ArticleType;
  21. articleId?: string;
  22. remains?: boolean;
  23. onEnd?: Function;
  24. }
  25. const ArticleViewWidget = ({
  26. id,
  27. title = "",
  28. subTitle,
  29. summary,
  30. content,
  31. html = [],
  32. path = [],
  33. created_at,
  34. updated_at,
  35. channels,
  36. type,
  37. articleId,
  38. onEnd,
  39. remains,
  40. }: IWidgetArticleData) => {
  41. let currChannelList = <></>;
  42. switch (type) {
  43. case "chapter":
  44. const chapterProps = articleId?.split("-");
  45. if (typeof chapterProps === "object" && chapterProps.length > 0) {
  46. currChannelList = (
  47. <PaliChapterChannelList
  48. para={{
  49. book: parseInt(chapterProps[0]),
  50. para: parseInt(chapterProps[1]),
  51. }}
  52. channelId={channels}
  53. openTarget="_self"
  54. />
  55. );
  56. }
  57. break;
  58. default:
  59. break;
  60. }
  61. return (
  62. <>
  63. <div style={{ textAlign: "right" }}>
  64. <Button
  65. type="link"
  66. shape="round"
  67. size="small"
  68. icon={<ReloadOutlined />}
  69. />
  70. </div>
  71. <div>
  72. <TocPath data={path} channel={channels} />
  73. <Title level={4}>
  74. <div
  75. dangerouslySetInnerHTML={{
  76. __html: title ? title : "",
  77. }}
  78. />
  79. </Title>
  80. <Text type="secondary">{subTitle}</Text>
  81. {currChannelList}
  82. <Paragraph ellipsis={{ rows: 2, expandable: true, symbol: "more" }}>
  83. {summary}
  84. </Paragraph>
  85. <Divider />
  86. </div>
  87. {html
  88. ? html.map((item, id) => {
  89. return (
  90. <div key={id}>
  91. <MdView className="pcd_article" html={item} />
  92. </div>
  93. );
  94. })
  95. : content}
  96. {remains ? (
  97. <>
  98. <VisibleObserver
  99. onVisible={(visible: boolean) => {
  100. console.log("visible", visible);
  101. if (visible && typeof onEnd !== "undefined") {
  102. onEnd();
  103. }
  104. }}
  105. />
  106. <Skeleton title={{ width: 200 }} paragraph={{ rows: 5 }} active />
  107. </>
  108. ) : undefined}
  109. </>
  110. );
  111. };
  112. export default ArticleViewWidget;