From d1d8e54d20e44f84af1d990b30f5a7897014f99e Mon Sep 17 00:00:00 2001 From: zadam Date: Fri, 16 Aug 2019 21:52:36 +0200 Subject: [PATCH] fixed state persisting and loading --- src/public/javascripts/services/note_detail.js | 4 ++-- src/public/javascripts/services/sidebar.js | 10 ++++++---- src/public/javascripts/widgets/standard_widget.js | 2 +- 3 files changed, 9 insertions(+), 7 deletions(-) diff --git a/src/public/javascripts/services/note_detail.js b/src/public/javascripts/services/note_detail.js index 1ca30469c..e35f68be7 100644 --- a/src/public/javascripts/services/note_detail.js +++ b/src/public/javascripts/services/note_detail.js @@ -503,12 +503,12 @@ function clearOpenTabsTask() { } function openTabsChanged() { - // we don't want to send too many requests with tab changes so we always schedule task to do this in 3 seconds, + // we don't want to send too many requests with tab changes so we always schedule task to do this in 1 seconds, // but if there's any change in between, we cancel the old one and schedule new one // so effectively we kind of wait until user stopped e.g. quickly switching tabs clearOpenTabsTask(); - tabsChangedTaskId = setTimeout(saveOpenTabs, 3000); + tabsChangedTaskId = setTimeout(saveOpenTabs, 1000); } async function saveOpenTabs() { diff --git a/src/public/javascripts/services/sidebar.js b/src/public/javascripts/services/sidebar.js index c78f2a22d..ed0f416e9 100644 --- a/src/public/javascripts/services/sidebar.js +++ b/src/public/javascripts/services/sidebar.js @@ -6,8 +6,9 @@ import AttributesWidget from "../widgets/attributes.js"; class Sidebar { /** * @param {TabContext} ctx + * @param {object} state */ - constructor(ctx, state) { + constructor(ctx, state = {}) { this.ctx = ctx; this.state = state; this.widgets = []; @@ -15,8 +16,6 @@ class Sidebar { this.$sidebar = ctx.$tabContent.find(".note-detail-sidebar"); this.$widgetContainer = this.$sidebar.find(".note-detail-widget-container"); this.$showSideBarButton = this.ctx.$tabContent.find(".show-sidebar-button"); - this.$showSideBarButton.hide(); - this.$hideSidebarButton = this.$sidebar.find(".hide-sidebar-button"); this.$hideSidebarButton.click(() => { @@ -30,10 +29,13 @@ class Sidebar { this.$showSideBarButton.hide(); this.ctx.stateChanged(); }); + + this.$showSideBarButton.toggle(!state.visible); + this.$sidebar.toggle(state.visible); } isVisible() { - return this.$sidebar.is(":visible"); + return this.$sidebar.css("display") !== "none"; } getSidebarState() { diff --git a/src/public/javascripts/widgets/standard_widget.js b/src/public/javascripts/widgets/standard_widget.js index 3f1ba185f..6bd77e492 100644 --- a/src/public/javascripts/widgets/standard_widget.js +++ b/src/public/javascripts/widgets/standard_widget.js @@ -58,7 +58,7 @@ class StandardWidget { async doRenderBody() {} isVisible() { - return this.$bodyWrapper.is(":visible"); + return this.$bodyWrapper.hasClass("show"); } getWidgetState() {