implemented copy paste
This commit is contained in:
@@ -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 = () => {
|
||||
<div>
|
||||
<FileBrowserContextMenu
|
||||
onSelect={onContextSelect}
|
||||
pasteActive={!!srcID}
|
||||
/>
|
||||
<DragAndDrop
|
||||
handleDrop={async (files)=>{
|
||||
|
||||
@@ -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> = (props) => {
|
||||
@@ -25,7 +28,8 @@ 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="item2" >Item 2</Item>
|
||||
<Item onClick={onClick} data={Action.FileCopy} >Copy</Item>
|
||||
<Item onClick={onClick} data={Action.FilePaste} disabled={!props.pasteActive}>Paste</Item>
|
||||
<Separator />
|
||||
<Item disabled>Disabled</Item>
|
||||
<Separator />
|
||||
|
||||
Reference in New Issue
Block a user