make note tree initial load non-lazy

This commit is contained in:
zadam 2020-04-30 23:58:34 +02:00
parent 0a05a40186
commit 90d091aedb
4 changed files with 25 additions and 20 deletions

View File

@ -2986,7 +2986,7 @@ var uniqueId = $.fn.extend( {
self = this,
wasExpanded = this.isExpanded();
_assert(this.isLazy(), "load() requires a lazy node");
//_assert(this.isLazy(), "load() requires a lazy node");
// _assert( forceReload || this.isUndefined(), "Pass forceReload=true to re-load a lazy node" );
if (!forceReload && !this.isUndefined()) {
return _getResolvedPromise(this);

View File

@ -21,12 +21,12 @@ async function prepareRootNode() {
return await prepareNode(hoistedBranch);
}
async function prepareBranch(note) {
async function prepareChildren(note) {
if (note.type === 'search') {
return await prepareSearchBranch(note);
return await prepareSearchNoteChildren(note);
}
else {
return await prepareRealBranch(note);
return await prepareNormalNoteChildren(note);
}
}
@ -94,17 +94,24 @@ async function prepareNode(branch) {
icon: getIcon(note),
refKey: note.noteId,
expanded: branch.isExpanded || hoistedNoteId === note.noteId,
lazy: true,
key: utils.randomString(12) // this should prevent some "duplicate key" errors
};
node.folder = getChildBranchesWithoutImages(note).length > 0
|| note.type === 'search';
const childBranches = getChildBranchesWithoutImages(note);
node.folder = childBranches.length > 0
|| note.type === 'search'
node.lazy = node.folder && !node.expanded;
if (node.folder && node.expanded) {
node.children = await prepareChildren(note);
}
return node;
}
async function prepareRealBranch(parentNote) {
async function prepareNormalNoteChildren(parentNote) {
utils.assertArguments(parentNote);
const noteList = [];
@ -132,12 +139,12 @@ function getChildBranchesWithoutImages(parentNote) {
return childBranches.filter(branch => !imageLinks.find(rel => rel.value === branch.noteId));
}
async function prepareSearchBranch(note) {
async function prepareSearchNoteChildren(note) {
await treeCache.reloadNotes([note.noteId]);
const newNote = await treeCache.getNote(note.noteId);
return await prepareRealBranch(newNote);
return await prepareNormalNoteChildren(newNote);
}
function getExtraClasses(note) {
@ -174,7 +181,7 @@ function getExtraClasses(note) {
export default {
prepareRootNode,
prepareBranch,
prepareBranch: prepareChildren,
getExtraClasses,
getIcon,
getChildBranchesWithoutImages

View File

@ -220,7 +220,7 @@ export default class NoteTreeWidget extends TabAwareWidget {
$span.append(refreshSearchButton);
}
},
// this is done to automatically lazy load all expanded search notes after tree load
// this is done to automatically lazy load all expanded notes after tree load
loadChildren: (event, data) => {
// semaphore since the conflict when two processes are trying to load the same data
// breaks the fancytree
@ -441,12 +441,6 @@ export default class NoteTreeWidget extends TabAwareWidget {
return list ? list : []; // if no nodes with this refKey are found, fancy tree returns null
}
async reload() {
const rootNode = await treeBuilder.prepareRootNode();
await this.tree.reload([rootNode]);
}
// must be event since it's triggered from outside the tree
collapseTreeEvent() { this.collapseTree(); }
@ -637,7 +631,11 @@ export default class NoteTreeWidget extends TabAwareWidget {
const activeNotePath = activeNode !== null ? treeService.getNotePath(activeNode) : null;
await this.reload();
const rootNode = await treeBuilder.prepareRootNode();
await this.batchUpdate(async () => {
await this.tree.reload([rootNode]);
});
if (activeNotePath) {
const node = await this.getNodeFromPath(activeNotePath, true);

View File

@ -64,7 +64,7 @@
<!-- Include Fancytree skin and library -->
<link href="libraries/fancytree/skin-win8/ui.fancytree.min.css" rel="stylesheet">
<script src="libraries/fancytree/jquery.fancytree-all-deps.min.js"></script>
<script src="libraries/fancytree/jquery.fancytree-all-deps.js"></script>
<script src="libraries/jquery.hotkeys.js"></script>
<script src="libraries/jquery.fancytree.hotkeys.js"></script>