mirror of
https://github.com/zadam/trilium.git
synced 2025-06-06 18:08:33 +02:00
note complement is now loaded through tree cache
This commit is contained in:
parent
f0cbca2838
commit
0e13678f7c
@ -345,6 +345,7 @@ class AppContext {
|
|||||||
this.openTabsChangedListener();
|
this.openTabsChangedListener();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// FIXME non existent event
|
||||||
noteChangesSavedListener() {
|
noteChangesSavedListener() {
|
||||||
const activeTabContext = this.getActiveTabContext();
|
const activeTabContext = this.getActiveTabContext();
|
||||||
|
|
||||||
|
@ -1,5 +1,3 @@
|
|||||||
import server from './server.js';
|
|
||||||
import NoteComplement from "../entities/note_complement.js";
|
|
||||||
import appContext from "./app_context.js";
|
import appContext from "./app_context.js";
|
||||||
|
|
||||||
function getActiveEditor() {
|
function getActiveEditor() {
|
||||||
@ -13,16 +11,6 @@ function getActiveEditor() {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
async function loadNoteComplement(noteId) {
|
|
||||||
if (!noteId) {
|
|
||||||
return null;
|
|
||||||
}
|
|
||||||
|
|
||||||
const row = await server.get('notes/' + noteId);
|
|
||||||
|
|
||||||
return new NoteComplement(row);
|
|
||||||
}
|
|
||||||
|
|
||||||
function focusOnTitle() {
|
function focusOnTitle() {
|
||||||
appContext.trigger('focusOnTitle');
|
appContext.trigger('focusOnTitle');
|
||||||
}
|
}
|
||||||
@ -47,7 +35,6 @@ $(window).on('beforeunload', () => {
|
|||||||
});
|
});
|
||||||
|
|
||||||
export default {
|
export default {
|
||||||
loadNoteComplement,
|
|
||||||
focusOnTitle,
|
focusOnTitle,
|
||||||
focusAndSelectTitle,
|
focusAndSelectTitle,
|
||||||
getActiveEditor,
|
getActiveEditor,
|
||||||
|
@ -44,7 +44,7 @@ async function mouseEnterHandler() {
|
|||||||
const noteId = treeService.getNoteIdFromNotePath(notePath);
|
const noteId = treeService.getNoteIdFromNotePath(notePath);
|
||||||
|
|
||||||
const note = await treeCache.getNote(noteId);
|
const note = await treeCache.getNote(noteId);
|
||||||
const noteComplement = await noteDetailService.loadNoteComplement(noteId);
|
const noteComplement = await treeCache.getNoteComplement(noteId);
|
||||||
|
|
||||||
const html = await renderTooltip(note, noteComplement);
|
const html = await renderTooltip(note, noteComplement);
|
||||||
|
|
||||||
|
@ -85,11 +85,7 @@ class TabContext extends Component {
|
|||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!this.noteComplementPromise) {
|
return await treeCache.getNoteComplement(this.noteId);
|
||||||
this.noteComplementPromise = noteDetailService.loadNoteComplement(this.noteId);
|
|
||||||
}
|
|
||||||
|
|
||||||
return await this.noteComplementPromise;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
async remove() {
|
async remove() {
|
||||||
|
@ -3,6 +3,7 @@ import NoteShort from "../entities/note_short.js";
|
|||||||
import Attribute from "../entities/attribute.js";
|
import Attribute from "../entities/attribute.js";
|
||||||
import server from "./server.js";
|
import server from "./server.js";
|
||||||
import {LoadResults} from "./load_results.js";
|
import {LoadResults} from "./load_results.js";
|
||||||
|
import NoteComplement from "../entities/note_complement.js";
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* TreeCache keeps a read only cache of note tree structure in frontend's memory.
|
* TreeCache keeps a read only cache of note tree structure in frontend's memory.
|
||||||
@ -26,6 +27,9 @@ class TreeCache {
|
|||||||
|
|
||||||
/** @type {Object.<string, Attribute>} */
|
/** @type {Object.<string, Attribute>} */
|
||||||
this.attributes = {};
|
this.attributes = {};
|
||||||
|
|
||||||
|
/** @type {Object.<string, Promise<NoteComplement>>} */
|
||||||
|
this.noteComplementPromises = {};
|
||||||
}
|
}
|
||||||
|
|
||||||
load(noteRows, branchRows, attributeRows) {
|
load(noteRows, branchRows, attributeRows) {
|
||||||
@ -216,6 +220,14 @@ class TreeCache {
|
|||||||
return child.parentToBranch[parentNoteId];
|
return child.parentToBranch[parentNoteId];
|
||||||
}
|
}
|
||||||
|
|
||||||
|
async getNoteComplement(noteId) {
|
||||||
|
if (!this.noteComplementPromises[noteId]) {
|
||||||
|
this.noteComplementPromises[noteId] = server.get('notes/' + noteId).then(row => new NoteComplement(row));
|
||||||
|
}
|
||||||
|
|
||||||
|
return await this.noteComplementPromises[noteId];
|
||||||
|
}
|
||||||
|
|
||||||
// FIXME does not actually belong here
|
// FIXME does not actually belong here
|
||||||
async processSyncRows(syncRows) {
|
async processSyncRows(syncRows) {
|
||||||
const loadResults = new LoadResults(this);
|
const loadResults = new LoadResults(this);
|
||||||
@ -329,6 +341,8 @@ class TreeCache {
|
|||||||
});
|
});
|
||||||
|
|
||||||
syncRows.filter(sync => sync.entityName === 'note_contents').forEach(sync => {
|
syncRows.filter(sync => sync.entityName === 'note_contents').forEach(sync => {
|
||||||
|
delete this.noteComplementPromises[sync.entityId];
|
||||||
|
|
||||||
loadResults.addNoteContent(sync.entityId, sync.sourceId);
|
loadResults.addNoteContent(sync.entityId, sync.sourceId);
|
||||||
});
|
});
|
||||||
|
|
||||||
|
@ -39,18 +39,11 @@ export default class NoteDetailWidget extends TabAwareWidget {
|
|||||||
this.spacedUpdate = new SpacedUpdate(async () => {
|
this.spacedUpdate = new SpacedUpdate(async () => {
|
||||||
const {note} = this.tabContext;
|
const {note} = this.tabContext;
|
||||||
const {noteId} = note;
|
const {noteId} = note;
|
||||||
const noteComplement = await this.tabContext.getNoteComplement();
|
|
||||||
|
|
||||||
// FIXME hack
|
|
||||||
const dto = note.dto;
|
const dto = note.dto;
|
||||||
dto.content = noteComplement.content = this.getTypeWidget().getContent();
|
dto.content = this.getTypeWidget().getContent();
|
||||||
|
|
||||||
const resp = await server.put('notes/' + noteId, dto, this.componentId);
|
await server.put('notes/' + noteId, dto, this.componentId);
|
||||||
|
|
||||||
noteComplement.dateModified = resp.dateModified;
|
|
||||||
noteComplement.utcDateModified = resp.utcDateModified;
|
|
||||||
|
|
||||||
this.trigger('noteChangesSaved', {noteId})
|
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -226,9 +219,9 @@ export default class NoteDetailWidget extends TabAwareWidget {
|
|||||||
}
|
}
|
||||||
|
|
||||||
async entitiesReloadedListener({loadResults}) {
|
async entitiesReloadedListener({loadResults}) {
|
||||||
if (loadResults.isNoteContentReloaded(this.noteId, this.componentId)) {
|
// we should test what happens when the loaded note is deleted
|
||||||
this.tabContext.noteComplement = await noteDetailService.loadNoteComplement(this.noteId);
|
|
||||||
|
|
||||||
|
if (loadResults.isNoteContentReloaded(this.noteId, this.componentId)) {
|
||||||
this.refreshWithNote(this.note, this.notePath);
|
this.refreshWithNote(this.note, this.notePath);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -67,13 +67,6 @@ class NoteInfoWidget extends StandardWidget {
|
|||||||
.attr("title", note.mime);
|
.attr("title", note.mime);
|
||||||
}
|
}
|
||||||
|
|
||||||
// this is interesting for this widget since dateModified had to change after update
|
|
||||||
noteChangesSavedListener({noteId}) {
|
|
||||||
if (this.isNote(noteId)) {
|
|
||||||
this.refreshWithNote(this.note, this.notePath);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
syncDataListener({data}) {
|
syncDataListener({data}) {
|
||||||
if (data.find(sd => sd.entityName === 'notes' && this.isNote(sd.entityId))) {
|
if (data.find(sd => sd.entityName === 'notes' && this.isNote(sd.entityId))) {
|
||||||
this.refresh();
|
this.refresh();
|
||||||
|
@ -34,13 +34,7 @@ export default class NoteTitleWidget extends TabAwareWidget {
|
|||||||
const noteId = this.tabContext.note.noteId;
|
const noteId = this.tabContext.note.noteId;
|
||||||
const title = this.$noteTitle.val();
|
const title = this.$noteTitle.val();
|
||||||
|
|
||||||
const resp = await server.put(`notes/${noteId}/change-title`, {title});
|
await server.put(`notes/${noteId}/change-title`, {title});
|
||||||
|
|
||||||
// FIXME: minor - does not propagate to other tab contexts with this note though
|
|
||||||
this.tabContext.note.dateModified = resp.dateModified;
|
|
||||||
this.tabContext.note.utcDateModified = resp.utcDateModified;
|
|
||||||
|
|
||||||
this.trigger('noteChangesSaved', {noteId})
|
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user