ChapterCard.tsx 2.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106
  1. import { Link } from "react-router";
  2. import { Row, Col, Progress, Space } from "antd";
  3. import { Typography } from "antd";
  4. import TimeShow from "../general/TimeShow";
  5. import TocPath from "./TocPath";
  6. import TagArea from "../tag/TagAreaInChapter";
  7. import type { IChannelApiData } from "../../api/Channel";
  8. import ChannelListItem from "../channel/ChannelListItem";
  9. import type { IStudio } from "../auth/Studio";
  10. import type { ITagData } from "./ChapterTag";
  11. const { Title, Paragraph, Text } = Typography;
  12. export interface ChapterData {
  13. title: string;
  14. paliTitle: string;
  15. path: string;
  16. book: number;
  17. paragraph: number;
  18. summary: string;
  19. tag: ITagData[];
  20. channel: IChannelApiData;
  21. studio: IStudio;
  22. progress: number;
  23. progressLine?: number[];
  24. createdAt: string;
  25. updatedAt: string;
  26. hit: number;
  27. like: number;
  28. }
  29. interface IWidget {
  30. data: ChapterData;
  31. onTagClick?: Function;
  32. }
  33. const ChapterCardWidget = ({ data, onTagClick }: IWidget) => {
  34. const path = JSON.parse(data.path);
  35. let url = `/article/chapter/${data.book}-${data.paragraph}`;
  36. url += data.channel.id ? `?channel=${data.channel.id}` : "";
  37. return (
  38. <Row>
  39. <Col>
  40. <Row>
  41. <Col span={16}>
  42. <Title level={5}>
  43. <Link to={url} target="_blank">
  44. {data.title ? data.title : data.paliTitle}
  45. </Link>
  46. </Title>
  47. <Text type="secondary">{data.paliTitle}</Text>
  48. <TocPath data={path} />
  49. </Col>
  50. <Col span={8}>
  51. <Progress percent={data.progress} size="small" />
  52. </Col>
  53. </Row>
  54. <Row>
  55. <Col>
  56. <Paragraph
  57. ellipsis={{
  58. rows: 2,
  59. expandable: false,
  60. symbol: "more",
  61. }}
  62. >
  63. {data.summary}
  64. </Paragraph>
  65. </Col>
  66. </Row>
  67. <div
  68. style={{
  69. display: "flex",
  70. flexWrap: "wrap",
  71. justifyContent: "space-between",
  72. }}
  73. >
  74. <div>
  75. <TagArea
  76. data={data.tag}
  77. onTagClick={(tag: string) => {
  78. if (typeof onTagClick !== "undefined") {
  79. onTagClick(tag);
  80. }
  81. }}
  82. />
  83. </div>
  84. <Space
  85. style={{
  86. flexWrap: "wrap",
  87. justifyContent: "flex-end",
  88. marginLeft: "auto",
  89. fontSize: 12,
  90. }}
  91. >
  92. <ChannelListItem channel={data.channel} studio={data.studio} />
  93. <TimeShow updatedAt={data.updatedAt} />
  94. </Space>
  95. </div>
  96. </Col>
  97. </Row>
  98. );
  99. };
  100. export default ChapterCardWidget;