2
0

SentSim.tsx 2.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103
  1. import { Button, Divider, List, Space, Switch } from "antd";
  2. import { ReloadOutlined } from "@ant-design/icons";
  3. import type {
  4. ISentenceSimListResponse,
  5. ISentSimParams,
  6. } from "../../api/sent-sim";
  7. import { useSentSim } from "../../hooks/useSentSim";
  8. import SentCanRead from "./SentCanRead";
  9. import MdView from "../general/MdView";
  10. type Fetcher = (params: ISentSimParams) => Promise<ISentenceSimListResponse>;
  11. interface IWidget {
  12. book: number;
  13. para: number;
  14. wordStart: number;
  15. wordEnd: number;
  16. channelsId?: string[];
  17. limit?: number;
  18. /** 可替换为 mock 函数,默认使用真实请求 */
  19. fetcher?: Fetcher;
  20. onCreate?: () => void;
  21. }
  22. const SentSimWidget = ({
  23. book,
  24. para,
  25. wordStart,
  26. wordEnd,
  27. limit = 5,
  28. channelsId,
  29. fetcher,
  30. onCreate,
  31. }: IWidget) => {
  32. const {
  33. sentData,
  34. remain,
  35. initLoading,
  36. loading,
  37. toggleSim,
  38. loadMore,
  39. reload,
  40. } = useSentSim({
  41. book,
  42. para,
  43. wordStart,
  44. wordEnd,
  45. limit,
  46. channelsId,
  47. fetcher,
  48. });
  49. return (
  50. <>
  51. <SentCanRead
  52. book={book}
  53. para={para}
  54. wordStart={wordStart}
  55. wordEnd={wordEnd}
  56. type="similar"
  57. channelsId={channelsId}
  58. onCreate={onCreate}
  59. />
  60. <List
  61. loading={initLoading}
  62. header={
  63. <div style={{ display: "flex", justifyContent: "space-between" }}>
  64. <span />
  65. <Space>
  66. {"只显示相同句"}
  67. <Switch onChange={toggleSim} />
  68. <Button
  69. type="link"
  70. shape="round"
  71. icon={<ReloadOutlined />}
  72. loading={loading}
  73. onClick={reload}
  74. />
  75. </Space>
  76. </div>
  77. }
  78. itemLayout="horizontal"
  79. split={false}
  80. loadMore={
  81. <Divider>
  82. <Button disabled={remain <= 0} onClick={loadMore} loading={loading}>
  83. load more
  84. </Button>
  85. </Divider>
  86. }
  87. dataSource={sentData}
  88. renderItem={(item, index) => (
  89. <List.Item>
  90. <MdView html={item.sent} key={index} style={{ width: "100%" }} />
  91. </List.Item>
  92. )}
  93. />
  94. </>
  95. );
  96. };
  97. export default SentSimWidget;