From 9cbda8073bc90a2d1646aec0a58cd4a01f40beba Mon Sep 17 00:00:00 2001 From: Mo Bitar Date: Thu, 3 Jan 2019 23:47:11 -0600 Subject: [PATCH] Reload component context on unhide --- .../javascripts/app/controllers/editor.js | 8 +++--- .../app/services/componentManager.js | 26 +++++++++++++++++++ 2 files changed, 31 insertions(+), 3 deletions(-) diff --git a/app/assets/javascripts/app/controllers/editor.js b/app/assets/javascripts/app/controllers/editor.js index 837d63de5..a4d35eeab 100644 --- a/app/assets/javascripts/app/controllers/editor.js +++ b/app/assets/javascripts/app/controllers/editor.js @@ -713,7 +713,7 @@ angular.module('app') if(this.note) { for(var component of this.componentStack) { if(component.active) { - component.hidden = !component.isExplicitlyEnabledForItem(this.note); + componentManager.setComponentHidden(component, !component.isExplicitlyEnabledForItem(this.note)); } } } @@ -728,7 +728,7 @@ angular.module('app') // If it's not active, then hidden won't be set, and we mean to activate and show it. if(component.hidden || !component.active) { // Unhide, associate with current item - component.hidden = false; + componentManager.setComponentHidden(component, false); this.associateComponentWithCurrentNote(component); if(!component.active) { componentManager.activateComponent(component); @@ -736,7 +736,7 @@ angular.module('app') componentManager.contextItemDidChangeInArea("editor-stack"); } else { // not hidden, hide - component.hidden = true; + componentManager.setComponentHidden(component, true); this.disassociateComponentWithCurrentNote(component); } } @@ -749,6 +749,7 @@ angular.module('app') } component.setDirty(true); + syncManager.sync(); } this.associateComponentWithCurrentNote = function(component) { @@ -759,6 +760,7 @@ angular.module('app') } component.setDirty(true); + syncManager.sync(); } diff --git a/app/assets/javascripts/app/services/componentManager.js b/app/assets/javascripts/app/services/componentManager.js index 045ceb93a..d4761bb6c 100644 --- a/app/assets/javascripts/app/services/componentManager.js +++ b/app/assets/javascripts/app/services/componentManager.js @@ -197,6 +197,32 @@ class ComponentManager { } } + setComponentHidden(component, hidden) { + /* + A hidden component will not receive messages. + However, when a component is unhidden, we need to send it any items it may have + registered streaming for. + */ + if(hidden) { + component.hidden = true; + } else if(component.hidden) { + // Only enter this condition if component is hidden to make this note have double side effects. + component.hidden = false; + + // streamContextItem + let contextObserver = _.find(this.contextStreamObservers, {identifier: component.uuid}); + if(contextObserver) { + this.handleStreamContextItemMessage(component, contextObserver.originalMessage); + } + + // streamItems + let streamObserver = _.find(this.streamObservers, {identifier: component.uuid}); + if(streamObserver) { + this.handleStreamItemsMessage(component, streamObserver.originalMessage); + } + } + } + jsonForItem(item, component, source) { var params = {uuid: item.uuid, content_type: item.content_type, created_at: item.created_at, updated_at: item.updated_at, deleted: item.deleted}; params.content = item.createContentJSONFromProperties();