fix(tree): type issues & error if active node is empty

This commit is contained in:
Elian Doran
2025-11-09 11:16:35 +02:00
parent cc0646e79c
commit afa92551ea
2 changed files with 29 additions and 14 deletions

View File

@@ -173,14 +173,6 @@ interface ExpandedSubtreeResponse {
branchIds: string[];
}
interface Node extends Fancytree.NodeData {
noteId: string;
parentNoteId: string;
branchId: string;
isProtected: boolean;
noteType: NoteType;
}
interface RefreshContext {
noteIdsToUpdate: Set<string>;
noteIdsToReload: Set<string>;
@@ -769,7 +761,7 @@ export default class NoteTreeWidget extends NoteContextAwareWidget {
prepareChildren(parentNote: FNote) {
utils.assertArguments(parentNote);
const noteList: Node[] = [];
const noteList: Fancytree.FancytreeNewNode[] = [];
const hideArchivedNotes = this.hideArchivedNotes;
@@ -837,7 +829,7 @@ export default class NoteTreeWidget extends NoteContextAwareWidget {
const isFolder = note.isFolder();
const node: Node = {
const node: Fancytree.FancytreeNewNode = {
noteId: note.noteId,
parentNoteId: branch.parentNoteId,
branchId: branch.branchId,
@@ -849,7 +841,7 @@ export default class NoteTreeWidget extends NoteContextAwareWidget {
refKey: note.noteId,
lazy: true,
folder: isFolder,
expanded: branch.isExpanded && note.type !== "search",
expanded: !!branch.isExpanded && note.type !== "search",
key: utils.randomString(12) // this should prevent some "duplicate key" errors
};
@@ -911,7 +903,6 @@ export default class NoteTreeWidget extends NoteContextAwareWidget {
return extraClasses.join(" ");
}
/** @returns {FancytreeNode[]} */
getSelectedNodes(stopOnParents = false) {
return this.tree.getSelectedNodes(stopOnParents);
}
@@ -1532,7 +1523,7 @@ export default class NoteTreeWidget extends NoteContextAwareWidget {
// Automatically expand the hoisted note by default
const node = this.getActiveNode();
if (node?.data.noteId === this.noteContext.hoistedNoteId){
if (node && node.data.noteId === this.noteContext.hoistedNoteId){
this.setExpanded(node.data.branchId, true);
}
}