Compare commits

...

3 Commits

Author SHA1 Message Date
052363c539 implemented move 2021-08-16 02:05:12 +02:00
603cfec4af removed debug statement 2021-08-16 01:43:58 +02:00
8344766ae3 implemented copy paste 2021-08-16 01:42:29 +02:00
6 changed files with 136 additions and 10 deletions

View File

@@ -2,7 +2,7 @@ import React from "react"
import { useState } from "react" import { useState } from "react"
import { useContextMenu } from "react-contexify" import { useContextMenu } from "react-contexify"
import uploadFile from "../functions/uploadFile" import uploadFile from "../functions/uploadFile"
import { useDeleteFileMutation, useOpenDirQuery } from "../generated/graphql" import { useCopyMutation, useDeleteFileMutation, useMoveMutation, useOpenDirQuery } from "../generated/graphql"
import Breadcrum from "./Breadcrum" import Breadcrum from "./Breadcrum"
import DragAndDrop from "./DragAndDrop" import DragAndDrop from "./DragAndDrop"
import FileBrowserContextMenu, { Action, CONTEXT_MENU_DIR, CONTEXT_MENU_FILE } from "./FileBrowserContextMenu" import FileBrowserContextMenu, { Action, CONTEXT_MENU_DIR, CONTEXT_MENU_FILE } from "./FileBrowserContextMenu"
@@ -15,7 +15,12 @@ const FileBrowser: React.FC = () => {
const [openFileId, setOpenFileId] = useState("") const [openFileId, setOpenFileId] = useState("")
const [showFile, setShowFile] = useState(false) const [showFile, setShowFile] = useState(false)
const [srcID,setSrcID] = useState("")
const [pasteAction,setPasteAction] = useState<Action>()
const [deleteMutation] = useDeleteFileMutation() const [deleteMutation] = useDeleteFileMutation()
const [copyMutation] = useCopyMutation()
const [moveMutation] = useMoveMutation()
const { show: showFileContext } = useContextMenu({ const { show: showFileContext } = useContextMenu({
id: CONTEXT_MENU_FILE, id: CONTEXT_MENU_FILE,
@@ -60,12 +65,24 @@ const FileBrowser: React.FC = () => {
} }
function onContextSelect(action:Action, id: string) { function onContextSelect(action:Action, id: string) {
console.debug(action)
switch (action) { switch (action) {
case Action.FileDelete: case Action.FileDelete:
deleteMutation({variables:{id}}) deleteMutation({variables:{id}})
break 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: default:
break break
} }
@@ -75,6 +92,7 @@ const FileBrowser: React.FC = () => {
<div> <div>
<FileBrowserContextMenu <FileBrowserContextMenu
onSelect={onContextSelect} onSelect={onContextSelect}
pasteActive={!!srcID}
/> />
<DragAndDrop <DragAndDrop
handleDrop={async (files)=>{ handleDrop={async (files)=>{

View File

@@ -6,11 +6,15 @@ export const CONTEXT_MENU_FILE = "CONTEXT_MENU_FILE"
export const CONTEXT_MENU_DIR = "CONTEXT_MENU_DIR" export const CONTEXT_MENU_DIR = "CONTEXT_MENU_DIR"
export enum Action { export enum Action {
FileDelete FileDelete,
FileCopy,
FilePaste,
FileMove
} }
interface Props { interface Props {
onSelect?: (action: Action, id: string)=>void onSelect?: (action: Action, id: string)=>void
pasteActive?: boolean
} }
const FileBrowserContextMenu: React.FC<Props> = (props) => { const FileBrowserContextMenu: React.FC<Props> = (props) => {
@@ -25,7 +29,9 @@ const FileBrowserContextMenu: React.FC<Props> = (props) => {
<> <>
<Menu id={CONTEXT_MENU_FILE} animation={false}> <Menu id={CONTEXT_MENU_FILE} animation={false}>
<Item onClick={onClick} data={Action.FileDelete} >Delete</Item> <Item onClick={onClick} data={Action.FileDelete} >Delete</Item>
<Item onClick={onClick} data="item2" >Item 2</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 /> <Separator />
<Item disabled>Disabled</Item> <Item disabled>Disabled</Item>
<Separator /> <Separator />

View File

@@ -1,8 +1,4 @@
async function uploadFile(file:File,id: string): Promise<boolean> { async function uploadFile(file:File,id: string): Promise<boolean> {
console.debug(file)
const res = await fetch(`/api/file?${new URLSearchParams({id:id}).toString()}`,{ const res = await fetch(`/api/file?${new URLSearchParams({id:id}).toString()}`,{
method: "POST", method: "POST",
headers: { headers: {

View File

@@ -60,8 +60,8 @@ export type RootMutationDeleteArgs = {
export type RootMutationMoveArgs = { export type RootMutationMoveArgs = {
src: Scalars["ID"];
dest: Scalars["ID"]; dest: Scalars["ID"];
src: Scalars["ID"];
}; };
export type RootQuery = { export type RootQuery = {
@@ -86,6 +86,20 @@ export type RootQueryFilesArgs = {
path: Scalars["String"]; path: Scalars["String"];
}; };
export type CopyMutationVariables = Exact<{
src: Scalars["ID"];
dest: Scalars["ID"];
}>;
export type CopyMutation = (
{ __typename?: "RootMutation" }
& { copy?: Maybe<(
{ __typename?: "File" }
& Pick<File, "id">
)> }
);
export type DeleteFileMutationVariables = Exact<{ export type DeleteFileMutationVariables = Exact<{
id: Scalars["ID"]; id: Scalars["ID"];
}>; }>;
@@ -109,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<{ export type OpenDirQueryVariables = Exact<{
path: Scalars["String"]; path: Scalars["String"];
}>; }>;
@@ -126,6 +154,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<CopyMutation, CopyMutationVariables>;
/**
* __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<CopyMutation, CopyMutationVariables>) {
const options = {...defaultOptions, ...baseOptions}
return Apollo.useMutation<CopyMutation, CopyMutationVariables>(CopyDocument, options)
}
export type CopyMutationHookResult = ReturnType<typeof useCopyMutation>;
export type CopyMutationResult = Apollo.MutationResult<CopyMutation>;
export type CopyMutationOptions = Apollo.BaseMutationOptions<CopyMutation, CopyMutationVariables>;
export const DeleteFileDocument = gql` export const DeleteFileDocument = gql`
mutation deleteFile($id: ID!) { mutation deleteFile($id: ID!) {
delete(id: $id) delete(id: $id)
@@ -196,6 +258,40 @@ export function useGetFileLazyQuery(baseOptions?: Apollo.LazyQueryHookOptions<Ge
export type GetFileQueryHookResult = ReturnType<typeof useGetFileQuery>; export type GetFileQueryHookResult = ReturnType<typeof useGetFileQuery>;
export type GetFileLazyQueryHookResult = ReturnType<typeof useGetFileLazyQuery>; export type GetFileLazyQueryHookResult = ReturnType<typeof useGetFileLazyQuery>;
export type GetFileQueryResult = Apollo.QueryResult<GetFileQuery, GetFileQueryVariables>; 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` export const OpenDirDocument = gql`
query openDir($path: String!) { query openDir($path: String!) {
files(path: $path) { files(path: $path) {

5
src/graphql/copy.graphql Normal file
View File

@@ -0,0 +1,5 @@
mutation copy($src: ID!, $dest: ID!) {
copy(src: $src,dest: $dest){
id
}
}

5
src/graphql/move.graphql Normal file
View File

@@ -0,0 +1,5 @@
mutation move($src: ID!, $dest: ID!) {
move(src: $src,dest: $dest){
id
}
}