From 56eeb1fc6b03c4e8ed9405e301c7edc7be5fd5d9 Mon Sep 17 00:00:00 2001 From: "Thomas F. K. Jorna" Date: Fri, 1 Oct 2021 19:11:08 +0200 Subject: feat: basic preview feature --- util/webSocketFunctions.ts | 25 +++++++++++++++++++++++++ 1 file changed, 25 insertions(+) create mode 100644 util/webSocketFunctions.ts (limited to 'util/webSocketFunctions.ts') diff --git a/util/webSocketFunctions.ts b/util/webSocketFunctions.ts new file mode 100644 index 0000000..8e2bd7e --- /dev/null +++ b/util/webSocketFunctions.ts @@ -0,0 +1,25 @@ +import { OrgRoamNode } from '../api' +import ReconnectingWebSocket from 'reconnecting-websocket' + +export function sendMessageToEmacs(command: string, data: {}, webSocket: ReconnectingWebSocket) { + webSocket.send(JSON.stringify({ command: command, data: data })) +} + +export function getOrgText(node: OrgRoamNode, webSocket: ReconnectingWebSocket) { + sendMessageToEmacs('getText', { id: node.id }, webSocket) +} + +export function openNodeInEmacs(node: OrgRoamNode, webSocket: ReconnectingWebSocket) { + sendMessageToEmacs('open', { id: node.id }, webSocket) +} + +export function deleteNodeInEmacs(node: OrgRoamNode, webSocket: ReconnectingWebSocket) { + if (node.level !== 0) { + return + } + sendMessageToEmacs('delete', { id: node.id, file: node.file }, webSocket) +} + +export function createNodeInEmacs(node: OrgRoamNode, webSocket: ReconnectingWebSocket) { + sendMessageToEmacs('create', { id: node.id, title: node.title, ref: node.properties.ROAM_REFS }, webSocket) +} -- cgit v1.2.3