From f647d87e636f175844fabc0ec5a2e8f975017347 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Magnus=20=C3=85hall?= Date: Sun, 7 Jun 2026 12:33:08 +0200 Subject: [PATCH] Refactored node saving and fixed click on save icon --- static/js/app.mjs | 34 +--------------------------------- static/js/page_node.mjs | 31 +++++++++++++++++++++++++++++++ 2 files changed, 32 insertions(+), 33 deletions(-) diff --git a/static/js/app.mjs b/static/js/app.mjs index be3ddeb..fdb3db4 100644 --- a/static/js/app.mjs +++ b/static/js/app.mjs @@ -107,11 +107,7 @@ export class App { */ case 'S': - this.saveNode() - /* - else if (this.page.value === 'node-properties') - this.nodeProperties.current.save() - */ + this.nodeUI.saveNode() break /* @@ -147,35 +143,7 @@ export class App { return await nodeStore.get(nodeUUID) }//}}} async saveNode() {//{{{ - if (!this.currentNode.isModified()) - return - /* The node history is a local store for node history. - * This could be provisioned from the server or cleared if - * deemed unnecessary. - * - * The send queue is what will be sent back to the server - * to have a recorded history of the notes. - * - * A setting to be implemented in the future could be to - * not save the history locally at all. */ - const node = this.currentNode - - // The node is still in its old state and will present - // the unmodified content to the node store. - const history = nodeStore.nodesHistory.add(node) - - // Prepares the node object for saving. - // Sets Updated value to current date and time. - await node.save() - - // Updated node is added to the send queue to be stored on server. - const sendQueue = nodeStore.sendQueue.add(node) - - // Updated node is saved to the primary node store. - const nodeStoreAdding = nodeStore.add([node]) - - await Promise.all([history, sendQueue, nodeStoreAdding]) }//}}} async createNode() {//{{{ let name = prompt("Name") diff --git a/static/js/page_node.mjs b/static/js/page_node.mjs index e26cb86..9a82b90 100644 --- a/static/js/page_node.mjs +++ b/static/js/page_node.mjs @@ -93,6 +93,7 @@ export class N2PageNodeUI extends CustomHTMLElement { this.node.setContent(this.elNodeContent.value) }) this.elIconHistory.addEventListener('click', () => _mbus.dispatch('SHOW_PAGE', { page: 'history' })) + this.elIconSave.addEventListener('click', ()=>this.saveNode()) this.showMarkdown(true) }// }}} @@ -110,6 +111,36 @@ export class N2PageNodeUI extends CustomHTMLElement { } else this.elNodeContent.focus({ preventScroll: true }) }// }}} + async saveNode() {// {{{ + if (!this.node.isModified()) + return + + /* The node history is a local store for node history. + * This could be provisioned from the server or cleared if + * deemed unnecessary. + * + * The send queue is what will be sent back to the server + * to have a recorded history of the notes. + * + * A setting to be implemented in the future could be to + * not save the history locally at all. */ + + // The node is still in its old state and will present + // the unmodified content to the node store. + const history = nodeStore.nodesHistory.add(this.node) + + // Prepares the node object for saving. + // Sets Updated value to current date and time. + await this.node.save() + + // Updated node is added to the send queue to be stored on server. + const sendQueue = nodeStore.sendQueue.add(this.node) + + // Updated node is saved to the primary node store. + const nodeStoreAdding = nodeStore.add([this.node]) + + await Promise.all([history, sendQueue, nodeStoreAdding]) + }// }}} contentChanged(event) {//{{{ this.node.setContent(event.target.value)