AnthologyStudioList.tsx 1.5 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556
  1. import { Link } from "react-router";
  2. import { useState, useEffect } from "react";
  3. import { List, Space, Card } from "antd";
  4. import StudioName from "../auth/Studio";
  5. import type { IAnthologyStudioListApiResponse } from "../../api/Article";
  6. import type { IStudioApiResponse } from "../../api/Auth";
  7. import { get } from "../../request";
  8. interface IAnthologyStudioData {
  9. count: number;
  10. studio: IStudioApiResponse;
  11. }
  12. /*
  13. interface IWidgetAnthologyList {
  14. data: IAnthologyData[];
  15. }
  16. */
  17. const AnthologyStudioListWidget = () => {
  18. const [tableData, setTableData] = useState<IAnthologyStudioData[]>([]);
  19. useEffect(() => {
  20. console.log("useEffect");
  21. const url = `/v2/anthology?view=studio_list`;
  22. get<IAnthologyStudioListApiResponse>(url).then(function (json) {
  23. const newTree: IAnthologyStudioData[] = json.data.rows.map((item) => {
  24. return {
  25. count: item.count,
  26. studio: item.studio,
  27. };
  28. });
  29. setTableData(newTree);
  30. });
  31. }, []);
  32. return (
  33. <Card title="作者" size="small">
  34. <List
  35. itemLayout="vertical"
  36. size="small"
  37. dataSource={tableData}
  38. renderItem={(item) => (
  39. <List.Item>
  40. <Link to={`/blog/${item.studio.realName}/anthology`}>
  41. <Space>
  42. <StudioName data={item.studio} />
  43. <span>({item.count})</span>
  44. </Space>
  45. </Link>
  46. </List.Item>
  47. )}
  48. />
  49. </Card>
  50. );
  51. };
  52. export default AnthologyStudioListWidget;