implemented move
This commit is contained in:
parent
603cfec4af
commit
052363c539
@ -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<Action>()
|
||||
|
||||
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:
|
||||
if (pasteAction === Action.FileCopy){
|
||||
copyMutation({variables:{src:srcID,dest:path}})
|
||||
}
|
||||
|
||||
if (pasteAction === Action.FileMove){
|
||||
moveMutation({variables:{src:srcID,dest:path}})
|
||||
}
|
||||
break
|
||||
default:
|
||||
break
|
||||
|
@ -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> = (props) => {
|
||||
<Menu id={CONTEXT_MENU_FILE} animation={false}>
|
||||
<Item onClick={onClick} data={Action.FileDelete} >Delete</Item>
|
||||
<Item onClick={onClick} data={Action.FileCopy} >Copy</Item>
|
||||
<Item onClick={onClick} data={Action.FileMove} >Move</Item>
|
||||
<Item onClick={onClick} data={Action.FilePaste} disabled={!props.pasteActive}>Paste</Item>
|
||||
<Separator />
|
||||
<Item disabled>Disabled</Item>
|
||||
|
@ -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<File, "id">
|
||||
)> }
|
||||
);
|
||||
|
||||
export type OpenDirQueryVariables = Exact<{
|
||||
path: Scalars["String"];
|
||||
}>;
|
||||
@ -244,6 +258,40 @@ export function useGetFileLazyQuery(baseOptions?: Apollo.LazyQueryHookOptions<Ge
|
||||
export type GetFileQueryHookResult = ReturnType<typeof useGetFileQuery>;
|
||||
export type GetFileLazyQueryHookResult = ReturnType<typeof useGetFileLazyQuery>;
|
||||
export type GetFileQueryResult = Apollo.QueryResult<GetFileQuery, GetFileQueryVariables>;
|
||||
export const MoveDocument = gql`
|
||||
mutation move($src: ID!, $dest: ID!) {
|
||||
move(src: $src, dest: $dest) {
|
||||
id
|
||||
}
|
||||
}
|
||||
`
|
||||
export type MoveMutationFn = Apollo.MutationFunction<MoveMutation, MoveMutationVariables>;
|
||||
|
||||
/**
|
||||
* __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<MoveMutation, MoveMutationVariables>) {
|
||||
const options = {...defaultOptions, ...baseOptions}
|
||||
return Apollo.useMutation<MoveMutation, MoveMutationVariables>(MoveDocument, options)
|
||||
}
|
||||
export type MoveMutationHookResult = ReturnType<typeof useMoveMutation>;
|
||||
export type MoveMutationResult = Apollo.MutationResult<MoveMutation>;
|
||||
export type MoveMutationOptions = Apollo.BaseMutationOptions<MoveMutation, MoveMutationVariables>;
|
||||
export const OpenDirDocument = gql`
|
||||
query openDir($path: String!) {
|
||||
files(path: $path) {
|
||||
|
5
src/graphql/move.graphql
Normal file
5
src/graphql/move.graphql
Normal file
@ -0,0 +1,5 @@
|
||||
mutation move($src: ID!, $dest: ID!) {
|
||||
move(src: $src,dest: $dest){
|
||||
id
|
||||
}
|
||||
}
|
Loading…
Reference in New Issue
Block a user