state management fixes

This commit is contained in:
zadam 2019-08-28 20:29:10 +02:00
parent ff1d312a43
commit 650d9e0b27
8 changed files with 20 additions and 16 deletions

View File

@ -1,4 +1,4 @@
FROM node:12.6.0-alpine FROM node:12.9.1-alpine
# Create app directory # Create app directory
WORKDIR /usr/src/app WORKDIR /usr/src/app

View File

@ -1,7 +1,7 @@
#!/usr/bin/env bash #!/usr/bin/env bash
PKG_DIR=dist/trilium-linux-x64-server PKG_DIR=dist/trilium-linux-x64-server
NODE_VERSION=12.6.0 NODE_VERSION=12.9.1
rm -r $PKG_DIR rm -r $PKG_DIR
mkdir $PKG_DIR mkdir $PKG_DIR

6
package-lock.json generated
View File

@ -3127,9 +3127,9 @@
"integrity": "sha512-PcW2a0tyTuPHz3tWyYqtK6r1fZ3gp+3Sop8Ph+ZYN81Ob5rwmbHEzaqs10N3BEsaGTkh/ooniXK+WwszGlc2+Q==" "integrity": "sha512-PcW2a0tyTuPHz3tWyYqtK6r1fZ3gp+3Sop8Ph+ZYN81Ob5rwmbHEzaqs10N3BEsaGTkh/ooniXK+WwszGlc2+Q=="
}, },
"electron": { "electron": {
"version": "6.0.4", "version": "6.0.5",
"resolved": "https://registry.npmjs.org/electron/-/electron-6.0.4.tgz", "resolved": "https://registry.npmjs.org/electron/-/electron-6.0.5.tgz",
"integrity": "sha512-zrPi36etADOAjxnVX6TxRNKSWaBscMLd9S7AB+qISzI0dnYIDKycHpc2mB+5QWBd/8cR4m/1NLNTqNhX5KKGFg==", "integrity": "sha512-B3gjUvvXxVH4QnmGEMYne83lG2XJNbNe0FPwVDhzA9FkapnBgvrsE/Fz6NFXTaZm6zSdC2ut1j38rfSTFvUtDA==",
"dev": true, "dev": true,
"requires": { "requires": {
"@types/node": "^10.12.18", "@types/node": "^10.12.18",

View File

@ -77,7 +77,7 @@
"xml2js": "0.4.19" "xml2js": "0.4.19"
}, },
"devDependencies": { "devDependencies": {
"electron": "6.0.4", "electron": "6.0.5",
"electron-builder": "21.2.0", "electron-builder": "21.2.0",
"electron-compile": "6.4.4", "electron-compile": "6.4.4",
"electron-installer-debian": "2.0.0", "electron-installer-debian": "2.0.0",

View File

@ -16,7 +16,7 @@ const linkOverlays = [
export default class LinkMap { export default class LinkMap {
constructor(note, $linkMapContainer, options = {}) { constructor(note, $linkMapContainer, options = {}) {
this.note = note; this.note = note;
this.options = $.extend({ this.options = Object.assign({
maxDepth: 10, maxDepth: 10,
maxNotes: 30, maxNotes: 30,
zoom: 1.0 zoom: 1.0
@ -39,7 +39,7 @@ export default class LinkMap {
} }
async loadNotesAndRelations(options = {}) { async loadNotesAndRelations(options = {}) {
this.options = $.extend(this.options, options); this.options = Object.assign(this.options, options);
this.cleanup(); this.cleanup();

View File

@ -183,6 +183,8 @@ async function renderComponent(ctx) {
ctx.$noteTitle.show(); // this can be hidden by empty detail ctx.$noteTitle.show(); // this can be hidden by empty detail
ctx.$noteTitle.removeAttr("readonly"); // this can be set by protected session service ctx.$noteTitle.removeAttr("readonly"); // this can be set by protected session service
await ctx.initComponent();
await ctx.getComponent().render(); await ctx.getComponent().render();
} }

View File

@ -10,7 +10,9 @@ class Sidebar {
constructor(ctx, state = {}) { constructor(ctx, state = {}) {
/** @property {TabContext} */ /** @property {TabContext} */
this.ctx = ctx; this.ctx = ctx;
this.state = state; this.state = Object.assign({
widgets: []
}, state);
this.widgets = []; this.widgets = [];
this.rendered = false; this.rendered = false;
this.$sidebar = ctx.$tabContent.find(".note-detail-sidebar"); this.$sidebar = ctx.$tabContent.find(".note-detail-sidebar");
@ -73,10 +75,8 @@ class Sidebar {
} }
for (const widgetClass of widgetClasses) { for (const widgetClass of widgetClasses) {
const state = (this.state.widgets || []).find(s => s.name === widgetClass.name);
try { try {
const widget = new widgetClass(this.ctx, options, state); const widget = new widgetClass(this.ctx, options, this.state);
if (await widget.isEnabled()) { if (await widget.isEnabled()) {
this.widgets.push(widget); this.widgets.push(widget);

View File

@ -20,14 +20,16 @@ class StandardWidget {
/** /**
* @param {TabContext} ctx * @param {TabContext} ctx
* @param {Options} options * @param {Options} options
* @param {object} state * @param {object} sidebarState
*/ */
constructor(ctx, options, state) { constructor(ctx, options, sidebarState) {
this.ctx = ctx; this.ctx = ctx;
this.state = state;
// construct in camelCase // construct in camelCase
this.widgetName = this.constructor.name.substr(0, 1).toLowerCase() + this.constructor.name.substr(1); this.widgetName = this.constructor.name.substr(0, 1).toLowerCase() + this.constructor.name.substr(1);
this.widgetOptions = options.getJson(this.widgetName) || {}; this.widgetOptions = options.getJson(this.widgetName) || {};
this.state = sidebarState.widgets.find(s => s.name === this.widgetName) || {
expanded: this.widgetOptions.expanded
};
} }
getWidgetTitle() { return "Untitled widget"; } getWidgetTitle() { return "Untitled widget"; }
@ -47,7 +49,7 @@ class StandardWidget {
this.$bodyWrapper = this.$widget.find('.body-wrapper'); this.$bodyWrapper = this.$widget.find('.body-wrapper');
this.$bodyWrapper.attr('id', widgetId); this.$bodyWrapper.attr('id', widgetId);
if ((this.state && this.state.expanded) || (!this.state && this.widgetOptions.expanded)) { if (this.state.expanded) {
this.$bodyWrapper.collapse("show"); this.$bodyWrapper.collapse("show");
} }