ChapterInChannel.tsx 2.5 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889
  1. import { Col, Layout, Progress, Row, Space, Tabs } from "antd";
  2. import { Typography } from "antd";
  3. import { LikeOutlined, EyeOutlined } from "@ant-design/icons";
  4. import { ChannelInfoProps } from "../api/Channel";
  5. import ChannelListItem from "../channel/ChannelListItem";
  6. import TimeShow from "../utilities/TimeShow";
  7. import { useIntl } from "react-intl";
  8. import { Link } from "react-router-dom";
  9. const { Text } = Typography;
  10. export interface IChapterChannelData {
  11. channel: ChannelInfoProps;
  12. progress: number;
  13. hit: number;
  14. like: number;
  15. updatedAt: string;
  16. }
  17. interface IWidgetChapterInChannel {
  18. data: IChapterChannelData[];
  19. book: number;
  20. para: number;
  21. }
  22. const Widget = ({ data, book, para }: IWidgetChapterInChannel) => {
  23. const intl = useIntl(); //i18n
  24. function getTab(type: string): JSX.Element[] {
  25. const output = data.map((item, id) => {
  26. if (item.channel.channelType === type) {
  27. return (
  28. <div key={id}>
  29. <Row>
  30. <Col span={5}>
  31. <Link
  32. to={`/article/chapter/${book}-${para}_${item.channel.channelId}`}
  33. target="_blank"
  34. >
  35. <ChannelListItem data={item.channel} />
  36. </Link>
  37. </Col>
  38. <Col span={5}>
  39. <Progress percent={item.progress} size="small" />
  40. </Col>
  41. <Col span={8}></Col>
  42. </Row>
  43. <Text type="secondary">
  44. <Space style={{ paddingLeft: "2em" }}>
  45. <EyeOutlined />
  46. {item.hit} | <LikeOutlined />
  47. {item.like} |
  48. <TimeShow time={item.updatedAt} title={item.updatedAt} />
  49. </Space>
  50. </Text>
  51. </div>
  52. );
  53. } else {
  54. return <></>;
  55. }
  56. });
  57. return output;
  58. }
  59. const items = [
  60. {
  61. label: intl.formatMessage({ id: "channel.type.translation.label" }),
  62. key: "translation",
  63. children: getTab("translation"),
  64. },
  65. {
  66. label: intl.formatMessage({ id: "channel.type.nissaya.label" }),
  67. key: "nissaya",
  68. children: getTab("nissaya"),
  69. },
  70. {
  71. label: intl.formatMessage({ id: "channel.type.commentary.label" }),
  72. key: "commentary",
  73. children: getTab("commentary"),
  74. },
  75. {
  76. label: intl.formatMessage({ id: "channel.type.original.label" }),
  77. key: "original",
  78. children: getTab("original"),
  79. },
  80. ];
  81. return <Tabs items={items} />;
  82. };
  83. export default Widget;