Fix surface color not restoring correctly from saved settings
This commit is contained in:
+2
-2
@@ -153,11 +153,11 @@ export class BookFilterComponent implements OnInit, OnDestroy {
|
|||||||
|
|
||||||
bookService = inject(BookService);
|
bookService = inject(BookService);
|
||||||
userService = inject(UserService);
|
userService = inject(UserService);
|
||||||
sidebarFilterSortingManager = inject(FilterSortPreferenceService);
|
filterSortPreferenceService = inject(FilterSortPreferenceService);
|
||||||
|
|
||||||
ngOnInit(): void {
|
ngOnInit(): void {
|
||||||
combineLatest([
|
combineLatest([
|
||||||
this.sidebarFilterSortingManager.sortMode$.pipe(distinctUntilChanged()),
|
this.filterSortPreferenceService.sortMode$.pipe(distinctUntilChanged()),
|
||||||
this.entity$ ?? of(null),
|
this.entity$ ?? of(null),
|
||||||
this.entityType$ ?? of(EntityType.ALL_BOOKS)
|
this.entityType$ ?? of(EntityType.ALL_BOOKS)
|
||||||
])
|
])
|
||||||
|
|||||||
+22
-25
@@ -27,12 +27,11 @@ interface Palette {
|
|||||||
imports: [CommonModule, FormsModule, InputSwitchModule, ButtonModule, RadioButtonModule, ToggleSwitchModule]
|
imports: [CommonModule, FormsModule, InputSwitchModule, ButtonModule, RadioButtonModule, ToggleSwitchModule]
|
||||||
})
|
})
|
||||||
export class ThemeConfiguratorComponent implements OnInit {
|
export class ThemeConfiguratorComponent implements OnInit {
|
||||||
|
readonly config = inject(PrimeNG);
|
||||||
|
readonly configService = inject(AppConfigService);
|
||||||
|
readonly platformId = inject(PLATFORM_ID);
|
||||||
|
|
||||||
config: PrimeNG = inject(PrimeNG);
|
readonly surfaces: Palette[] = [
|
||||||
configService: AppConfigService = inject(AppConfigService);
|
|
||||||
platformId = inject(PLATFORM_ID);
|
|
||||||
|
|
||||||
surfaces = [
|
|
||||||
{
|
{
|
||||||
name: 'slate',
|
name: 'slate',
|
||||||
palette: {
|
palette: {
|
||||||
@@ -171,38 +170,35 @@ export class ThemeConfiguratorComponent implements OnInit {
|
|||||||
}
|
}
|
||||||
];
|
];
|
||||||
|
|
||||||
selectedPrimaryColor = computed(() => {
|
readonly selectedPrimaryColor = computed(() => this.configService.appState().primary);
|
||||||
return this.configService.appState().primary;
|
readonly selectedSurfaceColor = computed(() => this.configService.appState().surface);
|
||||||
});
|
|
||||||
|
|
||||||
selectedSurfaceColor = computed(() => this.configService.appState().surface);
|
readonly primaryColors = computed<Palette[]>(() => {
|
||||||
|
const presetPalette = (Aura.primitive ?? {}) as Record<string, ColorPalette>;
|
||||||
primaryColors = computed<Palette[]>(() => {
|
|
||||||
const presetPalette = (Aura.primitive ?? {}) as Partial<Record<string, Palette>>;
|
|
||||||
const colors = ['emerald', 'green', 'lime', 'orange', 'amber', 'yellow', 'teal', 'cyan', 'sky', 'blue', 'indigo', 'violet', 'purple', 'fuchsia', 'pink', 'rose'];
|
const colors = ['emerald', 'green', 'lime', 'orange', 'amber', 'yellow', 'teal', 'cyan', 'sky', 'blue', 'indigo', 'violet', 'purple', 'fuchsia', 'pink', 'rose'];
|
||||||
return [{ name: 'noir', palette: {} }].concat(
|
return [{ name: 'noir', palette: {} }].concat(
|
||||||
colors.map((color) => ({
|
colors.map(name => ({
|
||||||
name: color,
|
name,
|
||||||
palette: presetPalette[color] ?? {}
|
palette: presetPalette[name] ?? {}
|
||||||
}))
|
}))
|
||||||
);
|
);
|
||||||
});
|
});
|
||||||
|
|
||||||
|
ngOnInit(): void {
|
||||||
ngOnInit() {
|
|
||||||
if (isPlatformBrowser(this.platformId)) {
|
if (isPlatformBrowser(this.platformId)) {
|
||||||
this.onPresetChange();
|
this.onPresetChange(); // Ensures both primary and surface colors apply
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
getPresetExt(): object {
|
getPresetExt(): object {
|
||||||
const color = this.primaryColors().find((c) => c.name === this.selectedPrimaryColor());
|
const color = this.primaryColors().find(c => c.name === this.selectedPrimaryColor());
|
||||||
if (!color) return {}; // Safe fallback
|
const surface = this.surfaces.find(s => s.name === this.selectedSurfaceColor());
|
||||||
|
|
||||||
|
if (!color) return {};
|
||||||
if (color.name === 'noir') {
|
if (color.name === 'noir') {
|
||||||
return {
|
return {
|
||||||
semantic: {
|
semantic: {
|
||||||
primary: {...this.surfaces.find((s) => s.name === this.selectedSurfaceColor())?.palette},
|
primary: { ...(surface?.palette ?? {}) },
|
||||||
colorScheme: {
|
colorScheme: {
|
||||||
dark: {
|
dark: {
|
||||||
primary: {
|
primary: {
|
||||||
@@ -255,16 +251,17 @@ export class ThemeConfiguratorComponent implements OnInit {
|
|||||||
event.stopPropagation();
|
event.stopPropagation();
|
||||||
}
|
}
|
||||||
|
|
||||||
applyTheme(type: string, color: any) {
|
applyTheme(type: 'primary' | 'surface', color: { name: string; palette?: ColorPalette }) {
|
||||||
if (type === 'primary') {
|
if (type === 'primary') {
|
||||||
updatePreset(this.getPresetExt());
|
updatePreset(this.getPresetExt());
|
||||||
} else if (type === 'surface') {
|
} else if (type === 'surface') {
|
||||||
updateSurfacePalette(color.palette);
|
updateSurfacePalette(color.palette ?? {});
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
onPresetChange() {
|
onPresetChange(): void {
|
||||||
const surfacePalette = this.primaryColors().find(c => c.name === this.selectedSurfaceColor())?.palette;
|
const surface = this.surfaces.find(s => s.name === this.selectedSurfaceColor());
|
||||||
|
const surfacePalette = surface?.palette ?? {};
|
||||||
$t().preset(Aura).preset(this.getPresetExt()).surfacePalette(surfacePalette).use({ useDefaultOptions: true });
|
$t().preset(Aura).preset(this.getPresetExt()).surfacePalette(surfacePalette).use({ useDefaultOptions: true });
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user