Browse Source

fix(dynamic-layout): replace OnInit implementation with environment change listener

pull/23458/head
Maik Stegemann 1 year ago
parent
commit
e913c85bd8
  1. 30
      npm/ng-packs/packages/core/src/lib/components/dynamic-layout.component.ts

30
npm/ng-packs/packages/core/src/lib/components/dynamic-layout.component.ts

@ -13,6 +13,7 @@ import { TreeNode } from '../utils/tree-utils';
import { DYNAMIC_LAYOUTS_TOKEN } from '../tokens/dynamic-layout.token'; import { DYNAMIC_LAYOUTS_TOKEN } from '../tokens/dynamic-layout.token';
import { EnvironmentService } from '../services'; import { EnvironmentService } from '../services';
import { NgComponentOutlet } from '@angular/common'; import { NgComponentOutlet } from '@angular/common';
import { filter, take } from 'rxjs';
@Component({ @Component({
selector: 'abp-dynamic-layout', selector: 'abp-dynamic-layout',
@ -24,7 +25,7 @@ import { NgComponentOutlet } from '@angular/common';
providers: [SubscriptionService], providers: [SubscriptionService],
imports: [NgComponentOutlet], imports: [NgComponentOutlet],
}) })
export class DynamicLayoutComponent implements OnInit { export class DynamicLayoutComponent {
layout?: Type<any>; layout?: Type<any>;
layoutKey?: eLayoutType; layoutKey?: eLayoutType;
readonly layouts = inject(DYNAMIC_LAYOUTS_TOKEN); readonly layouts = inject(DYNAMIC_LAYOUTS_TOKEN);
@ -48,17 +49,7 @@ export class DynamicLayoutComponent implements OnInit {
} }
this.checkLayoutOnNavigationEnd(); this.checkLayoutOnNavigationEnd();
this.listenToLanguageChange(); this.listenToLanguageChange();
} this.listenToEnvironmentChange();
ngOnInit(): void {
if (this.layout) {
return;
}
const { oAuthConfig } = this.environment.getEnvironment();
if (oAuthConfig.responseType === 'code') {
this.getLayout();
}
} }
private checkLayoutOnNavigationEnd() { private checkLayoutOnNavigationEnd() {
@ -120,4 +111,19 @@ export class DynamicLayoutComponent implements OnInit {
private getComponent(key: string): ReplaceableComponents.ReplaceableComponent | undefined { private getComponent(key: string): ReplaceableComponents.ReplaceableComponent | undefined {
return this.replaceableComponents.get(key); return this.replaceableComponents.get(key);
} }
private listenToEnvironmentChange() {
this.environment
.createOnUpdateStream(x => x.oAuthConfig)
.pipe(
take(1),
filter(config => config.responseType === 'code'),
)
.subscribe(() => {
if (this.layout) {
return;
}
this.getLayout();
});
}
} }

Loading…
Cancel
Save