Merge branch 'fix-ngonchanges-not-working-for-themed-components_contribute-7.4' into fix-ngonchanges-not-working-for-themed-components_contribute-7.6

This commit is contained in:
Alexandre Vryghem
2023-08-06 20:02:43 +02:00
3 changed files with 11 additions and 19 deletions

View File

@@ -29,7 +29,7 @@ export const themeStateSelector = createFeatureSelector<ThemeState>('theme');
export const currentThemeSelector = createSelector( export const currentThemeSelector = createSelector(
themeStateSelector, themeStateSelector,
(state: ThemeState): string => hasValue(state) ? state.currentTheme : undefined (state: ThemeState): string => hasValue(state) ? state.currentTheme : BASE_THEME_NAME,
); );
@Injectable({ @Injectable({
@@ -240,14 +240,7 @@ export class ThemeService {
if (hasValue(parentThemeName)) { if (hasValue(parentThemeName)) {
// inherit the head tags of the parent theme // inherit the head tags of the parent theme
return this.createHeadTags(parentThemeName); return this.createHeadTags(parentThemeName);
} } else {
const defaultThemeConfig = getDefaultThemeConfig();
const defaultThemeName = defaultThemeConfig.name;
if (
hasNoValue(defaultThemeName) ||
themeName === defaultThemeName ||
themeName === BASE_THEME_NAME
) {
// last resort, use fallback favicon.ico // last resort, use fallback favicon.ico
return [ return [
this.createHeadTag({ this.createHeadTag({
@@ -260,9 +253,6 @@ export class ThemeService {
}) })
]; ];
} }
// inherit the head tags of the default theme
return this.createHeadTags(defaultThemeConfig.name);
} }
return headTagConfigs.map(this.createHeadTag.bind(this)); return headTagConfigs.map(this.createHeadTag.bind(this));
@@ -425,9 +415,10 @@ export class ThemeService {
* @private * @private
*/ */
private getActionForMatch(newTheme: Theme, currentThemeName: string): SetThemeAction | NoOpAction { private getActionForMatch(newTheme: Theme, currentThemeName: string): SetThemeAction | NoOpAction {
if (hasValue(newTheme) && newTheme.config.name !== currentThemeName) { const newThemeName: string = newTheme?.config.name ?? BASE_THEME_NAME;
if (newThemeName !== currentThemeName) {
// If we have a match, and it isn't already the active theme, set it as the new theme // If we have a match, and it isn't already the active theme, set it as the new theme
return new SetThemeAction(newTheme.config.name); return new SetThemeAction(newThemeName);
} else { } else {
// Otherwise, do nothing // Otherwise, do nothing
return new NoOpAction(); return new NoOpAction();

View File

@@ -75,7 +75,6 @@ export abstract class ThemedComponent<T> implements OnInit, OnDestroy, OnChanges
} }
ngOnInit(): void { ngOnInit(): void {
this.destroyComponentInstance();
this.initComponentInstance(); this.initComponentInstance();
} }
@@ -96,8 +95,6 @@ export abstract class ThemedComponent<T> implements OnInit, OnDestroy, OnChanges
} }
if (hasNoValue(this.lazyLoadObs)) { if (hasNoValue(this.lazyLoadObs)) {
this.destroyComponentInstance();
this.lazyLoadObs = combineLatest([ this.lazyLoadObs = combineLatest([
observableOf(changes), observableOf(changes),
this.resolveThemedComponent(this.themeService.getThemeName()).pipe( this.resolveThemedComponent(this.themeService.getThemeName()).pipe(
@@ -120,6 +117,7 @@ export abstract class ThemedComponent<T> implements OnInit, OnDestroy, OnChanges
} }
this.lazyLoadSub = this.lazyLoadObs.subscribe(([simpleChanges, constructor]: [SimpleChanges, GenericConstructor<T>]) => { this.lazyLoadSub = this.lazyLoadObs.subscribe(([simpleChanges, constructor]: [SimpleChanges, GenericConstructor<T>]) => {
this.destroyComponentInstance();
const factory = this.resolver.resolveComponentFactory(constructor); const factory = this.resolver.resolveComponentFactory(constructor);
this.compRef = this.vcr.createComponent(factory, undefined, undefined, [this.themedElementContent.nativeElement.childNodes]); this.compRef = this.vcr.createComponent(factory, undefined, undefined, [this.themedElementContent.nativeElement.childNodes]);
if (hasValue(simpleChanges)) { if (hasValue(simpleChanges)) {

View File

@@ -5,7 +5,8 @@ import { environment } from '../environments/environment';
import { hasNoValue } from '../app/shared/empty.util'; import { hasNoValue } from '../app/shared/empty.util';
import { AppConfig } from './app-config.interface'; import { AppConfig } from './app-config.interface';
import { ThemeConfig } from './theme.model'; import { ThemeConfig, NamedThemeConfig } from './theme.model';
import { BASE_THEME_NAME } from '../app/shared/theme-support/theme.constants';
/** /**
* Extend Angular environment with app config. * Extend Angular environment with app config.
@@ -44,7 +45,9 @@ const getDefaultThemeConfig = (): ThemeConfig => {
hasNoValue(themeConfig.regex) && hasNoValue(themeConfig.regex) &&
hasNoValue(themeConfig.handle) && hasNoValue(themeConfig.handle) &&
hasNoValue(themeConfig.uuid) hasNoValue(themeConfig.uuid)
); ) ?? {
name: BASE_THEME_NAME,
} as NamedThemeConfig;
}; };
export { export {