feat(tenant): add site_title and favicon properties to Tenant interface; update app to set document title and favicon dynamically
This commit is contained in:
@@ -1,4 +1,6 @@
|
||||
import { Component, computed, inject } from '@angular/core';
|
||||
import { DOCUMENT } from '@angular/common';
|
||||
import { Component, computed, effect, inject } from '@angular/core';
|
||||
import { Title } from '@angular/platform-browser';
|
||||
import { RouterOutlet } from '@angular/router';
|
||||
|
||||
import { TenantService } from './core/services/tenant.service';
|
||||
@@ -57,6 +59,28 @@ function hexToRgb(hex: string): string {
|
||||
})
|
||||
export class App {
|
||||
private readonly tenantService = inject(TenantService);
|
||||
private readonly document = inject(DOCUMENT);
|
||||
private readonly title = inject(Title);
|
||||
|
||||
constructor() {
|
||||
effect(() => {
|
||||
const tenant = this.tenantService.tenant();
|
||||
const siteTitle = tenant?.site_title?.trim() || 'ShopitFront';
|
||||
const faviconHref = tenant?.favicon || 'favicon.ico';
|
||||
|
||||
this.title.setTitle(siteTitle);
|
||||
|
||||
let favicon = this.document.head.querySelector<HTMLLinkElement>('link[rel~="icon"]');
|
||||
|
||||
if (!favicon) {
|
||||
favicon = this.document.createElement('link');
|
||||
favicon.setAttribute('rel', 'icon');
|
||||
this.document.head.appendChild(favicon);
|
||||
}
|
||||
|
||||
favicon.setAttribute('href', faviconHref);
|
||||
});
|
||||
}
|
||||
|
||||
protected readonly status = this.tenantService.status;
|
||||
|
||||
|
||||
Reference in New Issue
Block a user