Fixed initial node when visiting page

This commit is contained in:
Magnus Åhall 2026-06-08 10:34:55 +02:00
parent 303c7d9b2d
commit b1c85d96e9
3 changed files with 29 additions and 17 deletions

View file

@ -11,12 +11,22 @@ export class App {
this.crumbsElement = document.getElementById('crumbs')
this.nodeUI = document.getElementById('note')
_mbus.subscribe('TREE_TRUNK_FETCHED', async () => {
document.getElementById('tree').append(this.tree.render())
// 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()
_mbus.subscribe(`NODE_COMPONENT_EXIST_${startNode.UUID}`, () => {
this.goToNode(startNode.UUID, false, false)
})
document.getElementById('tree').append(await this.tree.render())
document.getElementById('tree-nodes')?.focus()
const startNode = await this.getStartNode()
this.goToNode(startNode.UUID, false, false)
if (startNode.UUID == ROOT_NODE)
this.goToNode(startNode.UUID, false, false)
})
_mbus.subscribe('TREE_NODE_SELECTED', event => {
@ -41,7 +51,7 @@ export class App {
if (e.startsWith('page-'))
classList.remove(e)
})
classList.add('page-'+page)
classList.add('page-' + page)
})
window.addEventListener('keydown', event => this.keyHandler(event))