mirror of
https://github.com/zadam/trilium.git
synced 2025-06-06 18:08:33 +02:00
wip
This commit is contained in:
parent
865f7e1ee1
commit
9301679707
29
src/public/javascripts/services/load_results.js
Normal file
29
src/public/javascripts/services/load_results.js
Normal file
@ -0,0 +1,29 @@
|
||||
export class LoadResults {
|
||||
constructor() {
|
||||
this.noteIdToSync = {};
|
||||
this.sourceIdToNoteIds = {};
|
||||
}
|
||||
|
||||
add(noteId, sourceId) {
|
||||
this.noteIdToSync[noteId] = this.noteIdToSync[noteId] || [];
|
||||
|
||||
if (!this.noteIdToSync[noteId].includes(sourceId)) {
|
||||
this.noteIdToSync[noteId].push(sourceId);
|
||||
}
|
||||
|
||||
this.sourceIdToNoteIds[sourceId] = this.sourceIdToNoteIds[sourceId] || [];
|
||||
|
||||
if (!this.sourceIdToNoteIds[sourceId]) {
|
||||
this.sourceIdToNoteIds[sourceId].push(noteId);
|
||||
}
|
||||
}
|
||||
|
||||
getNoteIds() {
|
||||
return Object.keys(this.noteIdToSync);
|
||||
}
|
||||
|
||||
isNoteReloaded(noteId, sourceId) {
|
||||
const sourceIds = this.noteIdToSync[noteId];
|
||||
return sourceIds && !!sourceIds.find(sId => sId !== sourceId);
|
||||
}
|
||||
}
|
@ -2,6 +2,7 @@ import Branch from "../entities/branch.js";
|
||||
import NoteShort from "../entities/note_short.js";
|
||||
import Attribute from "../entities/attribute.js";
|
||||
import server from "./server.js";
|
||||
import {LoadResults} from "./load_results.js";
|
||||
|
||||
/**
|
||||
* TreeCache keeps a read only cache of note tree structure in frontend's memory.
|
||||
@ -158,9 +159,6 @@ class TreeCache {
|
||||
this.addResp([note], branches, []);
|
||||
}
|
||||
}
|
||||
|
||||
const appContext = (await import('./app_context.js')).default;
|
||||
appContext.trigger('notesReloaded', {noteIds})
|
||||
}
|
||||
|
||||
/** @return {Promise<NoteShort[]>} */
|
||||
@ -231,26 +229,31 @@ class TreeCache {
|
||||
}
|
||||
|
||||
async processSyncRows(syncRows) {
|
||||
const noteIdsToRefresh = new Set();
|
||||
const loadResults = new LoadResults();
|
||||
|
||||
syncRows.filter(sync => sync.entityName === 'branches').forEach(sync => {
|
||||
const branch = this.branches[sync.entityId];
|
||||
// we assume that the cache contains the old branch state and we add also the old parentNoteId
|
||||
// so that the old parent can also be updated
|
||||
noteIdsToRefresh.add(branch.parentNoteId);
|
||||
loadResults.add(branch.parentNoteId, sync.sourceId);
|
||||
|
||||
// this should then contain new parentNoteId for which we should also update the cache
|
||||
noteIdsToRefresh.add(sync.parentNoteId);
|
||||
loadResults.add(sync.parentNoteId, sync.sourceId);
|
||||
|
||||
loadResults.add(sync.noteId, sync.sourceId);
|
||||
});
|
||||
|
||||
syncRows.filter(sync => sync.entityName === 'notes').forEach(sync => noteIdsToRefresh.add(sync.entityId));
|
||||
syncRows.filter(sync => sync.entityName === 'notes').forEach(sync => loadResults.add(sync.entityId, sync.sourceId));
|
||||
|
||||
syncRows.filter(sync => sync.entityName === 'note_reordering').forEach(sync => noteIdsToRefresh.add(sync.entityId));
|
||||
syncRows.filter(sync => sync.entityName === 'note_reordering').forEach(sync => loadResults.add(sync.entityId, sync.sourceId));
|
||||
|
||||
// missing reloading the relation target note
|
||||
syncRows.filter(sync => sync.entityName === 'attributes').forEach(sync => noteIdsToRefresh.add(sync.noteId));
|
||||
syncRows.filter(sync => sync.entityName === 'attributes').forEach(sync => loadResults.add(sync.noteId, sync.sourceId));
|
||||
|
||||
await this.reloadNotes(Array.from(noteIdsToRefresh));
|
||||
await this.reloadNotes(loadResults.getNoteIds());
|
||||
|
||||
const appContext = (await import('./app_context.js')).default;
|
||||
appContext.trigger('notesReloaded', {loadResults});
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -219,4 +219,10 @@ export default class NoteDetailWidget extends TabAwareWidget {
|
||||
protectedSessionStartedListener() {
|
||||
this.refresh();
|
||||
}
|
||||
|
||||
notesReloadedListener({loadResults}) {
|
||||
if (loadResults.isNoteReloaded(this.noteId, this.componentId)) {
|
||||
this.refresh();
|
||||
}
|
||||
}
|
||||
}
|
@ -13,7 +13,15 @@ export default class TabAwareWidget extends BasicWidget {
|
||||
}
|
||||
|
||||
isNote(noteId) {
|
||||
return this.tabContext && this.tabContext.note && this.tabContext.note.noteId === noteId;
|
||||
return this.noteId === noteId;
|
||||
}
|
||||
|
||||
get note() {
|
||||
return this.tabContext && this.tabContext.note;
|
||||
}
|
||||
|
||||
get noteId() {
|
||||
return this.note && this.note.noteId;
|
||||
}
|
||||
|
||||
tabNoteSwitchedListener({tabId}) {
|
||||
|
Loading…
x
Reference in New Issue
Block a user