From 5b35da08f75b5b200b0ae898228234dcd57cb3db Mon Sep 17 00:00:00 2001 From: lotte Date: Wed, 26 Mar 2025 15:01:33 +0100 Subject: [PATCH 1/4] 129694: PoC #4099 solution --- src/app/shared/theme-support/theme.effects.ts | 15 ++------------- src/app/shared/theme-support/theme.service.ts | 7 +++++++ src/app/shared/theme-support/themed.component.ts | 12 +++++++----- 3 files changed, 16 insertions(+), 18 deletions(-) diff --git a/src/app/shared/theme-support/theme.effects.ts b/src/app/shared/theme-support/theme.effects.ts index f16c6cee705..8a8f89c27ad 100644 --- a/src/app/shared/theme-support/theme.effects.ts +++ b/src/app/shared/theme-support/theme.effects.ts @@ -11,25 +11,14 @@ import { getDefaultThemeConfig } from '../../../config/config.util'; import { hasValue } from '../empty.util'; import { SetThemeAction } from './theme.actions'; import { BASE_THEME_NAME } from './theme.constants'; +import { NoOpAction } from '../ngrx/no-op.action'; @Injectable() export class ThemeEffects { /** * Initialize with a theme that doesn't depend on the route. */ - initTheme$ = createEffect(() => - this.actions$.pipe( - ofType(ROOT_EFFECTS_INIT), - map(() => { - const defaultThemeConfig = getDefaultThemeConfig(); - if (hasValue(defaultThemeConfig)) { - return new SetThemeAction(defaultThemeConfig.name); - } else { - return new SetThemeAction(BASE_THEME_NAME); - } - }), - ), - ); + constructor( private actions$: Actions, diff --git a/src/app/shared/theme-support/theme.service.ts b/src/app/shared/theme-support/theme.service.ts index 6d0ba38b5b7..dc146901264 100644 --- a/src/app/shared/theme-support/theme.service.ts +++ b/src/app/shared/theme-support/theme.service.ts @@ -383,6 +383,13 @@ export class ThemeService { take(1), map((theme: Theme) => this.getActionForMatch(theme, currentTheme)), ); + } else if (hasNoValue(currentTheme)) { + const defaultThemeConfig = getDefaultThemeConfig(); + if (hasValue(defaultThemeConfig)) { + return [new SetThemeAction(defaultThemeConfig.name)]; + } else { + return [new SetThemeAction(BASE_THEME_NAME)]; + } } else { // If there are no themes configured, do nothing return observableOf(new NoOpAction()); diff --git a/src/app/shared/theme-support/themed.component.ts b/src/app/shared/theme-support/themed.component.ts index 84b1163d7b6..9e0c64da63f 100644 --- a/src/app/shared/theme-support/themed.component.ts +++ b/src/app/shared/theme-support/themed.component.ts @@ -29,7 +29,7 @@ import { import { GenericConstructor } from '../../core/shared/generic-constructor'; import { hasNoValue, - hasValue, + hasValue, hasValueOperator, isNotEmpty, } from '../empty.util'; import { BASE_THEME_NAME } from './theme.constants'; @@ -71,6 +71,7 @@ export abstract class ThemedComponent implements AfterViewInit protected abstract getComponentName(): string; protected abstract importThemedComponent(themeName: string): Promise; + protected abstract importUnthemedComponent(): Promise; ngOnChanges(changes: SimpleChanges): void { @@ -99,16 +100,17 @@ export abstract class ThemedComponent implements AfterViewInit } initComponentInstance(changes?: SimpleChanges) { - this.themeSub = this.themeService?.getThemeName$().subscribe(() => { - this.renderComponentInstance(changes); - }); + this.themeSub = this.themeService?.getThemeName$() + .pipe(hasValueOperator()) + .subscribe(() => { + this.renderComponentInstance(changes); + }); } protected renderComponentInstance(changes?: SimpleChanges): void { if (hasValue(this.lazyLoadSub)) { this.lazyLoadSub.unsubscribe(); } - if (hasNoValue(this.lazyLoadObs)) { this.lazyLoadObs = combineLatest([ observableOf(changes), From 9c38009edd299c653e4efe33af9bd7c25e4f8381 Mon Sep 17 00:00:00 2001 From: lotte Date: Tue, 22 Apr 2025 18:18:17 +0200 Subject: [PATCH 2/4] 129694: fixed lint issues --- src/app/shared/theme-support/theme.effects.ts | 13 +------------ src/app/shared/theme-support/themed.component.ts | 3 ++- 2 files changed, 3 insertions(+), 13 deletions(-) diff --git a/src/app/shared/theme-support/theme.effects.ts b/src/app/shared/theme-support/theme.effects.ts index 8a8f89c27ad..cc54928c4c2 100644 --- a/src/app/shared/theme-support/theme.effects.ts +++ b/src/app/shared/theme-support/theme.effects.ts @@ -1,17 +1,6 @@ import { Injectable } from '@angular/core'; -import { - Actions, - createEffect, - ofType, - ROOT_EFFECTS_INIT, -} from '@ngrx/effects'; -import { map } from 'rxjs/operators'; +import { Actions } from '@ngrx/effects'; -import { getDefaultThemeConfig } from '../../../config/config.util'; -import { hasValue } from '../empty.util'; -import { SetThemeAction } from './theme.actions'; -import { BASE_THEME_NAME } from './theme.constants'; -import { NoOpAction } from '../ngrx/no-op.action'; @Injectable() export class ThemeEffects { diff --git a/src/app/shared/theme-support/themed.component.ts b/src/app/shared/theme-support/themed.component.ts index 9e0c64da63f..cd40d59825d 100644 --- a/src/app/shared/theme-support/themed.component.ts +++ b/src/app/shared/theme-support/themed.component.ts @@ -29,7 +29,8 @@ import { import { GenericConstructor } from '../../core/shared/generic-constructor'; import { hasNoValue, - hasValue, hasValueOperator, + hasValue, + hasValueOperator, isNotEmpty, } from '../empty.util'; import { BASE_THEME_NAME } from './theme.constants'; From 81f42f426366575f26a78cdd541dbee021cd34ea Mon Sep 17 00:00:00 2001 From: lotte Date: Tue, 22 Apr 2025 18:25:06 +0200 Subject: [PATCH 3/4] 129694: fixed test issues --- src/app/shared/theme-support/theme.effects.spec.ts | 8 -------- 1 file changed, 8 deletions(-) diff --git a/src/app/shared/theme-support/theme.effects.spec.ts b/src/app/shared/theme-support/theme.effects.spec.ts index 96699498c98..9640bbbd584 100644 --- a/src/app/shared/theme-support/theme.effects.spec.ts +++ b/src/app/shared/theme-support/theme.effects.spec.ts @@ -46,13 +46,5 @@ describe('ThemeEffects', () => { }), ); }); - - it('should set the default theme', () => { - const expected = cold('--b-', { - b: new SetThemeAction(BASE_THEME_NAME), - }); - - expect(themeEffects.initTheme$).toBeObservable(expected); - }); }); }); From d49dc7d8c8539bff3314b01993736e5506b38911 Mon Sep 17 00:00:00 2001 From: lotte Date: Tue, 22 Apr 2025 18:54:53 +0200 Subject: [PATCH 4/4] 129694: fixed lint issues --- src/app/shared/theme-support/theme.effects.spec.ts | 7 +------ 1 file changed, 1 insertion(+), 6 deletions(-) diff --git a/src/app/shared/theme-support/theme.effects.spec.ts b/src/app/shared/theme-support/theme.effects.spec.ts index 9640bbbd584..2343c8f0736 100644 --- a/src/app/shared/theme-support/theme.effects.spec.ts +++ b/src/app/shared/theme-support/theme.effects.spec.ts @@ -2,13 +2,8 @@ import { TestBed } from '@angular/core/testing'; import { ROOT_EFFECTS_INIT } from '@ngrx/effects'; import { provideMockActions } from '@ngrx/effects/testing'; import { provideMockStore } from '@ngrx/store/testing'; -import { - cold, - hot, -} from 'jasmine-marbles'; +import { hot } from 'jasmine-marbles'; -import { SetThemeAction } from './theme.actions'; -import { BASE_THEME_NAME } from './theme.constants'; import { ThemeEffects } from './theme.effects'; describe('ThemeEffects', () => {