Refactored node saving and fixed click on save icon
This commit is contained in:
parent
98270b677b
commit
f647d87e63
2 changed files with 32 additions and 33 deletions
|
|
@ -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)
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue