2
0

ArticleView.tsx 2.1 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697
  1. import { Typography, Divider, Button } 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. const { Paragraph, Title, Text } = Typography;
  8. export interface IWidgetArticleData {
  9. id?: string;
  10. title?: string;
  11. subTitle?: string;
  12. summary?: string;
  13. content?: string;
  14. html?: string;
  15. path?: ITocPathNode[];
  16. created_at?: string;
  17. updated_at?: string;
  18. channels?: string[];
  19. type?: ArticleType;
  20. articleId?: string;
  21. }
  22. const ArticleViewWidget = ({
  23. id,
  24. title = "",
  25. subTitle,
  26. summary,
  27. content,
  28. html,
  29. path = [],
  30. created_at,
  31. updated_at,
  32. channels,
  33. type,
  34. articleId,
  35. }: IWidgetArticleData) => {
  36. let currChannelList = <></>;
  37. switch (type) {
  38. case "chapter":
  39. const chapterProps = articleId?.split("-");
  40. if (typeof chapterProps === "object" && chapterProps.length > 0) {
  41. currChannelList = (
  42. <PaliChapterChannelList
  43. para={{
  44. book: parseInt(chapterProps[0]),
  45. para: parseInt(chapterProps[1]),
  46. }}
  47. channelId={channels}
  48. openTarget="_self"
  49. />
  50. );
  51. }
  52. break;
  53. default:
  54. break;
  55. }
  56. return (
  57. <>
  58. <div style={{ textAlign: "right" }}>
  59. <Button
  60. type="link"
  61. shape="round"
  62. size="small"
  63. icon={<ReloadOutlined />}
  64. />
  65. </div>
  66. <div>
  67. <TocPath data={path} channel={channels} />
  68. <Title level={4}>
  69. <div
  70. dangerouslySetInnerHTML={{
  71. __html: title ? title : "",
  72. }}
  73. />
  74. </Title>
  75. <Text type="secondary">{subTitle}</Text>
  76. {currChannelList}
  77. <Paragraph ellipsis={{ rows: 2, expandable: true, symbol: "more" }}>
  78. {summary}
  79. </Paragraph>
  80. <Divider />
  81. </div>
  82. <div>
  83. <MdView html={html ? html : content} />
  84. </div>
  85. </>
  86. );
  87. };
  88. export default ArticleViewWidget;