diff --git a/main.go b/main.go index 7bd5abd..7c2decc 100644 --- a/main.go +++ b/main.go @@ -23,7 +23,7 @@ import ( "text/template" ) -const VERSION = "v16" +const VERSION = "v17" const CONTEXT_USER = 1 const SYNC_PAGINATION = 200 diff --git a/static/js/app.mjs b/static/js/app.mjs index 7a9ac52..688b476 100644 --- a/static/js/app.mjs +++ b/static/js/app.mjs @@ -10,25 +10,23 @@ 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_TRUNK_FETCHED', async () => { + _mbus.subscribe('TREE_RENDERED', 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 => { @@ -198,7 +196,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, eventSequence: this.showNodeEventSequence.next() }) + _mbus.dispatch('NODE_UI_OPEN', node) _mbus.dispatch('TREE_EXPANSION', { expand: false, when: 'narrow' }) _mbus.dispatch('NODE_UNMODIFIED') }//}}} @@ -208,18 +206,6 @@ 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 a2ebf52..cca6cf0 100644 --- a/static/js/page_node.mjs +++ b/static/js/page_node.mjs @@ -42,8 +42,7 @@ export class N2PageNodeUI extends CustomHTMLElement { this.marked = new MarkedPosition() _mbus.subscribe('NODE_UI_OPEN', event => { - console.log(event.detail.data.eventSequence, _app.showNodeEventSequence.current()) - this.node = event.detail.data.node + this.node = event.detail.data this.showMarkdown(true) this.render() }) diff --git a/static/js/sidebar.mjs b/static/js/sidebar.mjs index d1263a3..285fd44 100644 --- a/static/js/sidebar.mjs +++ b/static/js/sidebar.mjs @@ -160,6 +160,11 @@ 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 }// }}}