fix note tree flickering (note cache was not updated when expanded status changed)

This commit is contained in:
zadam 2021-02-04 22:05:32 +01:00
parent 48cb4d2ab9
commit 6469937393
5 changed files with 32 additions and 12 deletions

View File

@ -6,13 +6,8 @@ import treeCache from "../../services/tree_cache.js";
const TPL = ` const TPL = `
<div class="edited-notes-widget"> <div class="edited-notes-widget">
<style> <style>
.edited-notes-widget ul { .edited-notes-widget .edited-note-line {
padding-left: 10px !important;
}
.edited-notes-widget ul li {
white-space: nowrap; white-space: nowrap;
list-style-position:inside;
overflow-x: hidden; overflow-x: hidden;
text-overflow: ellipsis; text-overflow: ellipsis;
} }
@ -55,10 +50,10 @@ export default class EditedNotesWidget extends CollapsibleWidget {
await treeCache.getNotes(noteIds, true); // preload all at once await treeCache.getNotes(noteIds, true); // preload all at once
const $list = $('<ul>'); const $list = $('<div>'); // not using <ul> because it's difficult to style correctly with text-overflow
for (const editedNote of editedNotes) { for (const editedNote of editedNotes) {
const $item = $('<li>'); const $item = $('<div class="edited-note-line">');
if (editedNote.isDeleted) { if (editedNote.isDeleted) {
const title = editedNote.title + " (deleted)"; const title = editedNote.title + " (deleted)";

View File

@ -1175,7 +1175,7 @@ export default class NoteTreeWidget extends TabAwareWidget {
}); });
} }
async setExpanded(branchId, isExpanded) { setExpanded(branchId, isExpanded) {
utils.assertArguments(branchId); utils.assertArguments(branchId);
const branch = treeCache.getBranch(branchId, true); const branch = treeCache.getBranch(branchId, true);
@ -1193,7 +1193,7 @@ export default class NoteTreeWidget extends TabAwareWidget {
branch.isExpanded = isExpanded; branch.isExpanded = isExpanded;
await server.put(`branches/${branchId}/expanded/${isExpanded ? 1 : 0}`); server.put(`branches/${branchId}/expanded/${isExpanded ? 1 : 0}`);
} }
async reloadTreeFromCache() { async reloadTreeFromCache() {

View File

@ -5,6 +5,7 @@ const utils = require('../../services/utils');
const entityChangesService = require('../../services/entity_changes.js'); const entityChangesService = require('../../services/entity_changes.js');
const treeService = require('../../services/tree'); const treeService = require('../../services/tree');
const noteService = require('../../services/notes'); const noteService = require('../../services/notes');
const noteCache = require('../../services/note_cache/note_cache');
const repository = require('../../services/repository'); const repository = require('../../services/repository');
const TaskContext = require('../../services/task_context'); const TaskContext = require('../../services/task_context');
@ -126,6 +127,12 @@ function setExpanded(req) {
sql.execute("UPDATE branches SET isExpanded = ? WHERE branchId = ?", [expanded, branchId]); sql.execute("UPDATE branches SET isExpanded = ? WHERE branchId = ?", [expanded, branchId]);
// we don't sync expanded label // we don't sync expanded label
// also this does not trigger updates to the frontend, this would trigger too many reloads // also this does not trigger updates to the frontend, this would trigger too many reloads
const branch = noteCache.branches[branchId];
if (branch) {
branch.isExpanded = !!expanded;
}
} }
} }
@ -148,6 +155,14 @@ function setExpandedForSubtree(req) {
sql.executeMany(`UPDATE branches SET isExpanded = ${expanded} WHERE branchId IN (???)`, branchIds); sql.executeMany(`UPDATE branches SET isExpanded = ${expanded} WHERE branchId IN (???)`, branchIds);
for (const branchId of branchIds) {
const branch = noteCache.branches[branchId];
if (branch) {
branch.isExpanded = !!expanded;
}
}
return { return {
branchIds branchIds
}; };

View File

@ -54,6 +54,15 @@ class Branch {
return this.noteCache.notes[this.parentNoteId]; return this.noteCache.notes[this.parentNoteId];
} }
// for logging etc
get pojo() {
const pojo = {...this};
delete pojo.noteCache;
return pojo;
}
} }
module.exports = Branch; module.exports = Branch;

View File

@ -80,8 +80,9 @@ eventService.subscribe([eventService.ENTITY_CHANGED, eventService.ENTITY_DELETED
delete noteCache.branches[branchId]; delete noteCache.branches[branchId];
} }
else if (branchId in noteCache.branches) { else if (branchId in noteCache.branches) {
// only relevant thing which can change in a branch is prefix // only relevant properties which can change in a branch are prefix and isExpanded
noteCache.branches[branchId].prefix = entity.prefix; noteCache.branches[branchId].prefix = entity.prefix;
noteCache.branches[branchId].isExpanded = entity.isExpanded;
if (childNote) { if (childNote) {
childNote.flatTextCache = null; childNote.flatTextCache = null;