ChapterCard.tsx 2.6 KB

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