diff --git a/main.go b/main.go index 7c2decc..7bd5abd 100644 --- a/main.go +++ b/main.go @@ -23,7 +23,7 @@ import ( "text/template" ) -const VERSION = "v17" +const VERSION = "v16" const CONTEXT_USER = 1 const SYNC_PAGINATION = 200 diff --git a/static/js/app.mjs b/static/js/app.mjs index 688b476..7a9ac52 100644 --- a/static/js/app.mjs +++ b/static/js/app.mjs @@ -10,23 +10,25 @@ export class App { this.crumbs = new N2Crumbs() this.crumbsElement = document.getElementById('crumbs') this.nodeUI = document.getElementById('note') + this.showNodeEventSequence = new ShowNodeEventSequence() // discard all GO_TO_NODE events this.sidebar.render().then(sidebar => { document.getElementById('tree').append(sidebar) document.getElementById('tree-nodes')?.focus() }) - _mbus.subscribe('TREE_RENDERED', async () => { + _mbus.subscribe('TREE_TRUNK_FETCHED', async () => { // Subscribing to the start node existing after the tree trunk is // fetched since the NODE_COMPONENT_EXIST message isn't sent for the // root node itself, and the root node should be selected in the tree // after it is rendered when the site is shown without UUID in the URL. const startNode = await this.getStartNode() + document.getElementById('tree').append(await this.sidebar.render()) + document.getElementById('tree-nodes')?.focus() + if (startNode.UUID == ROOT_NODE) this.goToNode(startNode.UUID, false, false) - else - this.goToNode(startNode.UUID, false, false) }) _mbus.subscribe('TREE_NODE_SELECTED', event => { @@ -196,7 +198,7 @@ export class App { await this.sidebar.makeVisible(node, ancestors, dontExpand) _mbus.dispatch('CRUMBS_SET', ancestors, () => this.crumbsElement.replaceChildren(this.crumbs.render())) - _mbus.dispatch('NODE_UI_OPEN', node) + _mbus.dispatch('NODE_UI_OPEN', { node, eventSequence: this.showNodeEventSequence.next() }) _mbus.dispatch('TREE_EXPANSION', { expand: false, when: 'narrow' }) _mbus.dispatch('NODE_UNMODIFIED') }//}}} @@ -206,6 +208,18 @@ export class App { }// }}} } +class ShowNodeEventSequence { + constructor() { + this.seq = 0 + } + next() { + return ++this.seq + } + current() { + return this.seq + } +} + class N2Crumbs extends CustomHTMLElement { static {// {{{ this.tmpl = document.createElement('template') diff --git a/static/js/page_node.mjs b/static/js/page_node.mjs index cca6cf0..a2ebf52 100644 --- a/static/js/page_node.mjs +++ b/static/js/page_node.mjs @@ -42,7 +42,8 @@ export class N2PageNodeUI extends CustomHTMLElement { this.marked = new MarkedPosition() _mbus.subscribe('NODE_UI_OPEN', event => { - this.node = event.detail.data + console.log(event.detail.data.eventSequence, _app.showNodeEventSequence.current()) + this.node = event.detail.data.node this.showMarkdown(true) this.render() }) diff --git a/static/js/sidebar.mjs b/static/js/sidebar.mjs index 285fd44..d1263a3 100644 --- a/static/js/sidebar.mjs +++ b/static/js/sidebar.mjs @@ -160,11 +160,6 @@ export class N2Sidebar extends CustomHTMLElement { this.treeNodeComponents[startnode.UUID] = starttreenode this.elTreenodes.appendChild(await starttreenode.render()) - // Notify the application that the initial tree is rendered (with children) - // and that initial node selection can take place. App will check URL to - // select the correct one. - _mbus.dispatch('TREE_RENDERED') - this.rendered = true return this }// }}}