diff --git a/src/components/FileBrowser.tsx b/src/components/FileBrowser.tsx index ca43cda..4d9f18d 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 { useCopyMutation, useDeleteFileMutation, useOpenDirQuery } from "../generated/graphql" +import { useCopyMutation, useDeleteFileMutation, useMoveMutation, useOpenDirQuery } from "../generated/graphql" import Breadcrum from "./Breadcrum" import DragAndDrop from "./DragAndDrop" import FileBrowserContextMenu, { Action, CONTEXT_MENU_DIR, CONTEXT_MENU_FILE } from "./FileBrowserContextMenu" @@ -16,9 +16,11 @@ const FileBrowser: React.FC = () => { const [showFile, setShowFile] = useState(false) const [srcID,setSrcID] = useState("") + const [pasteAction,setPasteAction] = useState() const [deleteMutation] = useDeleteFileMutation() const [copyMutation] = useCopyMutation() + const [moveMutation] = useMoveMutation() const { show: showFileContext } = useContextMenu({ id: CONTEXT_MENU_FILE, @@ -68,10 +70,18 @@ const FileBrowser: React.FC = () => { deleteMutation({variables:{id}}) break case Action.FileCopy: + case Action.FileMove: setSrcID(id) + setPasteAction(action) break case Action.FilePaste: - copyMutation({variables:{src:srcID,dest:path}}) + if (pasteAction === Action.FileCopy){ + copyMutation({variables:{src:srcID,dest:path}}) + } + + if (pasteAction === Action.FileMove){ + moveMutation({variables:{src:srcID,dest:path}}) + } break default: break diff --git a/src/components/FileBrowserContextMenu.tsx b/src/components/FileBrowserContextMenu.tsx index 5786e53..974beb3 100644 --- a/src/components/FileBrowserContextMenu.tsx +++ b/src/components/FileBrowserContextMenu.tsx @@ -8,7 +8,8 @@ export const CONTEXT_MENU_DIR = "CONTEXT_MENU_DIR" export enum Action { FileDelete, FileCopy, - FilePaste + FilePaste, + FileMove } interface Props { @@ -29,6 +30,7 @@ const FileBrowserContextMenu: React.FC = (props) => { Delete Copy + Move Paste Disabled diff --git a/src/generated/graphql.tsx b/src/generated/graphql.tsx index 81b251f..e004365 100644 --- a/src/generated/graphql.tsx +++ b/src/generated/graphql.tsx @@ -123,6 +123,20 @@ export type GetFileQuery = ( )> } ); +export type MoveMutationVariables = Exact<{ + src: Scalars["ID"]; + dest: Scalars["ID"]; +}>; + + +export type MoveMutation = ( + { __typename?: "RootMutation" } + & { move?: Maybe<( + { __typename?: "File" } + & Pick + )> } +); + export type OpenDirQueryVariables = Exact<{ path: Scalars["String"]; }>; @@ -244,6 +258,40 @@ export function useGetFileLazyQuery(baseOptions?: Apollo.LazyQueryHookOptions; export type GetFileLazyQueryHookResult = ReturnType; export type GetFileQueryResult = Apollo.QueryResult; +export const MoveDocument = gql` + mutation move($src: ID!, $dest: ID!) { + move(src: $src, dest: $dest) { + id + } +} + ` +export type MoveMutationFn = Apollo.MutationFunction; + +/** + * __useMoveMutation__ + * + * To run a mutation, you first call `useMoveMutation` within a React component and pass it any options that fit your needs. + * When your component renders, `useMoveMutation` 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 [moveMutation, { data, loading, error }] = useMoveMutation({ + * variables: { + * src: // value for 'src' + * dest: // value for 'dest' + * }, + * }); + */ +export function useMoveMutation(baseOptions?: Apollo.MutationHookOptions) { + const options = {...defaultOptions, ...baseOptions} + return Apollo.useMutation(MoveDocument, options) +} +export type MoveMutationHookResult = ReturnType; +export type MoveMutationResult = Apollo.MutationResult; +export type MoveMutationOptions = Apollo.BaseMutationOptions; export const OpenDirDocument = gql` query openDir($path: String!) { files(path: $path) { diff --git a/src/graphql/move.graphql b/src/graphql/move.graphql new file mode 100644 index 0000000..20cc047 --- /dev/null +++ b/src/graphql/move.graphql @@ -0,0 +1,5 @@ +mutation move($src: ID!, $dest: ID!) { + move(src: $src,dest: $dest){ + id + } +} \ No newline at end of file