refetch after change

This commit is contained in:
Niklas 2021-08-16 12:34:01 +02:00
parent 052363c539
commit 1f9757b8a7
2 changed files with 12 additions and 19 deletions

View File

@ -30,7 +30,7 @@ const FileBrowser: React.FC = () => {
id: CONTEXT_MENU_DIR,
})
const { data, loading } = useOpenDirQuery({
const { data, loading, refetch: refetchDir } = useOpenDirQuery({
variables:{
path
}
@ -44,6 +44,7 @@ const FileBrowser: React.FC = () => {
}
await Promise.all(wait)
refetchDir()
}
function openFileContextMenu(e: React.MouseEvent, id: string) {
@ -64,10 +65,11 @@ const FileBrowser: React.FC = () => {
})
}
function onContextSelect(action:Action, id: string) {
async function onContextSelect(action:Action, id: string) {
switch (action) {
case Action.FileDelete:
deleteMutation({variables:{id}})
await deleteMutation({variables:{id}})
refetchDir()
break
case Action.FileCopy:
case Action.FileMove:
@ -76,11 +78,13 @@ const FileBrowser: React.FC = () => {
break
case Action.FilePaste:
if (pasteAction === Action.FileCopy){
copyMutation({variables:{src:srcID,dest:path}})
await copyMutation({variables:{src:srcID,dest:path}})
refetchDir()
}
if (pasteAction === Action.FileMove){
moveMutation({variables:{src:srcID,dest:path}})
await moveMutation({variables:{src:srcID,dest:path}})
refetchDir()
}
break
default:

View File

@ -1,5 +1,5 @@
import React from "react"
import { Item, ItemParams, Menu, Separator, Submenu } from "react-contexify"
import { Item, ItemParams, Menu, Separator } from "react-contexify"
export const CONTEXT_MENU_FILE = "CONTEXT_MENU_FILE"
@ -31,25 +31,14 @@ const FileBrowserContextMenu: React.FC<Props> = (props) => {
<Item onClick={onClick} data={Action.FileDelete} >Delete</Item>
<Item onClick={onClick} data={Action.FileCopy} >Copy</Item>
<Item onClick={onClick} data={Action.FileMove} >Move</Item>
<Separator />
<Item onClick={onClick} data={Action.FilePaste} disabled={!props.pasteActive}>Paste</Item>
<Separator />
<Item disabled>Disabled</Item>
<Separator />
<Submenu label="Foobar">
<Item onClick={onClick} >Sub Item 1</Item>
<Item onClick={onClick} >Sub Item 2</Item>
</Submenu>
</Menu>
<Menu id={CONTEXT_MENU_DIR} animation={false}>
<Item onClick={onClick} >Item 1</Item>
<Item onClick={onClick} >Item 2</Item>
<Separator />
<Item disabled>Disabled</Item>
<Separator />
<Submenu label="Foobar">
<Item onClick={onClick} >Sub Item 1</Item>
<Item onClick={onClick} >Sub Item 2</Item>
</Submenu>
<Item onClick={onClick} data={Action.FilePaste} disabled={!props.pasteActive}>Paste</Item>
</Menu>
</>
)