Removed old code, fixed root node showing up in tree

This commit is contained in:
Magnus Åhall 2024-12-19 22:44:10 +01:00
parent 41952df764
commit 147dc12e99
2 changed files with 8 additions and 37 deletions

View file

@ -68,7 +68,6 @@ export class Notes2 extends Component {
class Tree extends Component {
constructor(props) {//{{{
super(props)
this.treeNodes = {}
this.treeNodeComponents = {}
this.treeTrunk = []
this.selectedNode = null
@ -94,29 +93,16 @@ class Tree extends Component {
nodeStore.getTreeNodes('', 0)
.then(async res => {
res.sort(Node.sort)
this.treeNodes = {}
this.treeNodeComponents = {}
this.treeTrunk = []
// A tree of nodes is built. This requires the list of nodes
// returned from the server to be sorted in such a way that
// a parent node always appears before a child node.
// The server uses a recursive SQL query delivering this.
for (const node of res) {
this.treeNodes[node.UUID] = node
// The root node isn't supposed to be shown in the tree.
if (node.UUID === '00000000-0000-0000-0000-000000000000')
continue
if (node.ParentUUID === '')
this.treeTrunk.push(node)
else if (this.treeNodes[node.ParentUUD] !== undefined)
this.treeNodes[node.ParentUUID].Children.push(node)
}
// When starting with an explicit node value, expanding all nodes
// on its path gives the user a sense of location. Not necessarily working
// as the start node isn't guaranteed to have returned data yet.
// XXX this.crumbsUpdateNodes()
this.forceUpdate()
if (callback)
callback()
@ -140,25 +126,6 @@ class Tree extends Component {
isSelected(node) {//{{{
return this.selectedNode?.UUID === node.UUID
}//}}}
crumbsUpdateNodes(node) {//{{{
console.log('crumbs', this.props.app.startNode.Crumbs)
for (const crumb in this.props.app.startNode.Crumbs) {
// Start node is loaded before the tree.
const node = this.treeNodes[crumb.ID]
if (node)
node._expanded = true
// Tree is done before the start node.
const component = this.treeNodeComponents[crumb.ID]
if (component?.component.current)
component.current.expanded.value = true
}
// Will be undefined when called from tree initialization
// (as tree nodes aren't rendered yet)
if (node !== undefined)
this.setSelected(node)
}//}}}
async expandToTrunk(node) {//{{{
// Get all ancestors from a certain node up to the highest grandparent.
const ancestry = await nodeStore.getNodeAncestry(node, [])
@ -167,6 +134,10 @@ class Tree extends Component {
this.setNodeExpanded(ancestry[i].UUID, true)
}
// Already a top node, no need to expand anything.
if (ancestry.length === 0)
return
// Start the chain of by expanding the top node.
this.setNodeExpanded(ancestry[ancestry.length-1].UUID, true)
}//}}}