From 54b7210b9160c4aa3fffa9e29737111593af6512 Mon Sep 17 00:00:00 2001 From: "Thomas F. K. Jorna" Date: Thu, 5 Aug 2021 18:58:49 +0200 Subject: feature: context menu and slightly less jumpy graph --- components/contextmenu.tsx | 216 +++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 216 insertions(+) create mode 100644 components/contextmenu.tsx (limited to 'components') diff --git a/components/contextmenu.tsx b/components/contextmenu.tsx new file mode 100644 index 0000000..c20b3e9 --- /dev/null +++ b/components/contextmenu.tsx @@ -0,0 +1,216 @@ +import React, { useRef } from 'react' +import { + Box, + Menu, + MenuItem, + MenuList, + MenuGroup, + MenuItemOption, + MenuOptionGroup, + Heading, + MenuDivider, + Modal, + ModalOverlay, + ModalContent, + ModalHeader, + ModalFooter, + ModalBody, + ModalCloseButton, + useDisclosure, + Button, + PopoverTrigger, + PopoverContent, + Popover, + Flex, + PopoverBody, + PopoverCloseButton, + PopoverArrow, + PopoverHeader, + PopoverFooter, + Portal, + Text, + VStack, +} from '@chakra-ui/react' +import { + DeleteIcon, + EditIcon, + CopyIcon, + AddIcon, + ViewIcon, + ExternalLinkIcon, + ChevronRightIcon, + PlusSquareIcon, +} from '@chakra-ui/icons' + +import { OrgRoamGraphReponse, OrgRoamLink, OrgRoamNode } from '../api' + +export default interface ContextMenuProps { + background: Boolean + node?: OrgRoamNode + nodeType?: string + coordinates: number[] + handleLocal: (node: OrgRoamNode, add: string) => void + openNodeInEmacs: (node: OrgRoamNode) => void + menuClose: () => void + scope: { nodeIds: string[] } + deleteNodeInEmacs: (node: OrgRoamNode) => void +} + +export const ContextMenu = (props: ContextMenuProps) => { + const { background, node, nodeType, coordinates, handleLocal, menuClose, scope, openNodeInEmacs, deleteNodeInEmacs } = props + const { isOpen, onOpen, onClose } = useDisclosure() + const copyRef = useRef() + return ( + <> + + menuClose()}> + + {node && ( + <> + + {node.title} + + + + )} + {scope.nodeIds.length !== 0 && + <> + handleLocal(node!, "add")} icon={}> + Expand local graph at node + + handleLocal(node!, "replace")} icon={}> + Open local graph for this node + + + } + {!node?.properties.FILELESS ? ( + } onClick={() => openNodeInEmacs(node)}>Open in Emacs + ) : ( + }>Create node + )} + {node?.properties.ROAM_REFS && ( + }>Open in Zotero + )} + {scope.nodeIds.length === 0 && + } onClick={() => handleLocal(node!, "replace")}>Open local graph + } + {/* Doesn't work at the moment + + + + + }> + + Copy... + + + + + + + + ID + Title + File path + + + + + + */} + {node?.level === 0 && + } + color="red.500" + onClick={onOpen} + > + Permenantly delete note + + } + + + + + + + Delete node? + + + + + This will permanently delete your note: + + {node?.title} + + {node?.level !== 0 && + This will only delete the from this heading until but not including the next node. + Your parent file and all other nodes will not be deleted.} + + Are you sure you want to do continue? + + + + + + + + + + + ) +} + +/* + * + * + * Permenantly delete node + * + * + * + * Delete Node? + * + * + * + * This will permanently delete your node! Are you sure you want to do this? + * + * + * + * + * + * + * + * + * + * */ -- cgit v1.2.3