From 1d66292f8f16af75ac878a94a87abf9e56ee38ea Mon Sep 17 00:00:00 2001 From: "Thomas F. K. Jorna" Date: Thu, 22 Jul 2021 18:37:41 +0200 Subject: added eventsource node tracking --- org-roam-ui.el | 6 ++++-- pages/index.tsx | 8 ++++++++ 2 files changed, 12 insertions(+), 2 deletions(-) diff --git a/org-roam-ui.el b/org-roam-ui.el index 80991ad..fe012f6 100644 --- a/org-roam-ui.el +++ b/org-roam-ui.el @@ -115,9 +115,11 @@ ROWS is the sql result, while COLUMN-NAMES is the columns to use." (setq html-string (org-export-as 'html))) (insert html-string))) -(defservlet* current-node-data text/event-stream () +(defservlet* current-node-id text/event-stream () (insert (format "data: %s\n\n" - org-roam-ui-current-node-id))) + 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. diff --git a/pages/index.tsx b/pages/index.tsx index 356f5bb..31cc0ba 100644 --- a/pages/index.tsx +++ b/pages/index.tsx @@ -139,11 +139,19 @@ export function GraphPage() { const [physics, setPhysics] = usePersistantState('physics', initialPhysics) const [theme, setTheme] = useState(initialTheme) const [graphData, setGraphData] = useState(null) + const [emacsNode, setEmacsNode] = useState('') const nodeByIdRef = useRef({}) const linksByNodeIdRef = useRef({}) useEffect(() => { + const trackEmacs = new EventSource('http://127.0.0.1:35901/current-node-id') + + trackEmacs.addEventListener('message', (e) => { + setEmacsNode(e.data) + console.log(e.data) + console.log(emacsNode) + }) fetch('http://localhost:35901/theme') .then((res) => res.json()) .then((emacsTheme) => { -- cgit v1.2.3