summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorThomas F. K. Jorna <[email protected]>2021-10-04 15:34:56 +0200
committerThomas F. K. Jorna <[email protected]>2021-10-04 15:34:56 +0200
commitb0ddf286f087b31dc75626f709cfce3889de25dd (patch)
tree480c65853ef0a8e2de44f567ec95e367fc634a04
parent90820ca13a51b8a7e77d15896b0d34f9aba829fd (diff)
feat(preview): changed text-retrieval to http
-rw-r--r--components/Sidebar/index.tsx18
-rw-r--r--components/Tweaks/BehaviorPanel.tsx20
-rw-r--r--components/config.ts1
-rw-r--r--components/contextmenu.tsx20
-rw-r--r--org-roam-ui.el12
-rw-r--r--pages/index.tsx12
6 files changed, 61 insertions, 22 deletions
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<OrgRoamNode>()
+ 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' },
}}
>
- <UniOrg orgText={orgText} />
+ <UniOrg orgText={previewText} />
</Box>
</VStack>
</Scrollbars>
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
@@ -34,6 +34,26 @@ export const BehaviorPanel = (props: BehaviorPanelProps) => {
color="gray.800"
>
<Flex alignItems="center" justifyContent="space-between">
+ <Text>Preview node</Text>
+ <Menu isLazy placement="right">
+ <MenuButton as={Button} rightIcon={<ChevronDownIcon />} colorScheme="" color="black">
+ <Text>
+ {mouse.preview ? mouse.preview[0]!.toUpperCase() + mouse.preview!.slice(1) : 'Never'}
+ </Text>
+ </MenuButton>
+ <Portal>
+ {' '}
+ <MenuList bgColor="gray.200" zIndex="popover">
+ <MenuItem onClick={() => setMouse({ ...mouse, preview: '' })}>Never</MenuItem>
+ <MenuItem onClick={() => setMouse({ ...mouse, preview: 'click' })}>Click</MenuItem>
+ <MenuItem onClick={() => setMouse({ ...mouse, preview: 'double' })}>
+ Double Click
+ </MenuItem>
+ </MenuList>
+ </Portal>
+ </Menu>
+ </Flex>
+ <Flex alignItems="center" justifyContent="space-between">
<Flex>
<Text>Expand Node</Text>
<InfoTooltip infoText="View only the node and its direct neighbors" />
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<any>()
@@ -101,7 +101,10 @@ export const ContextMenu = (props: ContextMenuProps) => {
</>
)}
{!node?.properties.FILELESS ? (
- <MenuItem icon={<EditIcon />} onClick={() => openNodeInEmacs(node as OrgRoamNode, webSocket)}>
+ <MenuItem
+ icon={<EditIcon />}
+ onClick={() => openNodeInEmacs(node as OrgRoamNode, webSocket)}
+ >
Open in Emacs
</MenuItem>
) : (
@@ -156,8 +159,13 @@ export const ContextMenu = (props: ContextMenuProps) => {
Permenantly delete note
</MenuItem>
)}
- <MenuItem onClick={() => {getOrgText(node!, webSocket)
- setPreviewNode(node)}}>Preview</MenuItem>
+ <MenuItem
+ onClick={() => {
+ setPreviewNode(node)
+ }}
+ >
+ Preview
+ </MenuItem>
</MenuList>
</Menu>
</Box>
diff --git a/org-roam-ui.el b/org-roam-ui.el
index df21f7c..6fbb279 100644
--- a/org-roam-ui.el
+++ b/org-roam-ui.el
@@ -206,8 +206,8 @@ This serves the web-build and API over HTTP."
(org-roam-capture-
:node (org-roam-node-create :title (alist-get 'title data))
:props '(:finalize find-file))))
- ((string= command "getText")
- (org-roam-ui--send-text (alist-get 'id data) oru-ws))
+ ;((string= command "getText")
+ ; (org-roam-ui--send-text (alist-get 'id data) oru-ws))
(t (message "Something went wrong when receiving a message from Org-Roam-UI")))))
:on-close (lambda (_websocket)
(remove-hook 'after-save-hook #'org-roam-ui--on-save)
@@ -236,6 +236,14 @@ This serves the web-build and API over HTTP."
(websocket-send-text ws
(json-encode `((type . "orgText") (data . ,text))))))
+(defservlet* note/:id text/plain ()
+ (let* ((node (org-roam-populate (org-roam-node-create :id id)))
+ (file (org-roam-node-file node)))
+ (insert-file-contents-literally file)
+(httpd-send-header t "text/html" 200
+ :Access-Control-Allow-Origin "*")))
+
+
(defun org-roam-ui--on-save ()
"Send graphdata on saving an org-roam buffer."
(when (org-roam-buffer-p)
diff --git a/pages/index.tsx b/pages/index.tsx
index cc51920..6ebdc6c 100644
--- a/pages/index.tsx
+++ b/pages/index.tsx
@@ -42,12 +42,7 @@ import SpriteText from 'three-spritetext'
import wrap from 'word-wrap'
import ReconnectingWebSocket from 'reconnecting-websocket'
-import {
- getOrgText,
- deleteNodeInEmacs,
- openNodeInEmacs,
- createNodeInEmacs,
-} from '../util/webSocketFunctions'
+import { deleteNodeInEmacs, openNodeInEmacs, createNodeInEmacs } from '../util/webSocketFunctions'
import { ChevronLeftIcon } from '@chakra-ui/icons'
// react-force-graph fails on import when server-rendered
// https://github.com/vasturiano/react-force-graph/issues/155
@@ -92,7 +87,6 @@ export function GraphPage() {
const [emacsNodeId, setEmacsNodeId] = useState<string | null>(null)
const [behavior, setBehavior] = usePersistantState('behavior', initialBehavior)
const [mouse, setMouse] = usePersistantState('mouse', initialMouse)
- const [orgText, setOrgText] = useState('')
const [previewNode, setPreviewNode] = useState<NodeObject>({})
const { isOpen, onOpen, onClose } = useDisclosure()
@@ -369,8 +363,6 @@ export function GraphPage() {
switch (message.type) {
case 'graphdata':
return updateGraphData(message.data)
- case 'orgText':
- return setOrgText(message.data)
case 'theme':
return setEmacsTheme(message.data)
case 'command':
@@ -432,7 +424,6 @@ export function GraphPage() {
isOpen,
onClose,
previewNode,
- orgText,
}}
/>
<Tweaks
@@ -584,7 +575,6 @@ export const Graph = forwardRef(function (props: GraphProps, graphRef: any) {
openContextMenu(node, event)
}
case mouse.preview: {
- getOrgText(node, webSocket)
setPreviewNode(node)
}
default: