From b0ddf286f087b31dc75626f709cfce3889de25dd Mon Sep 17 00:00:00 2001 From: "Thomas F. K. Jorna" Date: Mon, 4 Oct 2021 15:34:56 +0200 Subject: feat(preview): changed text-retrieval to http --- components/Sidebar/index.tsx | 18 +++++++++++++++--- components/Tweaks/BehaviorPanel.tsx | 20 ++++++++++++++++++++ components/config.ts | 1 + components/contextmenu.tsx | 20 ++++++++++++++------ 4 files changed, 50 insertions(+), 9 deletions(-) (limited to 'components') diff --git a/components/Sidebar/index.tsx b/components/Sidebar/index.tsx index e3845d9..05f5720 100644 --- a/components/Sidebar/index.tsx +++ b/components/Sidebar/index.tsx @@ -33,14 +33,25 @@ export interface SidebarProps { onClose: any //nodeById: any previewNode: NodeObject - orgText: string } const Sidebar = (props: SidebarProps) => { - const { isOpen, onClose, previewNode, orgText } = props + const { isOpen, onClose, previewNode } = props const { highlightColor } = useContext(ThemeContext) const [previewRoamNode, setPreviewRoamNode] = useState() + const [previewText, setPreviewText] = useState('') + + const getText = (id: string) => { + fetch(`http://localhost:35901/note/${id}`) + .then((res) => { + return res.text() + }) + .then((res) => { + console.log(res) + setPreviewText(res) + }) + } useEffect(() => { if (!previewNode) { @@ -48,6 +59,7 @@ const Sidebar = (props: SidebarProps) => { } setPreviewRoamNode(previewNode as OrgRoamNode) + previewNode?.id && getText(previewNode?.id as string) }, [previewNode]) //maybe want to close it when clicking outside, but not sure @@ -246,7 +258,7 @@ const Sidebar = (props: SidebarProps) => { '.figure p': { textAlign: 'center' }, }} > - + diff --git a/components/Tweaks/BehaviorPanel.tsx b/components/Tweaks/BehaviorPanel.tsx index 8edb986..0c22e1a 100644 --- a/components/Tweaks/BehaviorPanel.tsx +++ b/components/Tweaks/BehaviorPanel.tsx @@ -33,6 +33,26 @@ export const BehaviorPanel = (props: BehaviorPanelProps) => { paddingLeft={7} color="gray.800" > + + Preview node + + } colorScheme="" color="black"> + + {mouse.preview ? mouse.preview[0]!.toUpperCase() + mouse.preview!.slice(1) : 'Never'} + + + + {' '} + + setMouse({ ...mouse, preview: '' })}>Never + setMouse({ ...mouse, preview: 'click' })}>Click + setMouse({ ...mouse, preview: 'double' })}> + Double Click + + + + + Expand Node diff --git a/components/config.ts b/components/config.ts index 56664df..0fe4bc1 100644 --- a/components/config.ts +++ b/components/config.ts @@ -122,6 +122,7 @@ export const initialMouse = { local: 'click', follow: 'double', context: 'right', + preview: 'click', } export const colorList = [ diff --git a/components/contextmenu.tsx b/components/contextmenu.tsx index ff3dd81..09d9cff 100644 --- a/components/contextmenu.tsx +++ b/components/contextmenu.tsx @@ -43,7 +43,7 @@ import { } from '@chakra-ui/icons' import { OrgRoamGraphReponse, OrgRoamLink, OrgRoamNode } from '../api' -import { getOrgText, deleteNodeInEmacs, openNodeInEmacs, createNodeInEmacs } from "../util/webSocketFunctions" +import { deleteNodeInEmacs, openNodeInEmacs, createNodeInEmacs } from '../util/webSocketFunctions' export default interface ContextMenuProps { background: Boolean @@ -54,7 +54,7 @@ export default interface ContextMenuProps { menuClose: () => void scope: { nodeIds: string[] } webSocket: any - setPreviewNode: any, + setPreviewNode: any } export const ContextMenu = (props: ContextMenuProps) => { @@ -67,7 +67,7 @@ export const ContextMenu = (props: ContextMenuProps) => { menuClose, scope, webSocket, - setPreviewNode, + setPreviewNode, } = props const { isOpen, onOpen, onClose } = useDisclosure() const copyRef = useRef() @@ -101,7 +101,10 @@ export const ContextMenu = (props: ContextMenuProps) => { )} {!node?.properties.FILELESS ? ( - } onClick={() => openNodeInEmacs(node as OrgRoamNode, webSocket)}> + } + onClick={() => openNodeInEmacs(node as OrgRoamNode, webSocket)} + > Open in Emacs ) : ( @@ -156,8 +159,13 @@ export const ContextMenu = (props: ContextMenuProps) => { Permenantly delete note )} - {getOrgText(node!, webSocket) - setPreviewNode(node)}}>Preview + { + setPreviewNode(node) + }} + > + Preview + -- cgit v1.2.3