This commit is contained in:
Magnus Åhall 2024-12-02 15:26:35 +01:00
parent 1d6ba99a36
commit 42b66714aa
3 changed files with 62 additions and 52 deletions

View file

@ -16,7 +16,7 @@ export class NodeUI extends Component {
this.keys = signal([])
this.page = signal('node')
window.addEventListener('popstate', evt => {
if (evt.state && evt.state.hasOwnProperty('nodeID'))
if (evt.state?.hasOwnProperty('nodeID'))
this.goToNode(evt.state.nodeID, true)
else
this.goToNode(0, true)
@ -28,7 +28,7 @@ export class NodeUI extends Component {
if (this.node.value === null)
return
let node = this.node.value
const node = this.node.value
document.title = `N: ${node.Name}`
let crumbs = [
@ -39,7 +39,7 @@ export class NodeUI extends Component {
html`<div class="crumb" onclick=${() => this.goToNode(node.ID)}>${node.Name}</div>`
).reverse())
let children = node.Children.sort((a, b) => {
const children = node.Children.sort((a, b) => {
if (a.Name.toLowerCase() > b.Name.toLowerCase()) return 1
if (a.Name.toLowerCase() < b.Name.toLowerCase()) return -1
return 0
@ -56,9 +56,9 @@ export class NodeUI extends Component {
let page = ''
switch (this.page.value) {
case 'node':
if (node.ID == 0) {
if (node.ID === 0) {
page = html`
<div style="cursor: pointer; color: #000; text-align: center;" onclick=${() => this.page.value = 'schedule-events'}>Schedule events</div>
<div style="cursor: pointer; color: #000; text-align: center;" onclick=${() => { this.page.value = 'schedule-events' }}>Schedule events</div>
${children.length > 0 ? html`<div class="child-nodes">${children}</div><div id="notes-version">Notes version ${window._VERSION}</div>` : html``}
`
} else {
@ -104,8 +104,8 @@ export class NodeUI extends Component {
break
}
let menu = () => (this.menu.value ? html`<${Menu} nodeui=${this} />` : null)
let checklist = () =>
const menu = () => (this.menu.value ? html`<${Menu} nodeui=${this} />` : null)
const checklist = () =>
html`
<div class="checklist" onclick=${evt => { evt.stopPropagation(); this.toggleChecklist() }}>
<img src="/images/${window._VERSION}/${this.showChecklist() ? 'checklist-on.svg' : 'checklist-off.svg'}" />
@ -209,17 +209,19 @@ export class NodeUI extends Component {
}//}}}
goToNode(nodeID, dontPush) {//{{{
/* TODO - implement modified values
if (this.props.app.nodeModified.value) {
if (!confirm("Changes not saved. Do you want to discard changes?"))
return
}
*/
if (!dontPush)
history.pushState({ nodeID }, '', `/?node=${nodeID}`)
// New node is fetched in order to retrieve content and files.
// Such data is unnecessary to transfer for tree/navigational purposes.
let node = new Node(this.props.app, nodeID)
const node = new Node(this.props.app, nodeID)
node.retrieve(node => {
this.props.app.nodeModified.value = false
this.node.value = node
@ -278,12 +280,14 @@ export class NodeUI extends Component {
async retrieveKeys() {//{{{
return new Promise((resolve, reject) => {
/* TODO - implement keys in IndexedDB
this.props.app.request('/key/retrieve', {})
.then(res => {
this.keys.value = res.Keys.map(keyData => new Key(keyData, this.keyCounter))
resolve(this.keys.value)
})
.catch(reject)
*/
})
}//}}}
keyCounter() {//{{{