summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--org-roam-ui.el48
-rw-r--r--pages/index.tsx3
2 files changed, 19 insertions, 32 deletions
diff --git a/org-roam-ui.el b/org-roam-ui.el
index b2886d2..94d8e61 100644
--- a/org-roam-ui.el
+++ b/org-roam-ui.el
@@ -50,10 +50,6 @@
(defvar org-roam-ui/app-build-dir (expand-file-name "./out/")
"Directory containing org-roam-ui's web build.")
-;;; Dynamic variables
-(defvar org-roam-ui-current-node-id nil
- "The current node id Org-roam is tracking.")
-
;; TODO: make into defcustom
(defvar org-roam-ui-port
35901
@@ -107,21 +103,27 @@ This serves the web-build and API over HTTP."
(websocket-server
35903
:host 'local
- :on-open (lambda (ws) (progn (setq oru-ws
- ws) (org-roam-ui--send-graphdata) (message "Connection established with org-roam-ui")
- (add-hook 'post-command-hook #'org-roam-ui--update-current-node)))
- :on-close (lambda (_websocket) (setq oru-ws
- nil) (message "Connection with org-roam-ui closed succesfully."))))
- (if (boundp 'counsel-load-theme)
-(advice-add 'counsel-load-theme :after #'org-roam-ui-sync-theme--advice)
- (advice-add 'load-theme :around #'org-roam-ui-sync-theme--advice))
- (add-hook 'post-command-hook #'org-roam-ui--update-current-node))
- ;(add-hook 'post-command-hook #'org-roam-ui-update))
+ :on-open (lambda (ws) (progn
+ (setq oru-ws ws)
+ (org-roam-ui--send-graphdata)
+ (add-hook 'after-save-hook #'org-roam-ui--send-graphdata)
+
+ (message "Connection established with org-roam-ui")
+ (add-hook 'post-command-hook #'org-roam-ui--update-current-node)))
+ :on-close (lambda (_websocket)
+ (setq oru-ws nil)
+ (remove-hook 'post-command-hook #'org-roam-ui--update-current-node)
+ (add-hook 'after-save-hook #'org-roam-ui--send-graphdata)
+ (message "Connection with org-roam-ui closed succesfully."))))
+
+ (if
+ (boundp 'counsel-load-theme)
+ (advice-add 'counsel-load-theme :after #'org-roam-ui-sync-theme--advice)
+ (advice-add 'load-theme :around #'org-roam-ui-sync-theme--advice)))
+
(t
(progn
(websocket-server-close org-roam-ui-ws)
- (remove-hook 'post-command-hook #'org-roam-ui-update)
- (remove-hook 'post-command-hook #'org-roam-ui--update-current-node)
(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))
@@ -220,20 +222,6 @@ ROWS is the sql result, while COLUMN-NAMES is the columns to use."
(insert html-string)
(httpd-send-header t "text/html" 200 :Access-Control-Allow-Origin "*")))
-
-(defservlet* current-node-id text/event-stream ()
- (insert (format "data: %s\n\n"
- org-roam-ui-current-node-id))
- (httpd-send-header t "text/event-stream" 200 :Access-Control-Allow-Origin "*"))
-
-(defun org-roam-ui-update ()
- "Track changes within Emacs to update Org-roam UI.
-This function is added to `post-command-hook'."
- (setq org-roam-ui-current-node-id
- (or
- (condition-case nil (org-roam-id-at-point) (error nil))
- org-roam-ui-current-node-id)))
-
(defun org-roam-ui-get-theme ()
"Attempt to bring the current theme into a standardized format."
(list `(bg . ,(face-background hl-line-face))
diff --git a/pages/index.tsx b/pages/index.tsx
index 66dd30b..afd0ed3 100644
--- a/pages/index.tsx
+++ b/pages/index.tsx
@@ -342,7 +342,7 @@ export const Graph = forwardRef(function (props: GraphProps, graphRef: any) {
nodes: scopedNodes,
links: scopedLinks,
}
- }, [filter, scope, JSON.stringify(Object.keys(nodeById))])
+ }, [filter, scope, graphData])
useEffect(() => {
;(async () => {
@@ -631,7 +631,6 @@ export const Graph = forwardRef(function (props: GraphProps, graphRef: any) {
d3VelocityDecay: physics.velocityDecay,
onNodeClick: (node: NodeObject, event: any) => {
- event.preventDefault()
const isDoubleClick = event.timeStamp - lastNodeClickRef.current < 400
lastNodeClickRef.current = event.timeStamp