ShareButton.tsx 2.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111
  1. import { useState } from "react";
  2. import { Button, Dropdown, Space, Typography } from "antd";
  3. import {
  4. ShareAltOutlined,
  5. ExportOutlined,
  6. ForkOutlined,
  7. InboxOutlined,
  8. } from "@ant-design/icons";
  9. import ExportModal from "./ExportModal";
  10. import { ArticleType } from "../article/Article";
  11. import AddToAnthology from "../article/AddToAnthology";
  12. import { useAppSelector } from "../../hooks";
  13. import { currentUser } from "../../reducers/current-user";
  14. import { fullUrl } from "../../utils";
  15. const { Text } = Typography;
  16. interface IWidget {
  17. type?: ArticleType;
  18. articleId?: string;
  19. book?: string | null;
  20. para?: string | null;
  21. channelId?: string | null;
  22. anthologyId?: string | null;
  23. }
  24. const ShareButtonWidget = ({
  25. type,
  26. book,
  27. para,
  28. channelId,
  29. articleId,
  30. anthologyId,
  31. }: IWidget) => {
  32. const [exportOpen, setExportOpen] = useState(false);
  33. const [addToAnthologyOpen, setAddToAnthologyOpen] = useState(false);
  34. const user = useAppSelector(currentUser);
  35. return (
  36. <>
  37. <Dropdown
  38. trigger={["click"]}
  39. menu={{
  40. items: [
  41. {
  42. label: (
  43. <Space>
  44. {"Export"}
  45. <Text type="secondary" style={{ fontSize: "80%" }}>
  46. {"PDF,Word,Html"}
  47. </Text>
  48. </Space>
  49. ),
  50. key: "export",
  51. icon: <ExportOutlined />,
  52. },
  53. {
  54. label: "添加到文集",
  55. key: "add_to_anthology",
  56. icon: <InboxOutlined />,
  57. disabled: type === "article" ? false : true,
  58. },
  59. {
  60. label: "创建副本",
  61. key: "fork",
  62. icon: <ForkOutlined />,
  63. disabled: user && type === "article" ? false : true,
  64. },
  65. ],
  66. onClick: ({ key }) => {
  67. switch (key) {
  68. case "export":
  69. setExportOpen(true);
  70. break;
  71. case "add_to_anthology":
  72. setAddToAnthologyOpen(true);
  73. break;
  74. case "fork":
  75. const url = `/studio/${user?.nickName}/article/create?parent=${articleId}`;
  76. window.open(fullUrl(url), "_blank");
  77. break;
  78. default:
  79. break;
  80. }
  81. },
  82. }}
  83. >
  84. <Button type="text" icon={<ShareAltOutlined color="#fff" />} />
  85. </Dropdown>
  86. <ExportModal
  87. type={type}
  88. articleId={articleId}
  89. book={book}
  90. para={para}
  91. channelId={channelId}
  92. anthologyId={anthologyId}
  93. open={exportOpen}
  94. onClose={() => setExportOpen(false)}
  95. />
  96. {articleId ? (
  97. <AddToAnthology
  98. open={addToAnthologyOpen}
  99. onClose={(isOpen: boolean) => setAddToAnthologyOpen(isOpen)}
  100. articleIds={[articleId]}
  101. />
  102. ) : undefined}
  103. </>
  104. );
  105. };
  106. export default ShareButtonWidget;