From 8344766ae30594eff58b81b2a2da57c2b142ffbf Mon Sep 17 00:00:00 2001 From: Niklas Date: Mon, 16 Aug 2021 01:42:29 +0200 Subject: [PATCH] implemented copy paste --- src/components/FileBrowser.tsx | 14 +++++-- src/components/FileBrowserContextMenu.tsx | 8 +++- src/generated/graphql.tsx | 50 ++++++++++++++++++++++- src/graphql/copy.graphql | 5 +++ 4 files changed, 71 insertions(+), 6 deletions(-) create mode 100644 src/graphql/copy.graphql diff --git a/src/components/FileBrowser.tsx b/src/components/FileBrowser.tsx index dcb4534..ca43cda 100644 --- a/src/components/FileBrowser.tsx +++ b/src/components/FileBrowser.tsx @@ -2,7 +2,7 @@ import React from "react" import { useState } from "react" import { useContextMenu } from "react-contexify" import uploadFile from "../functions/uploadFile" -import { useDeleteFileMutation, useOpenDirQuery } from "../generated/graphql" +import { useCopyMutation, useDeleteFileMutation, useOpenDirQuery } from "../generated/graphql" import Breadcrum from "./Breadcrum" import DragAndDrop from "./DragAndDrop" import FileBrowserContextMenu, { Action, CONTEXT_MENU_DIR, CONTEXT_MENU_FILE } from "./FileBrowserContextMenu" @@ -15,7 +15,10 @@ const FileBrowser: React.FC = () => { const [openFileId, setOpenFileId] = useState("") const [showFile, setShowFile] = useState(false) + const [srcID,setSrcID] = useState("") + const [deleteMutation] = useDeleteFileMutation() + const [copyMutation] = useCopyMutation() const { show: showFileContext } = useContextMenu({ id: CONTEXT_MENU_FILE, @@ -60,12 +63,16 @@ const FileBrowser: React.FC = () => { } function onContextSelect(action:Action, id: string) { - console.debug(action) switch (action) { case Action.FileDelete: deleteMutation({variables:{id}}) break - + case Action.FileCopy: + setSrcID(id) + break + case Action.FilePaste: + copyMutation({variables:{src:srcID,dest:path}}) + break default: break } @@ -75,6 +82,7 @@ const FileBrowser: React.FC = () => {
{ diff --git a/src/components/FileBrowserContextMenu.tsx b/src/components/FileBrowserContextMenu.tsx index d2d53e9..5786e53 100644 --- a/src/components/FileBrowserContextMenu.tsx +++ b/src/components/FileBrowserContextMenu.tsx @@ -6,11 +6,14 @@ export const CONTEXT_MENU_FILE = "CONTEXT_MENU_FILE" export const CONTEXT_MENU_DIR = "CONTEXT_MENU_DIR" export enum Action { - FileDelete + FileDelete, + FileCopy, + FilePaste } interface Props { onSelect?: (action: Action, id: string)=>void + pasteActive?: boolean } const FileBrowserContextMenu: React.FC = (props) => { @@ -25,7 +28,8 @@ const FileBrowserContextMenu: React.FC = (props) => { <> Delete - Item 2 + Copy + Paste Disabled diff --git a/src/generated/graphql.tsx b/src/generated/graphql.tsx index bef51b1..81b251f 100644 --- a/src/generated/graphql.tsx +++ b/src/generated/graphql.tsx @@ -60,8 +60,8 @@ export type RootMutationDeleteArgs = { export type RootMutationMoveArgs = { - src: Scalars["ID"]; dest: Scalars["ID"]; + src: Scalars["ID"]; }; export type RootQuery = { @@ -86,6 +86,20 @@ export type RootQueryFilesArgs = { path: Scalars["String"]; }; +export type CopyMutationVariables = Exact<{ + src: Scalars["ID"]; + dest: Scalars["ID"]; +}>; + + +export type CopyMutation = ( + { __typename?: "RootMutation" } + & { copy?: Maybe<( + { __typename?: "File" } + & Pick + )> } +); + export type DeleteFileMutationVariables = Exact<{ id: Scalars["ID"]; }>; @@ -126,6 +140,40 @@ export type OpenDirQuery = ( ); +export const CopyDocument = gql` + mutation copy($src: ID!, $dest: ID!) { + copy(src: $src, dest: $dest) { + id + } +} + ` +export type CopyMutationFn = Apollo.MutationFunction; + +/** + * __useCopyMutation__ + * + * To run a mutation, you first call `useCopyMutation` within a React component and pass it any options that fit your needs. + * When your component renders, `useCopyMutation` returns a tuple that includes: + * - A mutate function that you can call at any time to execute the mutation + * - An object with fields that represent the current status of the mutation's execution + * + * @param baseOptions options that will be passed into the mutation, supported options are listed on: https://www.apollographql.com/docs/react/api/react-hooks/#options-2; + * + * @example + * const [copyMutation, { data, loading, error }] = useCopyMutation({ + * variables: { + * src: // value for 'src' + * dest: // value for 'dest' + * }, + * }); + */ +export function useCopyMutation(baseOptions?: Apollo.MutationHookOptions) { + const options = {...defaultOptions, ...baseOptions} + return Apollo.useMutation(CopyDocument, options) +} +export type CopyMutationHookResult = ReturnType; +export type CopyMutationResult = Apollo.MutationResult; +export type CopyMutationOptions = Apollo.BaseMutationOptions; export const DeleteFileDocument = gql` mutation deleteFile($id: ID!) { delete(id: $id) diff --git a/src/graphql/copy.graphql b/src/graphql/copy.graphql new file mode 100644 index 0000000..38c8b33 --- /dev/null +++ b/src/graphql/copy.graphql @@ -0,0 +1,5 @@ +mutation copy($src: ID!, $dest: ID!) { + copy(src: $src,dest: $dest){ + id + } +}