فهرست منبع

add fork button

visuddhinanda 2 سال پیش
والد
کامیت
aa97fbd12a
1فایلهای تغییر یافته به همراه23 افزوده شده و 3 حذف شده
  1. 23 3
      dashboard/src/components/export/ShareButton.tsx

+ 23 - 3
dashboard/src/components/export/ShareButton.tsx

@@ -1,9 +1,18 @@
+import { useState } from "react";
 import { Button, Dropdown, Space, Typography } from "antd";
-import { ShareAltOutlined, ExportOutlined } from "@ant-design/icons";
+import {
+  ShareAltOutlined,
+  ExportOutlined,
+  ForkOutlined,
+  InboxOutlined,
+} from "@ant-design/icons";
+
 import ExportModal from "./ExportModal";
-import { useState } from "react";
 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;
 
@@ -25,6 +34,7 @@ const ShareButtonWidget = ({
 }: IWidget) => {
   const [exportOpen, setExportOpen] = useState(false);
   const [addToAnthologyOpen, setAddToAnthologyOpen] = useState(false);
+  const user = useAppSelector(currentUser);
 
   return (
     <>
@@ -47,7 +57,13 @@ const ShareButtonWidget = ({
             {
               label: "添加到文集",
               key: "add_to_anthology",
-              icon: <ExportOutlined />,
+              icon: <InboxOutlined />,
+            },
+            {
+              label: "创建副本",
+              key: "fork",
+              icon: <ForkOutlined />,
+              disabled: user && type === "article" ? false : true,
             },
           ],
           onClick: ({ key }) => {
@@ -58,6 +74,10 @@ const ShareButtonWidget = ({
               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;
             }