diff --git a/app/assets/javascripts/directives/views/componentView.ts b/app/assets/javascripts/directives/views/componentView.ts index 4f15778b2..5b593cee7 100644 --- a/app/assets/javascripts/directives/views/componentView.ts +++ b/app/assets/javascripts/directives/views/componentView.ts @@ -55,17 +55,18 @@ class ComponentViewCtrl implements ComponentViewScope { } $onDestroy() { + this.application.componentManager.onComponentIframeDestroyed(this.component.uuid); + if(this.liveComponent) { + this.liveComponent.deinit(); + } else { + this.application.componentManager.removeTemporaryTemplateComponent(this.templateComponent); + } this.cleanUpOn(); (this.cleanUpOn as any) = undefined; this.unregisterComponentHandler(); (this.unregisterComponentHandler as any) = undefined; this.unregisterDesktopObserver(); (this.unregisterDesktopObserver as any) = undefined; - if(this.liveComponent) { - this.liveComponent.deinit(); - } else { - this.application.componentManager.removeTemporaryTemplateComponent(this.templateComponent); - } (this.templateComponent as any) = undefined; (this.liveComponent as any) = undefined; (this.application as any) = undefined; @@ -91,6 +92,7 @@ class ComponentViewCtrl implements ComponentViewScope { return this.templateComponent || this.liveComponent?.item; } + /** @template */ public onIframeInit() { /** Perform in timeout required so that dynamic iframe id is set (based on ctrl values) */ this.$timeout(() => { diff --git a/app/assets/javascripts/services/themeManager.ts b/app/assets/javascripts/services/themeManager.ts index 487b4f7bb..f285ff143 100644 --- a/app/assets/javascripts/services/themeManager.ts +++ b/app/assets/javascripts/services/themeManager.ts @@ -6,7 +6,7 @@ import { SNTheme, ComponentArea, removeFromArray, - ApplicationEvent + ApplicationEvent, ContentType } from 'snjs'; import { AppStateEvent } from '@/ui_models/app_state'; @@ -17,24 +17,16 @@ export class ThemeManager extends ApplicationService { private activeThemes: string[] = [] private unsubState?: () => void private unregisterDesktop!: () => void - private unregisterComponent!: () => void + private unregisterStream!: () => void - /** @override */ - async onAppLaunch() { - super.onAppLaunch(); - this.unsubState = this.webApplication.getAppState().addObserver( - async (eventName) => { - if (eventName === AppStateEvent.DesktopExtsReady) { - this.activateCachedThemes(); - } - } - ); - } - - onAppEvent(event: ApplicationEvent) { + async onAppEvent(event: ApplicationEvent) { super.onAppEvent(event); if (event === ApplicationEvent.SignedOut) { this.deactivateAllThemes(); + } else if (event === ApplicationEvent.StorageReady) { + if (!this.webApplication.getDesktopService().isDesktop) { + await this.activateCachedThemes(); + } } } @@ -47,9 +39,9 @@ export class ThemeManager extends ApplicationService { (this.unsubState as any) = undefined; this.activeThemes.length = 0; this.unregisterDesktop(); - this.unregisterComponent(); + this.unregisterStream(); (this.unregisterDesktop as any) = undefined; - (this.unregisterComponent as any) = undefined; + (this.unregisterStream as any) = undefined; super.deinit(); } @@ -57,9 +49,13 @@ export class ThemeManager extends ApplicationService { async onAppStart() { super.onAppStart(); this.registerObservers(); - if (!this.webApplication.getDesktopService().isDesktop) { - this.activateCachedThemes(); - } + this.unsubState = this.webApplication.getAppState().addObserver( + async (eventName) => { + if (eventName === AppStateEvent.DesktopExtsReady) { + this.activateCachedThemes(); + } + } + ); } private async activateCachedThemes() { @@ -81,17 +77,16 @@ export class ThemeManager extends ApplicationService { } }); - this.unregisterComponent = this.application!.componentManager!.registerHandler({ - identifier: 'themeManager', - areas: [ComponentArea.Themes], - activationHandler: (uuid, component) => { - if (component?.active) { - this.activateTheme(component as SNTheme); + this.unregisterStream = this.application.streamItems(ContentType.Theme, (items) => { + const themes = items as SNTheme[]; + for (const theme of themes) { + if (theme.active) { + this.activateTheme(theme); } else { - this.deactivateTheme(uuid); + this.deactivateTheme(theme.uuid); } } - }); + }) } private deactivateAllThemes() { diff --git a/app/assets/javascripts/views/abstract/pure_view_ctrl.ts b/app/assets/javascripts/views/abstract/pure_view_ctrl.ts index 81734b617..7bab3ee98 100644 --- a/app/assets/javascripts/views/abstract/pure_view_ctrl.ts +++ b/app/assets/javascripts/views/abstract/pure_view_ctrl.ts @@ -124,6 +124,8 @@ export class PureViewCtrl
{ this.onAppFullSync(); } else if (eventName === ApplicationEvent.KeyStatusChanged) { this.onAppKeyChange(); + } else if (eventName === ApplicationEvent.LocalDataLoaded) { + this.onLocalDataLoaded(); } }); } @@ -137,6 +139,10 @@ export class PureViewCtrl
{
await this.resetState();
}
+ onLocalDataLoaded() {
+ /** Optional override */
+ }
+
async onAppLaunch() {
/** Optional override */
}
diff --git a/app/assets/javascripts/views/editor/editor_view.ts b/app/assets/javascripts/views/editor/editor_view.ts
index 75c239261..f0f0ee0f6 100644
--- a/app/assets/javascripts/views/editor/editor_view.ts
+++ b/app/assets/javascripts/views/editor/editor_view.ts
@@ -5,6 +5,7 @@ import angular from 'angular';
import {
ApplicationEvent,
isPayloadSourceRetrieved,
+ isPayloadSourceInternalChange,
ContentType,
ProtectedAction,
SNComponent,
@@ -209,12 +210,6 @@ class EditorViewCtrl extends PureViewCtrl<{}, EditorState> {
});
}
- $onDestroy() {
- if (this.state.tagsComponent) {
- this.application.componentManager!.deregisterComponent(this.state.tagsComponent.uuid);
- }
- }
-
/** @override */
getInitialState() {
return {
@@ -337,7 +332,10 @@ class EditorViewCtrl extends PureViewCtrl<{}, EditorState> {
this.removeComponentsObserver = this.application.streamItems(
ContentType.Component,
- async () => {
+ async (_items, source) => {
+ if (isPayloadSourceInternalChange(source!)) {
+ return;
+ }
if (!this.note) return;
this.reloadStackComponents();
this.reloadNoteTagsComponent();
@@ -350,25 +348,15 @@ class EditorViewCtrl extends PureViewCtrl<{}, EditorState> {
const newEditor = this.application.componentManager!.editorForNote(this.note);
const currentEditor = this.state.editorComponent;
if (currentEditor?.uuid !== newEditor?.uuid) {
- const unloading = this.setState({
+ await this.setState({
/** Unload current component view so that we create a new one */
editorUnloading: true
});
- if (newEditor) {
- /** Register this new editor while the editor view is reloading */
- this.application.componentManager!.registerComponent(newEditor.uuid);
- }
- await unloading;
- const reloading = this.setState({
+ await this.setState({
/** Reload component view */
editorComponent: newEditor,
editorUnloading: false,
});
- if (currentEditor) {
- /** Deregister the current (previous) editor while the editor view is reloading */
- this.application.componentManager!.deregisterComponent(currentEditor.uuid);
- }
- await reloading;
this.reloadFont();
}
this.application.componentManager!.contextItemDidChangeInArea(ComponentArea.Editor);
@@ -1066,15 +1054,6 @@ class EditorViewCtrl extends PureViewCtrl<{}, EditorState> {
reloadNoteTagsComponent() {
const [tagsComponent] =
this.application.componentManager!.componentsForArea(ComponentArea.NoteTags);
- if (tagsComponent?.uuid !== this.state.tagsComponent?.uuid) {
- if (tagsComponent) {
- if (tagsComponent.active) {
- this.application.componentManager!.registerComponent(tagsComponent.uuid);
- } else {
- this.application.componentManager!.deregisterComponent(tagsComponent.uuid);
- }
- }
- }
this.setState({
tagsComponent: tagsComponent?.active ? tagsComponent : undefined
});
diff --git a/app/assets/javascripts/views/tags/tags_view.ts b/app/assets/javascripts/views/tags/tags_view.ts
index 69a57f38e..cbde0bbee 100644
--- a/app/assets/javascripts/views/tags/tags_view.ts
+++ b/app/assets/javascripts/views/tags/tags_view.ts
@@ -46,7 +46,8 @@ class TagsViewCtrl extends PureViewCtrl<{}, TagState> {
private editingOriginalName?: string
formData: { tagTitle?: string } = {}
titles: Partial {
onAppEvent(eventName: ApplicationEvent): void;
/** @override */
onAppStart(): Promise