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

View File

@ -1,5 +1,5 @@
import React from "react" 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" 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.FileDelete} >Delete</Item>
<Item onClick={onClick} data={Action.FileCopy} >Copy</Item> <Item onClick={onClick} data={Action.FileCopy} >Copy</Item>
<Item onClick={onClick} data={Action.FileMove} >Move</Item> <Item onClick={onClick} data={Action.FileMove} >Move</Item>
<Separator />
<Item onClick={onClick} data={Action.FilePaste} disabled={!props.pasteActive}>Paste</Item> <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>
<Menu id={CONTEXT_MENU_DIR} animation={false}> <Menu id={CONTEXT_MENU_DIR} animation={false}>
<Item onClick={onClick} >Item 1</Item> <Item onClick={onClick} >Item 1</Item>
<Item onClick={onClick} >Item 2</Item> <Item onClick={onClick} >Item 2</Item>
<Separator /> <Separator />
<Item disabled>Disabled</Item> <Item onClick={onClick} data={Action.FilePaste} disabled={!props.pasteActive}>Paste</Item>
<Separator />
<Submenu label="Foobar">
<Item onClick={onClick} >Sub Item 1</Item>
<Item onClick={onClick} >Sub Item 2</Item>
</Submenu>
</Menu> </Menu>
</> </>
) )