From 90820ca13a51b8a7e77d15896b0d34f9aba829fd Mon Sep 17 00:00:00 2001 From: "Thomas F. K. Jorna" Date: Mon, 4 Oct 2021 14:17:34 +0200 Subject: fix: made viewer work --- components/Sidebar/index.tsx | 2 +- pages/index.tsx | 100 ++++++++++++++++++++++++------------------- 2 files changed, 58 insertions(+), 44 deletions(-) diff --git a/components/Sidebar/index.tsx b/components/Sidebar/index.tsx index 3332d39..e3845d9 100644 --- a/components/Sidebar/index.tsx +++ b/components/Sidebar/index.tsx @@ -88,7 +88,7 @@ const Sidebar = (props: SidebarProps) => { alignItems="center" color="black" > - {previewRoamNode} + {previewRoamNode?.title} (null) const [behavior, setBehavior] = usePersistantState('behavior', initialBehavior) const [mouse, setMouse] = usePersistantState('mouse', initialMouse) - const [orgText, setOrgText] = useState("") + const [orgText, setOrgText] = useState('') const [previewNode, setPreviewNode] = useState({}) const { isOpen, onOpen, onClose } = useDisclosure() @@ -365,7 +370,7 @@ export function GraphPage() { case 'graphdata': return updateGraphData(message.data) case 'orgText': - return setOrgText(message.data) + return setOrgText(message.data) case 'theme': return setEmacsTheme(message.data) case 'command': @@ -415,14 +420,20 @@ export function GraphPage() { return ( - + - - {!isOpen && ( - } - height={100} - aria-label="Open org-viewer" - position="relative" - zIndex="overlay" - colorScheme="purple" - onClick={onOpen} - variant="ghost" - marginTop={10} - /> - )} - + + {!isOpen && ( + } + height={100} + aria-label="Open org-viewer" + position="relative" + zIndex="overlay" + colorScheme="purple" + onClick={onOpen} + variant="ghost" + marginTop={10} + /> + )} + { @@ -573,6 +583,10 @@ export const Graph = forwardRef(function(props: GraphProps, graphRef: any) { case mouse.context: { openContextMenu(node, event) } + case mouse.preview: { + getOrgText(node, webSocket) + setPreviewNode(node) + } default: break } @@ -779,7 +793,7 @@ export const Graph = forwardRef(function(props: GraphProps, graphRef: any) { ]) useEffect(() => { - ; (async () => { + ;(async () => { const fg = graphRef.current const d3 = await d3promise if (physics.gravityOn && !(scope.nodeIds.length && !physics.gravityLocal)) { @@ -941,15 +955,15 @@ export const Graph = forwardRef(function(props: GraphProps, graphRef: any) { return needsHighlighting ? getThemeColor(visuals.citeNodeColor) : highlightColors[visuals.citeNodeColor][visuals.backgroundColor]( - visuals.highlightFade * opacity, - ) + visuals.highlightFade * opacity, + ) } if (visuals.refNodeColor && node.properties.ROAM_REFS) { return needsHighlighting ? getThemeColor(visuals.refNodeColor) : highlightColors[visuals.refNodeColor][visuals.backgroundColor]( - visuals.highlightFade * opacity, - ) + visuals.highlightFade * opacity, + ) } if (!needsHighlighting) { return highlightColors[getNodeColorById(node.id as string)][visuals.backgroundColor]( @@ -1097,20 +1111,20 @@ export const Graph = forwardRef(function(props: GraphProps, graphRef: any) { if (visuals.refLinkColor && roamLink.type === 'ref') { return needsHighlighting && (visuals.refLinkHighlightColor || visuals.linkHighlight) ? highlightColors[visuals.refLinkColor][ - visuals.refLinkHighlightColor || visuals.linkHighlight - ](opacity) + visuals.refLinkHighlightColor || visuals.linkHighlight + ](opacity) : highlightColors[visuals.refLinkColor][visuals.backgroundColor]( - visuals.highlightFade * opacity, - ) + visuals.highlightFade * opacity, + ) } if (visuals.citeLinkColor && roamLink.type?.includes('cite')) { return needsHighlighting && (visuals.citeLinkHighlightColor || visuals.linkHighlight) ? highlightColors[visuals.citeLinkColor][ - visuals.citeLinkHighlightColor || visuals.linkHighlight - ](opacity) + visuals.citeLinkHighlightColor || visuals.linkHighlight + ](opacity) : highlightColors[visuals.citeLinkColor][visuals.backgroundColor]( - visuals.highlightFade * opacity, - ) + visuals.highlightFade * opacity, + ) } return getLinkColor(sourceId as string, targetId as string, needsHighlighting) @@ -1200,7 +1214,7 @@ export const Graph = forwardRef(function(props: GraphProps, graphRef: any) { handleLocal={handleLocal} menuClose={contextMenu.onClose.bind(contextMenu)} webSocket={webSocket} - setPreviewNode={setPreviewNode} + setPreviewNode={setPreviewNode} /> )} {threeDim ? ( -- cgit v1.2.3