summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorThomas F. K. Jorna <[email protected]>2021-07-31 16:18:12 +0200
committerThomas F. K. Jorna <[email protected]>2021-07-31 16:18:12 +0200
commit9f04ec867ba90a9813a192834f7a104b6a2cf945 (patch)
treed06708039cd207a8b91775a846d7d8a940231264
parent144c2f66c54196bcc06e9096818317fc222ea009 (diff)
dotted all the ts and crossed the is
-rw-r--r--components/tweaks.tsx5
-rw-r--r--org-roam-ui.el47
-rw-r--r--pages/index.tsx43
3 files changed, 46 insertions, 49 deletions
diff --git a/components/tweaks.tsx b/components/tweaks.tsx
index 3da32cc..bc1a0d3 100644
--- a/components/tweaks.tsx
+++ b/components/tweaks.tsx
@@ -163,6 +163,7 @@ export const Tweaks = (props: TweakProps) => {
setFilter(initialFilter)
setMouse(initialMouse)
setPhysics(initialPhysics)
+ setBehavior(initialBehavior)
}}
variant="none"
size="sm"
@@ -1222,7 +1223,7 @@ export const Tweaks = (props: TweakProps) => {
</Portal>
</Menu>
</Flex>
- <Flex alignItems="center" justifyContent="space-between">
+ {/* <Flex alignItems="center" justifyContent="space-between">
<Flex>
<Text>Follow local graph</Text>
<InfoTooltip infoText="When in local mode and opening a node that already exists in Emacs, should I add that local graph or open the new one?" />
@@ -1252,7 +1253,7 @@ export const Tweaks = (props: TweakProps) => {
</MenuList>
</Portal>
</Menu>
- </Flex>
+ </Flex> */}
<SliderWithInfo
label="Zoom speed"
value={behavior.zoomSpeed}
diff --git a/org-roam-ui.el b/org-roam-ui.el
index 2b86914..b606e99 100644
--- a/org-roam-ui.el
+++ b/org-roam-ui.el
@@ -1,11 +1,11 @@
;;; org-roam-ui.el --- User Interface for Org-roam -*- coding: utf-8; lexical-binding: t; -*-
-;; Copyright © 2021 ...
+;; Copyright © 2021 Kirill Rogovoy, Thomas F. K. Jorna
-;; Author: ...
+;; author: Kirill Rogovoy, Thomas Jorna
;; URL: https://github.com/org-roam/org-roam-ui
;; Keywords: org-mode, roam
-;; Version: ...
+;; Version: 0
;; Package-Requires: ((emacs "26.1") (f "0.17.2") (org-roam "2.0.0"))
;; This file is NOT part of GNU Emacs.
@@ -115,21 +115,15 @@ This serves the web-build and API over HTTP."
(add-hook 'after-save-hook #'org-roam-ui--on-save)
(message "Connection established with org-roam-ui")
(when org-roam-ui-follow
- (add-hook 'post-command-hook #'org-roam-ui--update-current-node))))
+ (org-roam-ui-follow-mode 1))))
:on-close (lambda (_websocket)
- (remove-hook 'post-command-hook #'org-roam-ui--update-current-node)
(remove-hook 'after-save-hook #'org-roam-ui--on-save)
- (message "Connection with org-roam-ui closed."))))
- (if
- (boundp 'counsel-load-theme)
- (advice-add 'counsel-load-theme :after #'org-roam-ui-sync-theme--advice)
- (advice-add 'load-theme :after #'org-roam-ui-sync-theme--advice)))
+ (org-roam-ui-follow-mode -1)
+ (message "Connection with org-roam-ui closed.")))))
(t
(progn
(websocket-server-close org-roam-ui-ws)
- (if (boundp 'counsel-load-theme)
-(advice-remove 'counsel-load-theme #'org-roam-ui-sync-theme--advice)
- (advice-remove 'load-theme #'org-roam-ui-sync-theme--advice))
+ (org-roam-ui-follow-mode -1)
(httpd-stop)))))
(defun org-roam-ui--on-save ()
@@ -255,7 +249,8 @@ The padding around the nodes in the viewport."
(defun orui-node-local (&optional id speed padding)
- "Open the local graph view of the current node, or optionally of a node of your choosing."
+ "Open the local graph view of the current node, or optionally of a node of your choosing.
+Optionally with id (string), speed (number, ms) and padding (number, px)."
(interactive)
(if-let ((node (or id (org-roam-id-at-point))))
(websocket-send-text oru-ws (json-encode `((type . "command") (data .
@@ -263,25 +258,21 @@ The padding around the nodes in the viewport."
(message "No node found."))
(defvar org-roam-ui--following nil)
-(defun orui-toggle-follow ()
+
+(define-minor-mode org-roam-ui-follow-mode
"Set whether ORUI should follow your every move in emacs. Default yes."
- (interactive)
- (if (member 'org-roam-ui--update-current-node (default-value 'post-command-hook))
+ :lighter "org-roam-ui "
+ :global t
+ :group 'org-roam-ui
+ :init-value nil
+ (if org-roam-ui-follow-mode
(progn
- (remove-hook 'post-command-hook #'org-roam-ui--update-current-node)
- (message "Org-Roam-UI will now leave you alone.")
- (setq org-roam-ui--following nil))
(add-hook 'post-command-hook #'org-roam-ui--update-current-node)
- (setq org-roam-ui--following nil)
(message "Org-Roam-UI will now follow you around."))
- )
-
+ (remove-hook 'post-command-hook #'org-roam-ui--update-current-node)
+ (message "Org-Roam-UI will now leave you alone.")
+ ))
-(defun orui-toggle-local-zoom ()
- "Toggles whether org-roam-ui should go to the local view of a given node or zoom to it.
-Defaults to local."
- (interactive)
- (org-roam-ui--send-command "toggle" `(id . yes)))
(defun orui-sync-theme ()
"Sync your current Emacs theme with org-roam-ui."
diff --git a/pages/index.tsx b/pages/index.tsx
index 6eb86b1..da308c7 100644
--- a/pages/index.tsx
+++ b/pages/index.tsx
@@ -132,9 +132,13 @@ export function GraphPage() {
const [threeDim, setThreeDim] = useState(false)
const [scope, setScope] = useState<Scope>({ nodeIds: [] })
-
+ const scopeRef = useRef<Scope>({ nodeIds: [] })
+ const behaviorRef = useRef(initialBehavior)
+ behaviorRef.current = behavior
const graphRef = useRef<any>(null)
+ const WebSocketRef = useRef<any>(null)
+ scopeRef.current = scope
const followBehavior = (
command: string,
emacsNode: string,
@@ -142,6 +146,8 @@ export function GraphPage() {
padding: number = 200,
) => {
const fg = graphRef.current
+ const sr = scopeRef.current
+ const bh = behaviorRef.current
const links = linksByNodeIdRef.current[emacsNode] ?? []
const nodes = Object.fromEntries(
[emacsNode as string, ...links.flatMap((link) => [link.source, link.target])].map(
@@ -149,20 +155,23 @@ export function GraphPage() {
),
)
if (command === 'zoom') {
- if (scope.nodeIds.length) {
+ console.log(sr)
+ if (sr.nodeIds.length) {
+ console.log('emptying')
+ console.log('scope ' + sr.nodeIds)
setScope({ nodeIds: [] })
}
setTimeout(() => fg.zoomToFit(speed, padding, (node: OrgRoamNode) => nodes[node.id!]), 50)
return
}
- if (!scope.nodeIds.length) {
+ if (!sr.nodeIds.length) {
setScope({ nodeIds: [emacsNode] })
setTimeout(() => {
fg.zoomToFit(speed, padding, (node: OrgRoamNode) => nodes[node.id!])
}, 50)
return
}
- if (behavior.localSame !== 'add') {
+ if (bh.localSame !== 'add') {
setScope({ nodeIds: [emacsNode] })
setTimeout(() => {
fg.zoomToFit(speed, padding, (node: OrgRoamNode) => nodes[node.id!])
@@ -172,8 +181,8 @@ export function GraphPage() {
// if the node is in the scopednodes, add it to scope instead of replacing it
if (
- !scope.nodeIds.includes(emacsNode) ||
- !scope.nodeIds.some((scopeId: string) => {
+ !sr.nodeIds.includes(emacsNode) ||
+ !sr.nodeIds.some((scopeId: string) => {
return nodes[scopeId]
})
) {
@@ -191,12 +200,13 @@ export function GraphPage() {
}
useEffect(() => {
- const socket = new ReconnectingWebSocket('ws://localhost:35903')
- socket.addEventListener('open', (event) => {
+ WebSocketRef.current = new ReconnectingWebSocket('ws://localhost:35903')
+ WebSocketRef.current.addEventListener('open', (event: any) => {
console.log('Connection with Emacs established')
})
- socket.addEventListener('message', (event) => {
+ WebSocketRef.current.addEventListener('message', (event: any) => {
const fg = graphRef.current
+ const bh = behaviorRef.current
const message = JSON.parse(event.data)
switch (message.type) {
case 'graphdata':
@@ -212,19 +222,14 @@ export function GraphPage() {
setEmacsNodeId(message.data.id)
break
case 'zoom': {
- const speed = message?.data?.speed || behavior.zoomSpeed
- const padding = message?.data?.padding || behavior.zoomPadding
+ const speed = message?.data?.speed || bh.zoomSpeed
+ const padding = message?.data?.padding || bh.zoomPadding
followBehavior('zoom', message.data.id, speed, padding)
setEmacsNodeId(message.data.id)
break
}
case 'follow': {
- followBehavior(
- behavior.follow,
- message.data.id,
- behavior.zoomSpeed,
- behavior.zoomPadding,
- )
+ followBehavior(bh.follow, message.data.id, bh.zoomSpeed, bh.zoomPadding)
setEmacsNodeId(message.data.id)
break
}
@@ -355,7 +360,7 @@ export const Graph = forwardRef(function (props: GraphProps, graphRef: any) {
if (!emacsNodeId) {
return
}
- centralHighlightedNode.current = nodeById[emacsNodeId] as NodeObject
+ setHoverNode(nodeById[emacsNodeId] as NodeObject)
}, [emacsNodeId])
centralHighlightedNode.current = hoverNode
@@ -751,7 +756,7 @@ export const Graph = forwardRef(function (props: GraphProps, graphRef: any) {
if (scope.nodeIds.length === 0) {
return
}
- setScope((currentScope) => ({
+ setScope((currentScope: Scope) => ({
...currentScope,
nodeIds: [],
}))