diff options
author | Thomas F. K. Jorna <[email protected]> | 2021-10-11 21:27:17 +0200 |
---|---|---|
committer | GitHub <[email protected]> | 2021-10-11 21:27:17 +0200 |
commit | 58b7030d45370072dee25214748670d6413343a9 (patch) | |
tree | 9632df7273415f4b197413c45ad11563af32d53a /util/webSocketFunctions.ts | |
parent | 89be3b67b2d10d35d72b5c54e1e166beeeef3095 (diff) | |
parent | 6e3dcf585c35620c6804f3c208e6882c29dfc17e (diff) |
Merge pull request #101 from org-roam/sidebar
feat: Add file preview functionality
Diffstat (limited to 'util/webSocketFunctions.ts')
-rw-r--r-- | util/webSocketFunctions.ts | 25 |
1 files changed, 25 insertions, 0 deletions
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) +} |