From 56eeb1fc6b03c4e8ed9405e301c7edc7be5fd5d9 Mon Sep 17 00:00:00 2001 From: "Thomas F. K. Jorna" Date: Fri, 1 Oct 2021 19:11:08 +0200 Subject: feat: basic preview feature --- components/Sidebar/index.tsx | 273 +++++++++++++++++++++++++++++++++++++++++++ components/contextmenu.tsx | 22 ++-- 2 files changed, 283 insertions(+), 12 deletions(-) create mode 100644 components/Sidebar/index.tsx (limited to 'components') diff --git a/components/Sidebar/index.tsx b/components/Sidebar/index.tsx new file mode 100644 index 0000000..64436f2 --- /dev/null +++ b/components/Sidebar/index.tsx @@ -0,0 +1,273 @@ +import React, { useContext, useEffect, useState } from 'react' + +import { UniOrg } from "../../util/uniorg" +import { getOrgText } from "../../util/webSocketFunctions" + +import { + Button, + Slide, + VStack, + Flex, + Heading, + Box, + CloseButton, + Text, + Drawer, + DrawerOverlay, + DrawerHeader, + DrawerBody, + DrawerCloseButton, + DrawerContent, + DrawerFooter, + IconButton, +} from '@chakra-ui/react' +import { Scrollbars } from 'react-custom-scrollbars-2' +import { ChevronLeftIcon, ChevronRightIcon } from '@chakra-ui/icons' + +import { GraphData, NodeObject, LinkObject } from 'force-graph' +import { OrgRoamNode } from '../../api' +import {ThemeContext} from '../../util/themecontext' + +export interface SidebarProps { + isOpen: boolean + onClose: any + openNode: string + nodeById: any + previewNode: NodeObject, + orgText: string +} + +const Sidebar = (props: SidebarProps) => { + + const { isOpen, onClose, openNode, nodeById, previewNode, orgText } = props + + const {highlightColor}= useContext(ThemeContext) + + useEffect(() => { + (async () => { + if (!openNode) { + return + } + if (openNode === 'nil') { + return + } + })() + + const previewRoamNode = previewNode as OrgRoamNode + }, [previewNode]) + + //maybe want to close it when clicking outside, but not sure + //const outsideClickRef = useRef(); + return ( + + + } + colorScheme="white" + aria-label="Close file-viewer" + height={100} + variant="ghost" + marginRight={-2} + bg="alt.100" + onClick={onClose} + marginTop={20} + /> + + + {previewNode.title} + + ( + + )} + > + + + + + + + + + + ) +} + +export default Sidebar + + + + +/* + {previewNode.title} + */ diff --git a/components/contextmenu.tsx b/components/contextmenu.tsx index 39b1895..ff3dd81 100644 --- a/components/contextmenu.tsx +++ b/components/contextmenu.tsx @@ -43,6 +43,7 @@ import { } from '@chakra-ui/icons' import { OrgRoamGraphReponse, OrgRoamLink, OrgRoamNode } from '../api' +import { getOrgText, deleteNodeInEmacs, openNodeInEmacs, createNodeInEmacs } from "../util/webSocketFunctions" export default interface ContextMenuProps { background: Boolean @@ -50,12 +51,10 @@ export default interface ContextMenuProps { nodeType?: string coordinates: number[] handleLocal: (node: OrgRoamNode, add: string) => void - openNodeInEmacs: (node: OrgRoamNode) => void menuClose: () => void scope: { nodeIds: string[] } - deleteNodeInEmacs: (node: OrgRoamNode) => void - createNodeInEmacs: (node: OrgRoamNode) => void - getOrgText: any + webSocket: any + setPreviewNode: any, } export const ContextMenu = (props: ContextMenuProps) => { @@ -67,10 +66,8 @@ export const ContextMenu = (props: ContextMenuProps) => { handleLocal, menuClose, scope, - openNodeInEmacs, - deleteNodeInEmacs, - createNodeInEmacs, - getOrgText, + webSocket, + setPreviewNode, } = props const { isOpen, onOpen, onClose } = useDisclosure() const copyRef = useRef() @@ -104,11 +101,11 @@ export const ContextMenu = (props: ContextMenuProps) => { )} {!node?.properties.FILELESS ? ( - } onClick={() => openNodeInEmacs(node as OrgRoamNode)}> + } onClick={() => openNodeInEmacs(node as OrgRoamNode, webSocket)}> Open in Emacs ) : ( - } onClick={() => createNodeInEmacs(node)}> + } onClick={() => createNodeInEmacs(node, webSocket)}> Create node )} @@ -159,7 +156,8 @@ export const ContextMenu = (props: ContextMenuProps) => { Permenantly delete note )} - getOrgText(node)}>Preview + {getOrgText(node!, webSocket) + setPreviewNode(node)}}>Preview @@ -198,7 +196,7 @@ export const ContextMenu = (props: ContextMenuProps) => { ml={3} onClick={() => { console.log('aaaaa') - deleteNodeInEmacs(node!) + deleteNodeInEmacs(node!, webSocket) onClose() menuClose() }} -- cgit v1.2.3