| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111 |
- import { useState } from "react";
- import { Button, Dropdown, Space, Typography } from "antd";
- import {
- ShareAltOutlined,
- ExportOutlined,
- ForkOutlined,
- InboxOutlined,
- } from "@ant-design/icons";
- import ExportModal from "./ExportModal";
- import { ArticleType } from "../article/Article";
- import AddToAnthology from "../article/AddToAnthology";
- import { useAppSelector } from "../../hooks";
- import { currentUser } from "../../reducers/current-user";
- import { fullUrl } from "../../utils";
- const { Text } = Typography;
- interface IWidget {
- type?: ArticleType;
- articleId?: string;
- book?: string | null;
- para?: string | null;
- channelId?: string | null;
- anthologyId?: string | null;
- }
- const ShareButtonWidget = ({
- type,
- book,
- para,
- channelId,
- articleId,
- anthologyId,
- }: IWidget) => {
- const [exportOpen, setExportOpen] = useState(false);
- const [addToAnthologyOpen, setAddToAnthologyOpen] = useState(false);
- const user = useAppSelector(currentUser);
- return (
- <>
- <Dropdown
- trigger={["click"]}
- menu={{
- items: [
- {
- label: (
- <Space>
- {"Export"}
- <Text type="secondary" style={{ fontSize: "80%" }}>
- {"PDF,Word,Html"}
- </Text>
- </Space>
- ),
- key: "export",
- icon: <ExportOutlined />,
- },
- {
- label: "添加到文集",
- key: "add_to_anthology",
- icon: <InboxOutlined />,
- disabled: type === "article" ? false : true,
- },
- {
- label: "创建副本",
- key: "fork",
- icon: <ForkOutlined />,
- disabled: user && type === "article" ? false : true,
- },
- ],
- onClick: ({ key }) => {
- switch (key) {
- case "export":
- setExportOpen(true);
- break;
- case "add_to_anthology":
- setAddToAnthologyOpen(true);
- break;
- case "fork":
- const url = `/studio/${user?.nickName}/article/create?parent=${articleId}`;
- window.open(fullUrl(url), "_blank");
- break;
- default:
- break;
- }
- },
- }}
- >
- <Button type="text" icon={<ShareAltOutlined color="#fff" />} />
- </Dropdown>
- <ExportModal
- type={type}
- articleId={articleId}
- book={book}
- para={para}
- channelId={channelId}
- anthologyId={anthologyId}
- open={exportOpen}
- onClose={() => setExportOpen(false)}
- />
- {articleId ? (
- <AddToAnthology
- open={addToAnthologyOpen}
- onClose={(isOpen: boolean) => setAddToAnthologyOpen(isOpen)}
- articleIds={[articleId]}
- />
- ) : undefined}
- </>
- );
- };
- export default ShareButtonWidget;
|