mirror of
https://github.com/zadam/trilium.git
synced 2025-11-02 11:26:15 +01:00
exposing tree cache methods to reload note's parents/children to frontend API
This commit is contained in:
@@ -50,7 +50,10 @@ class TreeCache {
|
||||
}
|
||||
}
|
||||
|
||||
async reload(noteId) {
|
||||
/**
|
||||
* Reload children of given noteId.
|
||||
*/
|
||||
async reloadChildren(noteId) {
|
||||
const resp = await server.post('tree/load', { noteIds: [noteId] });
|
||||
|
||||
for (const childNoteId of this.children[noteId] || []) {
|
||||
@@ -69,6 +72,22 @@ class TreeCache {
|
||||
this.addResp(resp.notes, resp.branches, resp.relations);
|
||||
}
|
||||
|
||||
/**
|
||||
* Reloads parents of given noteId - useful when new note is created to make sure note is loaded
|
||||
* in a correct order.
|
||||
*/
|
||||
async reloadParents(noteId) {
|
||||
// to be able to find parents we need first to make sure it is actually loaded
|
||||
await this.getNote(noteId);
|
||||
|
||||
for (const parentNoteId of this.parents[noteId] || []) {
|
||||
await this.reloadChildren(parentNoteId);
|
||||
}
|
||||
|
||||
// this is done to load the new parents for the noteId
|
||||
await this.reloadChildren(noteId);
|
||||
}
|
||||
|
||||
/** @return {Promise<NoteShort[]>} */
|
||||
async getNotes(noteIds, silentNotFoundError = false) {
|
||||
const missingNoteIds = noteIds.filter(noteId => this.notes[noteId] === undefined);
|
||||
|
||||
Reference in New Issue
Block a user