From 650d9e0b27a74e8487e7dff13929ef2601514f71 Mon Sep 17 00:00:00 2001 From: zadam Date: Wed, 28 Aug 2019 20:29:10 +0200 Subject: [PATCH] state management fixes --- Dockerfile | 2 +- bin/build-server.sh | 2 +- package-lock.json | 6 +++--- package.json | 2 +- src/public/javascripts/services/link_map.js | 4 ++-- src/public/javascripts/services/note_detail.js | 2 ++ src/public/javascripts/services/sidebar.js | 8 ++++---- src/public/javascripts/widgets/standard_widget.js | 10 ++++++---- 8 files changed, 20 insertions(+), 16 deletions(-) diff --git a/Dockerfile b/Dockerfile index 31281ddd1..b47edaf42 100644 --- a/Dockerfile +++ b/Dockerfile @@ -1,4 +1,4 @@ -FROM node:12.6.0-alpine +FROM node:12.9.1-alpine # Create app directory WORKDIR /usr/src/app diff --git a/bin/build-server.sh b/bin/build-server.sh index d0ac558bb..12d46e660 100755 --- a/bin/build-server.sh +++ b/bin/build-server.sh @@ -1,7 +1,7 @@ #!/usr/bin/env bash PKG_DIR=dist/trilium-linux-x64-server -NODE_VERSION=12.6.0 +NODE_VERSION=12.9.1 rm -r $PKG_DIR mkdir $PKG_DIR diff --git a/package-lock.json b/package-lock.json index 30d17bb07..bcd9585a4 100644 --- a/package-lock.json +++ b/package-lock.json @@ -3127,9 +3127,9 @@ "integrity": "sha512-PcW2a0tyTuPHz3tWyYqtK6r1fZ3gp+3Sop8Ph+ZYN81Ob5rwmbHEzaqs10N3BEsaGTkh/ooniXK+WwszGlc2+Q==" }, "electron": { - "version": "6.0.4", - "resolved": "https://registry.npmjs.org/electron/-/electron-6.0.4.tgz", - "integrity": "sha512-zrPi36etADOAjxnVX6TxRNKSWaBscMLd9S7AB+qISzI0dnYIDKycHpc2mB+5QWBd/8cR4m/1NLNTqNhX5KKGFg==", + "version": "6.0.5", + "resolved": "https://registry.npmjs.org/electron/-/electron-6.0.5.tgz", + "integrity": "sha512-B3gjUvvXxVH4QnmGEMYne83lG2XJNbNe0FPwVDhzA9FkapnBgvrsE/Fz6NFXTaZm6zSdC2ut1j38rfSTFvUtDA==", "dev": true, "requires": { "@types/node": "^10.12.18", diff --git a/package.json b/package.json index b9d735373..1bdc3a970 100644 --- a/package.json +++ b/package.json @@ -77,7 +77,7 @@ "xml2js": "0.4.19" }, "devDependencies": { - "electron": "6.0.4", + "electron": "6.0.5", "electron-builder": "21.2.0", "electron-compile": "6.4.4", "electron-installer-debian": "2.0.0", diff --git a/src/public/javascripts/services/link_map.js b/src/public/javascripts/services/link_map.js index 0d776da79..29cc7e1c6 100644 --- a/src/public/javascripts/services/link_map.js +++ b/src/public/javascripts/services/link_map.js @@ -16,7 +16,7 @@ const linkOverlays = [ export default class LinkMap { constructor(note, $linkMapContainer, options = {}) { this.note = note; - this.options = $.extend({ + this.options = Object.assign({ maxDepth: 10, maxNotes: 30, zoom: 1.0 @@ -39,7 +39,7 @@ export default class LinkMap { } async loadNotesAndRelations(options = {}) { - this.options = $.extend(this.options, options); + this.options = Object.assign(this.options, options); this.cleanup(); diff --git a/src/public/javascripts/services/note_detail.js b/src/public/javascripts/services/note_detail.js index c53d7446a..66b898cea 100644 --- a/src/public/javascripts/services/note_detail.js +++ b/src/public/javascripts/services/note_detail.js @@ -183,6 +183,8 @@ async function renderComponent(ctx) { ctx.$noteTitle.show(); // this can be hidden by empty detail ctx.$noteTitle.removeAttr("readonly"); // this can be set by protected session service + await ctx.initComponent(); + await ctx.getComponent().render(); } diff --git a/src/public/javascripts/services/sidebar.js b/src/public/javascripts/services/sidebar.js index 17155b5f4..878de8eac 100644 --- a/src/public/javascripts/services/sidebar.js +++ b/src/public/javascripts/services/sidebar.js @@ -10,7 +10,9 @@ class Sidebar { constructor(ctx, state = {}) { /** @property {TabContext} */ this.ctx = ctx; - this.state = state; + this.state = Object.assign({ + widgets: [] + }, state); this.widgets = []; this.rendered = false; this.$sidebar = ctx.$tabContent.find(".note-detail-sidebar"); @@ -73,10 +75,8 @@ class Sidebar { } for (const widgetClass of widgetClasses) { - const state = (this.state.widgets || []).find(s => s.name === widgetClass.name); - try { - const widget = new widgetClass(this.ctx, options, state); + const widget = new widgetClass(this.ctx, options, this.state); if (await widget.isEnabled()) { this.widgets.push(widget); diff --git a/src/public/javascripts/widgets/standard_widget.js b/src/public/javascripts/widgets/standard_widget.js index 9ec709365..b5e8b1b89 100644 --- a/src/public/javascripts/widgets/standard_widget.js +++ b/src/public/javascripts/widgets/standard_widget.js @@ -20,14 +20,16 @@ class StandardWidget { /** * @param {TabContext} ctx * @param {Options} options - * @param {object} state + * @param {object} sidebarState */ - constructor(ctx, options, state) { + constructor(ctx, options, sidebarState) { this.ctx = ctx; - this.state = state; // construct in camelCase this.widgetName = this.constructor.name.substr(0, 1).toLowerCase() + this.constructor.name.substr(1); this.widgetOptions = options.getJson(this.widgetName) || {}; + this.state = sidebarState.widgets.find(s => s.name === this.widgetName) || { + expanded: this.widgetOptions.expanded + }; } getWidgetTitle() { return "Untitled widget"; } @@ -47,7 +49,7 @@ class StandardWidget { this.$bodyWrapper = this.$widget.find('.body-wrapper'); this.$bodyWrapper.attr('id', widgetId); - if ((this.state && this.state.expanded) || (!this.state && this.widgetOptions.expanded)) { + if (this.state.expanded) { this.$bodyWrapper.collapse("show"); }