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
|
|
@ -107,11 +107,7 @@ export class App {
|
||||||
|
|
||||||
*/
|
*/
|
||||||
case 'S':
|
case 'S':
|
||||||
this.saveNode()
|
this.nodeUI.saveNode()
|
||||||
/*
|
|
||||||
else if (this.page.value === 'node-properties')
|
|
||||||
this.nodeProperties.current.save()
|
|
||||||
*/
|
|
||||||
break
|
break
|
||||||
/*
|
/*
|
||||||
|
|
||||||
|
|
@ -147,35 +143,7 @@ export class App {
|
||||||
return await nodeStore.get(nodeUUID)
|
return await nodeStore.get(nodeUUID)
|
||||||
}//}}}
|
}//}}}
|
||||||
async saveNode() {//{{{
|
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() {//{{{
|
async createNode() {//{{{
|
||||||
let name = prompt("Name")
|
let name = prompt("Name")
|
||||||
|
|
|
||||||
|
|
@ -93,6 +93,7 @@ export class N2PageNodeUI extends CustomHTMLElement {
|
||||||
this.node.setContent(this.elNodeContent.value)
|
this.node.setContent(this.elNodeContent.value)
|
||||||
})
|
})
|
||||||
this.elIconHistory.addEventListener('click', () => _mbus.dispatch('SHOW_PAGE', { page: 'history' }))
|
this.elIconHistory.addEventListener('click', () => _mbus.dispatch('SHOW_PAGE', { page: 'history' }))
|
||||||
|
this.elIconSave.addEventListener('click', ()=>this.saveNode())
|
||||||
|
|
||||||
this.showMarkdown(true)
|
this.showMarkdown(true)
|
||||||
}// }}}
|
}// }}}
|
||||||
|
|
@ -110,6 +111,36 @@ export class N2PageNodeUI extends CustomHTMLElement {
|
||||||
} else
|
} else
|
||||||
this.elNodeContent.focus({ preventScroll: true })
|
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) {//{{{
|
contentChanged(event) {//{{{
|
||||||
this.node.setContent(event.target.value)
|
this.node.setContent(event.target.value)
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue