53 lines
1.5 KiB
TypeScript
53 lines
1.5 KiB
TypeScript
|
|
import { Injectable, computed, signal } from '@angular/core';
|
||
|
|
import { take } from 'rxjs/operators';
|
||
|
|
import { BootstrapConfig } from '../../shared/models/config';
|
||
|
|
import { ConfigService } from '../../core/config/config.service';
|
||
|
|
|
||
|
|
@Injectable({ providedIn: 'root' })
|
||
|
|
export class BuilderConfigFacade {
|
||
|
|
private readonly bootstrapState = signal<BootstrapConfig | null>(null);
|
||
|
|
|
||
|
|
readonly bootstrap = this.bootstrapState.asReadonly();
|
||
|
|
readonly branding = computed(() => this.bootstrapState()?.branding ?? null);
|
||
|
|
readonly featureFlags = computed(() => this.bootstrapState()?.featureFlags ?? null);
|
||
|
|
|
||
|
|
constructor(private readonly configService: ConfigService) {}
|
||
|
|
|
||
|
|
load(): void {
|
||
|
|
this.configService.loadBootstrap().pipe(take(1)).subscribe({
|
||
|
|
next: (config) => this.bootstrapState.set(JSON.parse(JSON.stringify(config)) as BootstrapConfig),
|
||
|
|
error: () => this.bootstrapState.set(null)
|
||
|
|
});
|
||
|
|
}
|
||
|
|
|
||
|
|
updateBrandName(nextBrandName: string): void {
|
||
|
|
const current = this.bootstrapState();
|
||
|
|
if (!current) {
|
||
|
|
return;
|
||
|
|
}
|
||
|
|
|
||
|
|
this.bootstrapState.set({
|
||
|
|
...current,
|
||
|
|
branding: {
|
||
|
|
...current.branding,
|
||
|
|
brandName: nextBrandName
|
||
|
|
}
|
||
|
|
});
|
||
|
|
}
|
||
|
|
|
||
|
|
setFeatureFlag(flag: string, enabled: boolean): void {
|
||
|
|
const current = this.bootstrapState();
|
||
|
|
if (!current) {
|
||
|
|
return;
|
||
|
|
}
|
||
|
|
|
||
|
|
this.bootstrapState.set({
|
||
|
|
...current,
|
||
|
|
featureFlags: {
|
||
|
|
...current.featureFlags,
|
||
|
|
[flag]: enabled
|
||
|
|
}
|
||
|
|
});
|
||
|
|
}
|
||
|
|
}
|