ChapterNewList.tsx 3.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104
  1. import { Badge, Card, List, Typography } from "antd";
  2. import { useEffect, useState } from "react";
  3. import { Link, useNavigate } from "react-router";
  4. import { get } from "../../request";
  5. import type { IChapterData, IChapterListResponse } from "../../api/Corpus";
  6. import StudioName from "../auth/Studio";
  7. import type { ChapterData } from "../corpus/ChapterCard";
  8. const { Title, Text, Paragraph } = Typography;
  9. const ChapterNewListWidget = () => {
  10. const [listData, setListData] = useState<ChapterData[]>([]);
  11. const navigate = useNavigate();
  12. useEffect(() => {
  13. get<IChapterListResponse>(`/v2/progress?view=chapter&limit=4&lang=zh`).then(
  14. (json) => {
  15. console.log("chapter list ajax", json);
  16. if (json.ok) {
  17. const newTree: ChapterData[] = json.data.rows.map(
  18. (item: IChapterData) => {
  19. return {
  20. title: item.title,
  21. paliTitle: item.toc,
  22. path: item.path,
  23. book: item.book,
  24. paragraph: item.para,
  25. summary: item.summary,
  26. tag: item.tags.map((item) => {
  27. return { title: item.name, key: item.name };
  28. }),
  29. channel: {
  30. name: item.channel.name,
  31. id: item.channel_id,
  32. type: "translation",
  33. },
  34. studio: item.studio,
  35. progress: Math.round(item.progress * 100),
  36. createdAt: item.created_at,
  37. updatedAt: item.updated_at,
  38. hit: item.view,
  39. like: item.like,
  40. channelInfo: "string",
  41. };
  42. }
  43. );
  44. setListData(newTree);
  45. }
  46. }
  47. );
  48. }, []);
  49. return (
  50. <List
  51. itemLayout="vertical"
  52. size="small"
  53. split={false}
  54. dataSource={listData}
  55. renderItem={(item) => {
  56. const channel = item.channel.id ? `?channel=${item.channel.id}` : "";
  57. return (
  58. <List.Item>
  59. <Badge.Ribbon
  60. text="首发"
  61. color="darkred"
  62. style={{ display: "none" }}
  63. >
  64. <Card
  65. hoverable
  66. bordered={false}
  67. style={{ width: "100%", borderRadius: 20 }}
  68. onClick={(_e) => {
  69. navigate(
  70. `/article/chapter/${item.book}-${item.paragraph}${channel}`
  71. );
  72. }}
  73. >
  74. <Title level={5}>
  75. <Link
  76. to={`/article/chapter/${item.book}-${item.paragraph}${channel}`}
  77. >
  78. {item.title ? item.title : item.paliTitle}
  79. </Link>
  80. </Title>
  81. <div>
  82. <Text type="secondary">{item.paliTitle}</Text>
  83. </div>
  84. <Paragraph
  85. ellipsis={{
  86. rows: 2,
  87. expandable: false,
  88. symbol: "more",
  89. }}
  90. >
  91. <Text>{item.summary}</Text>
  92. </Paragraph>
  93. <StudioName data={item.studio} />
  94. </Card>
  95. </Badge.Ribbon>
  96. </List.Item>
  97. );
  98. }}
  99. />
  100. );
  101. };
  102. export default ChapterNewListWidget;