refactor(ui): move theme and locale settings location (#1624)
This commit is contained in:
@@ -471,6 +471,13 @@ export class UserService {
|
|||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
async updateCurrentUserProfile(updateData: UserProfileUpdateRequest): Promise<User | null> {
|
||||||
|
const user = this.currentUser();
|
||||||
|
if (!user) return null;
|
||||||
|
|
||||||
|
return lastValueFrom(this.updateUserProfile(user.id, updateData));
|
||||||
|
}
|
||||||
|
|
||||||
deleteUser(userId: number): Observable<void> {
|
deleteUser(userId: number): Observable<void> {
|
||||||
return this.http.delete<void>(`${this.userUrl}/${userId}`);
|
return this.http.delete<void>(`${this.userUrl}/${userId}`);
|
||||||
}
|
}
|
||||||
|
|||||||
-122
@@ -22,128 +22,6 @@
|
|||||||
</div>
|
</div>
|
||||||
|
|
||||||
<div class="form-container">
|
<div class="form-container">
|
||||||
<div class="form-section preferences-section">
|
|
||||||
<h3 class="section-title">
|
|
||||||
<i class="pi pi-palette" aria-hidden="true"></i>
|
|
||||||
{{ 'settingsView.theme.sectionTitle' | transloco }}
|
|
||||||
</h3>
|
|
||||||
|
|
||||||
<div class="form-field">
|
|
||||||
<label class="field-label" for="app-appearance">{{ 'layout.theme.appearance' | transloco }}</label>
|
|
||||||
<p-select
|
|
||||||
inputId="app-appearance"
|
|
||||||
[options]="appearanceOptions()"
|
|
||||||
[ngModel]="selectedAppearancePreference()"
|
|
||||||
(ngModelChange)="updateAppearancePreference($event)"
|
|
||||||
optionLabel="label"
|
|
||||||
optionValue="value"
|
|
||||||
appendTo="body"
|
|
||||||
class="preference-select">
|
|
||||||
</p-select>
|
|
||||||
</div>
|
|
||||||
|
|
||||||
@if (showOledDarkModeToggle()) {
|
|
||||||
<div class="theme-toggle-row">
|
|
||||||
<label class="field-label" for="oled-dark-mode">{{ 'settingsView.theme.oledDarkMode' | transloco }}</label>
|
|
||||||
<p-toggleswitch
|
|
||||||
inputId="oled-dark-mode"
|
|
||||||
[ngModel]="oledDarkMode()"
|
|
||||||
(ngModelChange)="updateOledDarkMode($event)">
|
|
||||||
</p-toggleswitch>
|
|
||||||
</div>
|
|
||||||
}
|
|
||||||
|
|
||||||
<div class="form-field">
|
|
||||||
<label class="field-label" for="app-theme">{{ 'layout.theme.theme' | transloco }}</label>
|
|
||||||
<p-select
|
|
||||||
inputId="app-theme"
|
|
||||||
[options]="themeOptions()"
|
|
||||||
[ngModel]="selectedThemePreference()"
|
|
||||||
(ngModelChange)="updateThemePreference($event)"
|
|
||||||
optionLabel="label"
|
|
||||||
optionValue="value"
|
|
||||||
appendTo="body"
|
|
||||||
class="preference-select">
|
|
||||||
<ng-template #selectedItem let-option>
|
|
||||||
@if (option) {
|
|
||||||
<span class="inline-flex items-center gap-2.5 min-w-0">
|
|
||||||
@if (option.value !== 'custom') {
|
|
||||||
<span
|
|
||||||
class="w-3.5 h-3.5 rounded-full shrink-0 ring-1 ring-black/15 ring-inset bg-(--color-primary-500)"
|
|
||||||
[attr.data-app-theme]="option.value"
|
|
||||||
aria-hidden="true">
|
|
||||||
</span>
|
|
||||||
}
|
|
||||||
<span>{{ option.label }}</span>
|
|
||||||
</span>
|
|
||||||
}
|
|
||||||
</ng-template>
|
|
||||||
<ng-template #item let-option>
|
|
||||||
<span class="inline-flex items-center gap-2.5 min-w-0">
|
|
||||||
@if (option.value !== 'custom') {
|
|
||||||
<span
|
|
||||||
class="w-3.5 h-3.5 rounded-full shrink-0 ring-1 ring-black/15 ring-inset bg-(--color-primary-500)"
|
|
||||||
[attr.data-app-theme]="option.value"
|
|
||||||
aria-hidden="true">
|
|
||||||
</span>
|
|
||||||
}
|
|
||||||
<span>{{ option.label }}</span>
|
|
||||||
</span>
|
|
||||||
</ng-template>
|
|
||||||
</p-select>
|
|
||||||
</div>
|
|
||||||
|
|
||||||
<div class="form-field">
|
|
||||||
<label class="field-label" for="theme-sync">{{ 'layout.theme.syncAcrossDevices' | transloco }}</label>
|
|
||||||
<p-toggleswitch
|
|
||||||
inputId="theme-sync"
|
|
||||||
[ngModel]="selectedThemeSyncEnabled()"
|
|
||||||
(ngModelChange)="updateThemeSyncEnabled($event)">
|
|
||||||
</p-toggleswitch>
|
|
||||||
</div>
|
|
||||||
|
|
||||||
@if (selectedThemePreference() === 'custom') {
|
|
||||||
<fieldset class="form-field">
|
|
||||||
<legend class="field-label">{{ 'layout.theme.customPrimary' | transloco }}</legend>
|
|
||||||
<div class="custom-primary-card">
|
|
||||||
<div class="custom-primary-options">
|
|
||||||
@for (palette of customPrimaryOptions; track palette) {
|
|
||||||
<button
|
|
||||||
type="button"
|
|
||||||
[class]="'w-7 h-7 rounded-full cursor-pointer shadow-[inset_0_0_0_1px_rgb(0_0_0_/_0.1)] dark:shadow-[inset_0_0_0_1px_rgb(255_255_255_/_0.1)] ' + (palette === selectedCustomPrimary() ? 'ring-1 ring-black dark:ring-white' : '')"
|
|
||||||
[style.background]="'var(--color-' + palette + '-500)'"
|
|
||||||
[attr.aria-label]="palette"
|
|
||||||
[attr.aria-pressed]="palette === selectedCustomPrimary()"
|
|
||||||
(click)="updateCustomPrimary(palette)">
|
|
||||||
</button>
|
|
||||||
}
|
|
||||||
</div>
|
|
||||||
</div>
|
|
||||||
</fieldset>
|
|
||||||
}
|
|
||||||
</div>
|
|
||||||
|
|
||||||
<div class="gradient-divider"></div>
|
|
||||||
|
|
||||||
<div class="form-section preferences-section">
|
|
||||||
<h3 class="section-title">
|
|
||||||
<i class="pi pi-language" aria-hidden="true"></i>
|
|
||||||
{{ 'settingsView.language.sectionTitle' | transloco }}
|
|
||||||
</h3>
|
|
||||||
|
|
||||||
<p-select
|
|
||||||
[options]="languageOptions"
|
|
||||||
[ngModel]="activeLang()"
|
|
||||||
(ngModelChange)="onLanguageChange($event)"
|
|
||||||
optionLabel="label"
|
|
||||||
optionValue="value"
|
|
||||||
appendTo="body"
|
|
||||||
class="preference-select">
|
|
||||||
</p-select>
|
|
||||||
</div>
|
|
||||||
|
|
||||||
<div class="gradient-divider"></div>
|
|
||||||
|
|
||||||
<div class="form-section">
|
<div class="form-section">
|
||||||
<h3 class="section-title">
|
<h3 class="section-title">
|
||||||
<i class="pi pi-id-card"></i>
|
<i class="pi pi-id-card"></i>
|
||||||
|
|||||||
-39
@@ -67,14 +67,6 @@
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
.preferences-section {
|
|
||||||
gap: 1rem;
|
|
||||||
}
|
|
||||||
|
|
||||||
.preference-select {
|
|
||||||
width: 100%;
|
|
||||||
}
|
|
||||||
|
|
||||||
.form-field {
|
.form-field {
|
||||||
display: flex;
|
display: flex;
|
||||||
flex-direction: column;
|
flex-direction: column;
|
||||||
@@ -134,37 +126,6 @@
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
fieldset.form-field {
|
|
||||||
min-width: 0;
|
|
||||||
margin: 0;
|
|
||||||
padding: 0;
|
|
||||||
border: 0;
|
|
||||||
}
|
|
||||||
|
|
||||||
.custom-primary-card {
|
|
||||||
padding: 0.75rem;
|
|
||||||
background: var(--color-card);
|
|
||||||
border-radius: 6px;
|
|
||||||
box-shadow: inset 0 0 0 1px var(--color-border);
|
|
||||||
}
|
|
||||||
|
|
||||||
.custom-primary-options {
|
|
||||||
display: flex;
|
|
||||||
flex-wrap: wrap;
|
|
||||||
gap: 0.5rem;
|
|
||||||
}
|
|
||||||
|
|
||||||
.theme-toggle-row {
|
|
||||||
display: flex;
|
|
||||||
align-items: center;
|
|
||||||
justify-content: space-between;
|
|
||||||
gap: 1rem;
|
|
||||||
|
|
||||||
.field-label {
|
|
||||||
margin: 0;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
.edit-actions {
|
.edit-actions {
|
||||||
margin-top: 0.5rem;
|
margin-top: 0.5rem;
|
||||||
|
|
||||||
|
|||||||
+1
-120
@@ -1,27 +1,12 @@
|
|||||||
import {Component, DestroyRef, computed, effect, inject} from '@angular/core';
|
import {Component, effect, inject} from '@angular/core';
|
||||||
import {Button} from 'primeng/button';
|
import {Button} from 'primeng/button';
|
||||||
import {AbstractControl, FormBuilder, FormGroup, FormsModule, ReactiveFormsModule, ValidationErrors, ValidatorFn, Validators} from '@angular/forms';
|
import {AbstractControl, FormBuilder, FormGroup, FormsModule, ReactiveFormsModule, ValidationErrors, ValidatorFn, Validators} from '@angular/forms';
|
||||||
import {InputText} from 'primeng/inputtext';
|
import {InputText} from 'primeng/inputtext';
|
||||||
import {Password} from 'primeng/password';
|
import {Password} from 'primeng/password';
|
||||||
import {User, UserProfileUpdateRequest, UserService} from '../user-management/user.service';
|
import {User, UserProfileUpdateRequest, UserService} from '../user-management/user.service';
|
||||||
import {ToggleSwitch} from 'primeng/toggleswitch';
|
|
||||||
import {MessageService} from 'primeng/api';
|
import {MessageService} from 'primeng/api';
|
||||||
import {DynamicDialogRef} from 'primeng/dynamicdialog';
|
import {DynamicDialogRef} from 'primeng/dynamicdialog';
|
||||||
import {TranslocoDirective, TranslocoPipe, TranslocoService} from '@jsverse/transloco';
|
import {TranslocoDirective, TranslocoPipe, TranslocoService} from '@jsverse/transloco';
|
||||||
import {Select} from 'primeng/select';
|
|
||||||
import {takeUntilDestroyed, toSignal} from '@angular/core/rxjs-interop';
|
|
||||||
import {from, switchMap} from 'rxjs';
|
|
||||||
import {AVAILABLE_LANGS, LANG_LABELS} from '../../../core/config/transloco-loader';
|
|
||||||
import {AppThemeService} from '../../../shared/service/app-theme.service';
|
|
||||||
import {AppLocaleService} from '../../../shared/service/app-locale.service';
|
|
||||||
import {
|
|
||||||
AppearancePreference,
|
|
||||||
AppTheme,
|
|
||||||
CUSTOM_PRIMARY_OPTIONS,
|
|
||||||
CustomPrimary,
|
|
||||||
DEFAULT_APP_THEME,
|
|
||||||
DEFAULT_CUSTOM_PRIMARY,
|
|
||||||
} from '../../../shared/model/app-state.model';
|
|
||||||
|
|
||||||
export const passwordMatchValidator: ValidatorFn = (control: AbstractControl): ValidationErrors | null => {
|
export const passwordMatchValidator: ValidatorFn = (control: AbstractControl): ValidationErrors | null => {
|
||||||
const newPassword = control.get('newPassword');
|
const newPassword = control.get('newPassword');
|
||||||
@@ -42,8 +27,6 @@ export const passwordMatchValidator: ValidatorFn = (control: AbstractControl): V
|
|||||||
ReactiveFormsModule,
|
ReactiveFormsModule,
|
||||||
InputText,
|
InputText,
|
||||||
Password,
|
Password,
|
||||||
Select,
|
|
||||||
ToggleSwitch,
|
|
||||||
TranslocoDirective,
|
TranslocoDirective,
|
||||||
TranslocoPipe,
|
TranslocoPipe,
|
||||||
],
|
],
|
||||||
@@ -56,44 +39,12 @@ export class UserProfileDialogComponent {
|
|||||||
currentUser: User | null = null;
|
currentUser: User | null = null;
|
||||||
editUserData: Partial<User> = {};
|
editUserData: Partial<User> = {};
|
||||||
changePasswordForm: FormGroup;
|
changePasswordForm: FormGroup;
|
||||||
readonly languageOptions = AVAILABLE_LANGS.map(value => ({
|
|
||||||
value,
|
|
||||||
label: LANG_LABELS[value] ?? value,
|
|
||||||
}));
|
|
||||||
|
|
||||||
protected readonly userService = inject(UserService);
|
protected readonly userService = inject(UserService);
|
||||||
protected readonly themeService = inject(AppThemeService);
|
|
||||||
protected readonly appLocaleService = inject(AppLocaleService);
|
|
||||||
private readonly messageService = inject(MessageService);
|
private readonly messageService = inject(MessageService);
|
||||||
private readonly fb = inject(FormBuilder);
|
private readonly fb = inject(FormBuilder);
|
||||||
private readonly dialogRef = inject(DynamicDialogRef);
|
private readonly dialogRef = inject(DynamicDialogRef);
|
||||||
private readonly t = inject(TranslocoService);
|
private readonly t = inject(TranslocoService);
|
||||||
private readonly destroyRef = inject(DestroyRef);
|
|
||||||
protected readonly activeLang = toSignal(this.t.langChanges$, {initialValue: this.t.getActiveLang()});
|
|
||||||
protected readonly selectedThemePreference = computed(() => this.themeService.appState().themePreference ?? DEFAULT_APP_THEME);
|
|
||||||
protected readonly selectedAppearancePreference = computed(() => this.themeService.appState().appearancePreference ?? 'system');
|
|
||||||
protected readonly oledDarkMode = computed(() => this.themeService.appState().oledDarkMode);
|
|
||||||
protected readonly showOledDarkModeToggle = computed(() => this.themeService.effectiveAppearance() === 'dark');
|
|
||||||
protected readonly selectedCustomPrimary = computed<CustomPrimary>(
|
|
||||||
() => this.themeService.appState().customPrimary ?? DEFAULT_CUSTOM_PRIMARY,
|
|
||||||
);
|
|
||||||
protected readonly selectedThemeSyncEnabled = computed(() => this.themeService.appState().themeSyncEnabled !== false);
|
|
||||||
protected readonly customPrimaryOptions = CUSTOM_PRIMARY_OPTIONS;
|
|
||||||
protected readonly themeOptions = computed(() => {
|
|
||||||
this.activeLang();
|
|
||||||
return this.themeService.themes.map((theme) => ({
|
|
||||||
value: theme.name,
|
|
||||||
label: this.t.translate(theme.labelKey),
|
|
||||||
}));
|
|
||||||
});
|
|
||||||
protected readonly appearanceOptions = computed(() => {
|
|
||||||
this.activeLang();
|
|
||||||
return [
|
|
||||||
{value: 'light' as AppearancePreference, label: this.t.translate('layout.theme.light')},
|
|
||||||
{value: 'dark' as AppearancePreference, label: this.t.translate('layout.theme.dark')},
|
|
||||||
{value: 'system' as AppearancePreference, label: this.t.translate('layout.theme.system')},
|
|
||||||
];
|
|
||||||
});
|
|
||||||
|
|
||||||
constructor() {
|
constructor() {
|
||||||
this.changePasswordForm = this.fb.group(
|
this.changePasswordForm = this.fb.group(
|
||||||
@@ -131,76 +82,6 @@ export class UserProfileDialogComponent {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
onLanguageChange(lang: string): void {
|
|
||||||
if (lang === this.activeLang()) return;
|
|
||||||
if (!this.currentUser) return;
|
|
||||||
|
|
||||||
this.userService.updateUserProfile(this.currentUser.id, {locale: lang}).pipe(
|
|
||||||
switchMap(user => from(this.appLocaleService.applyLocale(user.locale))),
|
|
||||||
takeUntilDestroyed(this.destroyRef),
|
|
||||||
).subscribe();
|
|
||||||
}
|
|
||||||
|
|
||||||
updateThemePreference(themePreference: AppTheme): void {
|
|
||||||
if (!this.currentUser) return;
|
|
||||||
|
|
||||||
if (!this.selectedThemeSyncEnabled()) {
|
|
||||||
this.themeService.applyDeviceTheme(themePreference, this.selectedCustomPrimary());
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
const updateRequest: UserProfileUpdateRequest = {
|
|
||||||
theme: themePreference,
|
|
||||||
...(themePreference === 'custom' ? {themeAccent: this.selectedCustomPrimary()} : {}),
|
|
||||||
};
|
|
||||||
|
|
||||||
this.userService.updateUserProfile(this.currentUser.id, updateRequest).pipe(takeUntilDestroyed(this.destroyRef)).subscribe({
|
|
||||||
next: (user) => this.themeService.applySyncedTheme(user.theme, user.themeAccent ?? DEFAULT_CUSTOM_PRIMARY),
|
|
||||||
});
|
|
||||||
}
|
|
||||||
|
|
||||||
updateCustomPrimary(customPrimary: CustomPrimary): void {
|
|
||||||
if (!this.currentUser) return;
|
|
||||||
|
|
||||||
if (!this.selectedThemeSyncEnabled()) {
|
|
||||||
this.themeService.applyDeviceTheme('custom', customPrimary);
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
this.userService.updateUserProfile(this.currentUser.id, {theme: 'custom', themeAccent: customPrimary}).pipe(takeUntilDestroyed(this.destroyRef)).subscribe({
|
|
||||||
next: (user) => this.themeService.applySyncedTheme(user.theme, user.themeAccent ?? DEFAULT_CUSTOM_PRIMARY),
|
|
||||||
});
|
|
||||||
}
|
|
||||||
|
|
||||||
updateThemeSyncEnabled(themeSyncEnabled: boolean): void {
|
|
||||||
if (!this.currentUser) return;
|
|
||||||
|
|
||||||
if (!themeSyncEnabled) {
|
|
||||||
this.userService.updateUserProfile(this.currentUser.id, {themeSyncEnabled: false}).pipe(takeUntilDestroyed(this.destroyRef)).subscribe({
|
|
||||||
next: () => this.themeService.applyDeviceTheme(this.selectedThemePreference(), this.selectedCustomPrimary()),
|
|
||||||
});
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
const theme = this.selectedThemePreference();
|
|
||||||
const updateRequest: UserProfileUpdateRequest = {
|
|
||||||
themeSyncEnabled: true,
|
|
||||||
theme,
|
|
||||||
...(theme === 'custom' ? {themeAccent: this.selectedCustomPrimary()} : {}),
|
|
||||||
};
|
|
||||||
this.userService.updateUserProfile(this.currentUser.id, updateRequest).pipe(takeUntilDestroyed(this.destroyRef)).subscribe({
|
|
||||||
next: (user) => this.themeService.applySyncedTheme(user.theme, user.themeAccent ?? DEFAULT_CUSTOM_PRIMARY),
|
|
||||||
});
|
|
||||||
}
|
|
||||||
|
|
||||||
updateAppearancePreference(appearancePreference: AppearancePreference): void {
|
|
||||||
this.themeService.setAppearancePreference(appearancePreference);
|
|
||||||
}
|
|
||||||
|
|
||||||
updateOledDarkMode(oledDarkMode: boolean): void {
|
|
||||||
this.themeService.setOledDarkMode(oledDarkMode);
|
|
||||||
}
|
|
||||||
|
|
||||||
updateProfile(): void {
|
updateProfile(): void {
|
||||||
if (!this.currentUser) {
|
if (!this.currentUser) {
|
||||||
this.messageService.add({
|
this.messageService.add({
|
||||||
|
|||||||
+131
@@ -0,0 +1,131 @@
|
|||||||
|
<ng-container *transloco="let t; prefix: 'settingsView'">
|
||||||
|
<div class="flex flex-col gap-5 rounded-lg border border-border bg-card p-6 max-md:gap-4 max-md:p-4">
|
||||||
|
<div class="mb-1">
|
||||||
|
<h3 class="m-0 mb-2 flex items-center gap-2 text-xl font-semibold text-text">
|
||||||
|
<i class="pi pi-palette text-lg text-primary" aria-hidden="true"></i>
|
||||||
|
{{ t('theme.sectionTitle') }}
|
||||||
|
</h3>
|
||||||
|
<p class="m-0 text-sm leading-6 text-text-secondary">{{ t('theme.sectionDesc') }}</p>
|
||||||
|
</div>
|
||||||
|
|
||||||
|
<div class="flex flex-col gap-4 pl-4 max-md:pl-2">
|
||||||
|
<section class="w-full max-w-3xl rounded-md border-l-[3px] border-l-primary bg-[color-mix(in_srgb,var(--color-card)_35%,var(--color-page))] p-4 transition-[background,border-color] duration-200 hover:bg-[color-mix(in_srgb,var(--color-card)_20%,var(--color-page))] max-md:p-3">
|
||||||
|
<div class="mb-1">
|
||||||
|
<label class="text-[0.9375rem] font-medium text-text" for="appearance-preference">{{ 'layout.theme.appearance' | transloco }}</label>
|
||||||
|
</div>
|
||||||
|
<div class="mt-3 border-t border-dashed border-border pt-3">
|
||||||
|
<p-select
|
||||||
|
inputId="appearance-preference"
|
||||||
|
[options]="appearanceOptions()"
|
||||||
|
[ngModel]="selectedAppearancePreference()"
|
||||||
|
(ngModelChange)="updateAppearancePreference($event)"
|
||||||
|
optionLabel="label"
|
||||||
|
optionValue="value"
|
||||||
|
appendTo="body"
|
||||||
|
class="w-80 max-w-full">
|
||||||
|
</p-select>
|
||||||
|
</div>
|
||||||
|
|
||||||
|
@if (showOledDarkModeToggle()) {
|
||||||
|
<div class="mt-4 flex max-w-xl items-center gap-3 border-t border-dashed border-border pt-3">
|
||||||
|
<p-toggleswitch
|
||||||
|
inputId="oled-dark-mode"
|
||||||
|
[ngModel]="oledDarkMode()"
|
||||||
|
(ngModelChange)="updateOledDarkMode($event)">
|
||||||
|
</p-toggleswitch>
|
||||||
|
<label class="text-[0.9375rem] font-medium text-text" for="oled-dark-mode">{{ t('theme.oledDarkMode') }}</label>
|
||||||
|
</div>
|
||||||
|
}
|
||||||
|
</section>
|
||||||
|
|
||||||
|
<section class="w-full max-w-3xl rounded-md border-l-[3px] border-l-primary bg-[color-mix(in_srgb,var(--color-card)_35%,var(--color-page))] p-4 transition-[background,border-color] duration-200 hover:bg-[color-mix(in_srgb,var(--color-card)_20%,var(--color-page))] max-md:p-3">
|
||||||
|
<div class="mb-1">
|
||||||
|
<label class="text-[0.9375rem] font-medium text-text" for="app-theme">{{ 'layout.theme.theme' | transloco }}</label>
|
||||||
|
</div>
|
||||||
|
<div class="mt-3 border-t border-dashed border-border pt-3">
|
||||||
|
<p-select
|
||||||
|
inputId="app-theme"
|
||||||
|
[options]="themeOptions()"
|
||||||
|
[ngModel]="selectedThemePreference()"
|
||||||
|
(ngModelChange)="updateThemePreference($event)"
|
||||||
|
optionLabel="label"
|
||||||
|
optionValue="value"
|
||||||
|
appendTo="body"
|
||||||
|
class="w-80 max-w-full">
|
||||||
|
<ng-template #selectedItem let-option>
|
||||||
|
@if (option) {
|
||||||
|
<span class="inline-flex min-w-0 items-center gap-2.5">
|
||||||
|
@if (option.value !== 'custom') {
|
||||||
|
<span
|
||||||
|
class="h-3.5 w-3.5 shrink-0 rounded-full bg-(--color-primary-500) ring-1 ring-inset ring-black/15"
|
||||||
|
[attr.data-app-theme]="option.value"
|
||||||
|
aria-hidden="true">
|
||||||
|
</span>
|
||||||
|
}
|
||||||
|
<span>{{ option.label }}</span>
|
||||||
|
</span>
|
||||||
|
}
|
||||||
|
</ng-template>
|
||||||
|
<ng-template #item let-option>
|
||||||
|
<span class="inline-flex min-w-0 items-center gap-2.5">
|
||||||
|
@if (option.value !== 'custom') {
|
||||||
|
<span
|
||||||
|
class="h-3.5 w-3.5 shrink-0 rounded-full bg-(--color-primary-500) ring-1 ring-inset ring-black/15"
|
||||||
|
[attr.data-app-theme]="option.value"
|
||||||
|
aria-hidden="true">
|
||||||
|
</span>
|
||||||
|
}
|
||||||
|
<span>{{ option.label }}</span>
|
||||||
|
</span>
|
||||||
|
</ng-template>
|
||||||
|
</p-select>
|
||||||
|
</div>
|
||||||
|
|
||||||
|
@if (selectedThemePreference() === 'custom') {
|
||||||
|
<div class="mt-4 max-w-xl">
|
||||||
|
<div class="flex flex-wrap gap-2">
|
||||||
|
@for (option of customPrimaryOptions(); track option.value) {
|
||||||
|
<button
|
||||||
|
type="button"
|
||||||
|
class="size-7 cursor-pointer rounded-full border-0 p-0 shadow-[inset_0_0_0_1px_rgb(0_0_0_/_10%)] aria-pressed:ring-2 aria-pressed:ring-[var(--color-text)] aria-pressed:ring-offset-2 aria-pressed:ring-offset-[var(--color-page)] focus-visible:outline-2 focus-visible:outline-offset-2 focus-visible:outline-primary"
|
||||||
|
[style.background]="'var(--color-' + option.value + '-500)'"
|
||||||
|
[attr.aria-label]="option.ariaLabel"
|
||||||
|
[attr.aria-pressed]="option.value === selectedCustomPrimary()"
|
||||||
|
(click)="updateCustomPrimary(option.value)">
|
||||||
|
</button>
|
||||||
|
}
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
}
|
||||||
|
|
||||||
|
<div class="mt-4 flex max-w-xl items-center gap-3 border-t border-dashed border-border pt-3">
|
||||||
|
<p-toggleswitch
|
||||||
|
inputId="theme-sync"
|
||||||
|
[ngModel]="selectedThemeSyncEnabled()"
|
||||||
|
(ngModelChange)="updateThemeSyncEnabled($event)">
|
||||||
|
</p-toggleswitch>
|
||||||
|
<label class="text-[0.9375rem] font-medium text-text" for="theme-sync">{{ 'layout.theme.syncAcrossDevices' | transloco }}</label>
|
||||||
|
</div>
|
||||||
|
</section>
|
||||||
|
|
||||||
|
<section class="w-full max-w-3xl rounded-md border-l-[3px] border-l-primary bg-[color-mix(in_srgb,var(--color-card)_35%,var(--color-page))] p-4 transition-[background,border-color] duration-200 hover:bg-[color-mix(in_srgb,var(--color-card)_20%,var(--color-page))] max-md:p-3">
|
||||||
|
<div class="mb-1">
|
||||||
|
<label class="text-[0.9375rem] font-medium text-text" for="interface-language">{{ t('language.label') }}</label>
|
||||||
|
</div>
|
||||||
|
<div class="mt-3 border-t border-dashed border-border pt-3">
|
||||||
|
<p-select
|
||||||
|
inputId="interface-language"
|
||||||
|
[options]="languageOptions"
|
||||||
|
[ngModel]="activeLang()"
|
||||||
|
(ngModelChange)="onLanguageChange($event)"
|
||||||
|
optionLabel="label"
|
||||||
|
optionValue="value"
|
||||||
|
appendTo="body"
|
||||||
|
class="w-80 max-w-full">
|
||||||
|
</p-select>
|
||||||
|
</div>
|
||||||
|
</section>
|
||||||
|
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
</ng-container>
|
||||||
+173
@@ -0,0 +1,173 @@
|
|||||||
|
import {ChangeDetectionStrategy, Component, computed, inject} from '@angular/core';
|
||||||
|
import {FormsModule} from '@angular/forms';
|
||||||
|
import {toSignal} from '@angular/core/rxjs-interop';
|
||||||
|
import {Select} from 'primeng/select';
|
||||||
|
import {ToggleSwitch} from 'primeng/toggleswitch';
|
||||||
|
import {MessageService} from 'primeng/api';
|
||||||
|
import {TranslocoDirective, TranslocoPipe, TranslocoService} from '@jsverse/transloco';
|
||||||
|
|
||||||
|
import {AVAILABLE_LANGS, LANG_LABELS} from '../../../../core/config/transloco-loader';
|
||||||
|
import {AppLocaleService} from '../../../../shared/service/app-locale.service';
|
||||||
|
import {AppThemeService} from '../../../../shared/service/app-theme.service';
|
||||||
|
import {
|
||||||
|
CUSTOM_PRIMARY_OPTIONS,
|
||||||
|
DEFAULT_CUSTOM_PRIMARY,
|
||||||
|
} from '../../../../shared/model/app-state.model';
|
||||||
|
import type {AppearancePreference, AppTheme, CustomPrimary} from '../../../../shared/model/app-state.model';
|
||||||
|
import {APPEARANCE_OPTIONS} from '../../../../shared/layout/theme/appearance-options';
|
||||||
|
import {UserService} from '../../user-management/user.service';
|
||||||
|
import type {User, UserProfileUpdateRequest} from '../../user-management/user.service';
|
||||||
|
|
||||||
|
@Component({
|
||||||
|
selector: 'app-display-preferences',
|
||||||
|
standalone: true,
|
||||||
|
imports: [
|
||||||
|
FormsModule,
|
||||||
|
Select,
|
||||||
|
ToggleSwitch,
|
||||||
|
TranslocoDirective,
|
||||||
|
TranslocoPipe,
|
||||||
|
],
|
||||||
|
templateUrl: './display-preferences.component.html',
|
||||||
|
changeDetection: ChangeDetectionStrategy.OnPush,
|
||||||
|
})
|
||||||
|
export class DisplayPreferencesComponent {
|
||||||
|
private readonly themeService = inject(AppThemeService);
|
||||||
|
private readonly localeService = inject(AppLocaleService);
|
||||||
|
private readonly userService = inject(UserService);
|
||||||
|
private readonly messageService = inject(MessageService);
|
||||||
|
private readonly t = inject(TranslocoService);
|
||||||
|
|
||||||
|
protected readonly activeLang = toSignal(this.t.langChanges$, {initialValue: this.t.getActiveLang()});
|
||||||
|
protected readonly appearanceOptions = computed(() => {
|
||||||
|
const activeLang = this.activeLang();
|
||||||
|
return APPEARANCE_OPTIONS.map((option) => ({
|
||||||
|
value: option.value,
|
||||||
|
label: this.t.translate(option.labelKey, {}, activeLang),
|
||||||
|
}));
|
||||||
|
});
|
||||||
|
protected readonly languageOptions = AVAILABLE_LANGS.map(value => ({
|
||||||
|
value,
|
||||||
|
label: LANG_LABELS[value] ?? value,
|
||||||
|
}));
|
||||||
|
protected readonly selectedAppearancePreference = this.themeService.appearancePreference;
|
||||||
|
protected readonly selectedThemePreference = this.themeService.themePreference;
|
||||||
|
protected readonly oledDarkMode = this.themeService.oledDarkMode;
|
||||||
|
protected readonly showOledDarkModeToggle = computed(() => this.themeService.effectiveAppearance() === 'dark');
|
||||||
|
protected readonly selectedCustomPrimary = this.themeService.customPrimary;
|
||||||
|
protected readonly selectedThemeSyncEnabled = this.themeService.themeSyncEnabled;
|
||||||
|
protected readonly customPrimaryOptions = computed(() => {
|
||||||
|
const activeLang = this.activeLang();
|
||||||
|
return CUSTOM_PRIMARY_OPTIONS.map((value) => {
|
||||||
|
const color = this.t.translate(`settingsView.theme.customPrimaryColors.${value}`, {}, activeLang);
|
||||||
|
return {
|
||||||
|
value,
|
||||||
|
ariaLabel: this.t.translate('settingsView.theme.customPrimaryOptionLabel', {color}, activeLang),
|
||||||
|
};
|
||||||
|
});
|
||||||
|
});
|
||||||
|
protected readonly themeOptions = computed(() => {
|
||||||
|
const activeLang = this.activeLang();
|
||||||
|
return this.themeService.themes.map((theme) => ({
|
||||||
|
value: theme.name,
|
||||||
|
label: this.t.translate(theme.labelKey, {}, activeLang),
|
||||||
|
}));
|
||||||
|
});
|
||||||
|
|
||||||
|
protected async onLanguageChange(lang: string): Promise<void> {
|
||||||
|
if (lang === this.activeLang()) return;
|
||||||
|
|
||||||
|
const updatedUser = await this.updateCurrentUserProfile({locale: lang});
|
||||||
|
if (!updatedUser) return;
|
||||||
|
|
||||||
|
await this.localeService.applyLocale(updatedUser.locale);
|
||||||
|
this.showSavedToast('settingsView.language.savedDetail');
|
||||||
|
}
|
||||||
|
|
||||||
|
protected async updateThemePreference(themePreference: AppTheme): Promise<void> {
|
||||||
|
if (!this.selectedThemeSyncEnabled()) {
|
||||||
|
this.themeService.applyDeviceTheme(themePreference, this.selectedCustomPrimary());
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
const updateRequest: UserProfileUpdateRequest = {
|
||||||
|
theme: themePreference,
|
||||||
|
...(themePreference === 'custom' ? {themeAccent: this.selectedCustomPrimary()} : {}),
|
||||||
|
};
|
||||||
|
|
||||||
|
const updatedUser = await this.updateCurrentUserProfile(updateRequest);
|
||||||
|
if (!updatedUser) return;
|
||||||
|
|
||||||
|
this.applySyncedUserTheme(updatedUser);
|
||||||
|
this.showSavedToast();
|
||||||
|
}
|
||||||
|
|
||||||
|
protected updateAppearancePreference(appearancePreference: AppearancePreference): void {
|
||||||
|
this.themeService.setAppearancePreference(appearancePreference);
|
||||||
|
}
|
||||||
|
|
||||||
|
protected async updateCustomPrimary(customPrimary: CustomPrimary): Promise<void> {
|
||||||
|
if (!this.selectedThemeSyncEnabled()) {
|
||||||
|
this.themeService.applyDeviceTheme('custom', customPrimary);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
const updatedUser = await this.updateCurrentUserProfile({theme: 'custom', themeAccent: customPrimary});
|
||||||
|
if (!updatedUser) return;
|
||||||
|
|
||||||
|
this.applySyncedUserTheme(updatedUser);
|
||||||
|
this.showSavedToast();
|
||||||
|
}
|
||||||
|
|
||||||
|
protected async updateThemeSyncEnabled(themeSyncEnabled: boolean): Promise<void> {
|
||||||
|
if (!themeSyncEnabled) {
|
||||||
|
const updatedUser = await this.updateCurrentUserProfile({themeSyncEnabled: false});
|
||||||
|
if (!updatedUser) return;
|
||||||
|
|
||||||
|
this.themeService.applyDeviceTheme(this.selectedThemePreference(), this.selectedCustomPrimary());
|
||||||
|
this.showSavedToast('settingsView.theme.syncSavedDetail');
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
const theme = this.selectedThemePreference();
|
||||||
|
const updateRequest: UserProfileUpdateRequest = {
|
||||||
|
themeSyncEnabled: true,
|
||||||
|
theme,
|
||||||
|
...(theme === 'custom' ? {themeAccent: this.selectedCustomPrimary()} : {}),
|
||||||
|
};
|
||||||
|
const updatedUser = await this.updateCurrentUserProfile(updateRequest);
|
||||||
|
if (!updatedUser) return;
|
||||||
|
|
||||||
|
this.applySyncedUserTheme(updatedUser);
|
||||||
|
this.showSavedToast('settingsView.theme.syncSavedDetail');
|
||||||
|
}
|
||||||
|
|
||||||
|
protected updateOledDarkMode(oledDarkMode: boolean): void {
|
||||||
|
this.themeService.setOledDarkMode(oledDarkMode);
|
||||||
|
}
|
||||||
|
|
||||||
|
private applySyncedUserTheme(user: User): void {
|
||||||
|
this.themeService.applySyncedTheme(user.theme, user.themeAccent ?? DEFAULT_CUSTOM_PRIMARY);
|
||||||
|
}
|
||||||
|
|
||||||
|
private async updateCurrentUserProfile(updateRequest: UserProfileUpdateRequest): Promise<User | null> {
|
||||||
|
try {
|
||||||
|
return await this.userService.updateCurrentUserProfile(updateRequest);
|
||||||
|
} catch {
|
||||||
|
this.messageService.add({
|
||||||
|
severity: 'error',
|
||||||
|
summary: this.t.translate('common.error'),
|
||||||
|
detail: this.t.translate('settingsView.saveFailedDetail'),
|
||||||
|
});
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
private showSavedToast(detailKey = 'settingsView.theme.savedDetail'): void {
|
||||||
|
this.messageService.add({
|
||||||
|
severity: 'success',
|
||||||
|
summary: this.t.translate('common.success'),
|
||||||
|
detail: this.t.translate(detailKey),
|
||||||
|
});
|
||||||
|
}
|
||||||
|
}
|
||||||
+2
@@ -10,6 +10,8 @@
|
|||||||
</p>
|
</p>
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
|
<app-display-preferences></app-display-preferences>
|
||||||
|
<div class="section-divider"><hr></div>
|
||||||
<app-view-preferences></app-view-preferences>
|
<app-view-preferences></app-view-preferences>
|
||||||
<div class="section-divider"><hr></div>
|
<div class="section-divider"><hr></div>
|
||||||
<app-filter-preferences></app-filter-preferences>
|
<app-filter-preferences></app-filter-preferences>
|
||||||
|
|||||||
+2
@@ -6,6 +6,7 @@ import {ViewPreferencesComponent} from './view-preferences/view-preferences.comp
|
|||||||
import {SidebarSortingPreferencesComponent} from './sidebar-sorting-preferences/sidebar-sorting-preferences.component';
|
import {SidebarSortingPreferencesComponent} from './sidebar-sorting-preferences/sidebar-sorting-preferences.component';
|
||||||
import {MetaCenterViewModeComponent} from './meta-center-view-mode/meta-center-view-mode-component';
|
import {MetaCenterViewModeComponent} from './meta-center-view-mode/meta-center-view-mode-component';
|
||||||
import {FilterPreferencesComponent} from './filter-preferences/filter-preferences.component';
|
import {FilterPreferencesComponent} from './filter-preferences/filter-preferences.component';
|
||||||
|
import {DisplayPreferencesComponent} from './display-preferences/display-preferences.component';
|
||||||
import {TranslocoDirective, TranslocoService} from '@jsverse/transloco';
|
import {TranslocoDirective, TranslocoService} from '@jsverse/transloco';
|
||||||
import {Slider} from 'primeng/slider';
|
import {Slider} from 'primeng/slider';
|
||||||
import {MessageService} from 'primeng/api';
|
import {MessageService} from 'primeng/api';
|
||||||
@@ -21,6 +22,7 @@ import {LayoutService, SIDEBAR_MAX_WIDTH, SIDEBAR_MIN_WIDTH} from '../../../shar
|
|||||||
SidebarSortingPreferencesComponent,
|
SidebarSortingPreferencesComponent,
|
||||||
MetaCenterViewModeComponent,
|
MetaCenterViewModeComponent,
|
||||||
FilterPreferencesComponent,
|
FilterPreferencesComponent,
|
||||||
|
DisplayPreferencesComponent,
|
||||||
TranslocoDirective,
|
TranslocoDirective,
|
||||||
Slider,
|
Slider,
|
||||||
],
|
],
|
||||||
|
|||||||
@@ -52,7 +52,6 @@
|
|||||||
required
|
required
|
||||||
[(ngModel)]="username"
|
[(ngModel)]="username"
|
||||||
[placeholder]="t('usernamePlaceholder')"
|
[placeholder]="t('usernamePlaceholder')"
|
||||||
class="form-input"
|
|
||||||
autocomplete="username"
|
autocomplete="username"
|
||||||
/>
|
/>
|
||||||
</div>
|
</div>
|
||||||
|
|||||||
@@ -91,10 +91,6 @@
|
|||||||
@include auth.form-label;
|
@include auth.form-label;
|
||||||
}
|
}
|
||||||
|
|
||||||
.form-input {
|
|
||||||
@include auth.form-input;
|
|
||||||
}
|
|
||||||
|
|
||||||
.login-button {
|
.login-button {
|
||||||
@include auth.auth-button;
|
@include auth.auth-button;
|
||||||
|
|
||||||
|
|||||||
@@ -404,6 +404,53 @@
|
|||||||
<span>{{ t('readingStats') }}</span>
|
<span>{{ t('readingStats') }}</span>
|
||||||
</button>
|
</button>
|
||||||
}
|
}
|
||||||
|
|
||||||
|
<div class="flex flex-col-reverse">
|
||||||
|
<button
|
||||||
|
type="button"
|
||||||
|
class="menu-item user-account-popover-action"
|
||||||
|
aria-controls="user-account-appearance-menu"
|
||||||
|
[attr.aria-expanded]="appearanceMenuOpen()"
|
||||||
|
(click)="toggleAppearanceMenu()"
|
||||||
|
>
|
||||||
|
<i class="pi pi-palette" aria-hidden="true"></i>
|
||||||
|
<span>{{ 'layout.theme.appearance' | transloco }}</span>
|
||||||
|
<span class="ml-auto mr-2 min-w-0 max-w-[5.5rem] overflow-hidden text-ellipsis whitespace-nowrap text-xs text-text-secondary">{{ selectedAppearanceLabel() }}</span>
|
||||||
|
<i
|
||||||
|
class="pi pi-chevron-down size-3 shrink-0 text-[0.6875rem] text-text-secondary! transition-transform duration-150"
|
||||||
|
[class.rotate-180]="appearanceMenuOpen()"
|
||||||
|
aria-hidden="true">
|
||||||
|
</i>
|
||||||
|
</button>
|
||||||
|
|
||||||
|
<div
|
||||||
|
id="user-account-appearance-menu"
|
||||||
|
class="pointer-events-none grid origin-bottom grid-rows-[0fr] translate-y-1 opacity-0 transition-[grid-template-rows,opacity,transform] duration-150 ease-out data-[open=true]:pointer-events-auto data-[open=true]:mt-1 data-[open=true]:border-t data-[open=true]:border-border data-[open=true]:pt-1 data-[open=true]:grid-rows-[1fr] data-[open=true]:translate-y-0 data-[open=true]:opacity-100 motion-reduce:transition-none"
|
||||||
|
[attr.aria-label]="'layout.theme.appearance' | transloco"
|
||||||
|
[attr.aria-hidden]="!appearanceMenuOpen()"
|
||||||
|
[attr.data-open]="appearanceMenuOpen()"
|
||||||
|
[attr.inert]="appearanceMenuOpen() ? null : ''"
|
||||||
|
>
|
||||||
|
<div class="min-h-0 overflow-hidden">
|
||||||
|
<div class="flex flex-col gap-0.5 pb-1 pl-[calc(var(--control-icon-size)+var(--menu-item-gap))]">
|
||||||
|
@for (option of appearanceOptions; track option.value) {
|
||||||
|
<button
|
||||||
|
type="button"
|
||||||
|
class="menu-item user-account-popover-action aria-pressed:bg-active-surface aria-pressed:text-primary! aria-pressed:[&_.pi]:text-primary!"
|
||||||
|
[attr.aria-pressed]="selectedAppearancePreference() === option.value"
|
||||||
|
(click)="updateAppearancePreference(option.value)"
|
||||||
|
>
|
||||||
|
<i [class]="option.icon" aria-hidden="true"></i>
|
||||||
|
<span>{{ option.labelKey | transloco }}</span>
|
||||||
|
@if (selectedAppearancePreference() === option.value) {
|
||||||
|
<i class="pi pi-check ml-auto text-primary!" aria-hidden="true"></i>
|
||||||
|
}
|
||||||
|
</button>
|
||||||
|
}
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
<footer class="user-account-popover-footer">
|
<footer class="user-account-popover-footer">
|
||||||
|
|||||||
@@ -25,6 +25,8 @@ import { LibraryImportProgressService } from '../../service/library-import-progr
|
|||||||
import { AppVersion, VersionService } from '../../service/version.service';
|
import { AppVersion, VersionService } from '../../service/version.service';
|
||||||
import { DialogLauncherService } from '../../services/dialog-launcher.service';
|
import { DialogLauncherService } from '../../services/dialog-launcher.service';
|
||||||
import { LayoutService } from '../layout.service';
|
import { LayoutService } from '../layout.service';
|
||||||
|
import { AppThemeService } from '../../service/app-theme.service';
|
||||||
|
import type { AppearancePreference } from '../../model/app-state.model';
|
||||||
|
|
||||||
import { AppSidebarComponent } from './app.sidebar.component';
|
import { AppSidebarComponent } from './app.sidebar.component';
|
||||||
|
|
||||||
@@ -44,6 +46,8 @@ describe('AppSidebarComponent', () => {
|
|||||||
let progressUpdates$: BehaviorSubject<MetadataBatchProgressNotification>;
|
let progressUpdates$: BehaviorSubject<MetadataBatchProgressNotification>;
|
||||||
let hasPendingFiles: WritableSignal<boolean>;
|
let hasPendingFiles: WritableSignal<boolean>;
|
||||||
let hasActiveImport: WritableSignal<boolean>;
|
let hasActiveImport: WritableSignal<boolean>;
|
||||||
|
let setAppearancePreference: ReturnType<typeof vi.fn>;
|
||||||
|
let appState: WritableSignal<{ appearancePreference: AppearancePreference }>;
|
||||||
const sidebarCollapsed = signal(false);
|
const sidebarCollapsed = signal(false);
|
||||||
const isDesktop = signal(true);
|
const isDesktop = signal(true);
|
||||||
const currentPath = signal('/dashboard');
|
const currentPath = signal('/dashboard');
|
||||||
@@ -73,6 +77,10 @@ describe('AppSidebarComponent', () => {
|
|||||||
});
|
});
|
||||||
hasPendingFiles = signal(false);
|
hasPendingFiles = signal(false);
|
||||||
hasActiveImport = signal(false);
|
hasActiveImport = signal(false);
|
||||||
|
appState = signal({ appearancePreference: 'system' });
|
||||||
|
setAppearancePreference = vi.fn((appearancePreference: AppearancePreference) => {
|
||||||
|
appState.update(state => ({...state, appearancePreference}));
|
||||||
|
});
|
||||||
|
|
||||||
TestBed.configureTestingModule({
|
TestBed.configureTestingModule({
|
||||||
imports: [AppSidebarComponent, getTranslocoModule()],
|
imports: [AppSidebarComponent, getTranslocoModule()],
|
||||||
@@ -110,6 +118,14 @@ describe('AppSidebarComponent', () => {
|
|||||||
{ provide: SeriesDataService, useValue: { allSeries: signal([]) } },
|
{ provide: SeriesDataService, useValue: { allSeries: signal([]) } },
|
||||||
{ provide: AuthorService, useValue: { allAuthors: signal([]) } },
|
{ provide: AuthorService, useValue: { allAuthors: signal([]) } },
|
||||||
{ provide: MessageService, useValue: { add: vi.fn() } },
|
{ provide: MessageService, useValue: { add: vi.fn() } },
|
||||||
|
{
|
||||||
|
provide: AppThemeService,
|
||||||
|
useValue: {
|
||||||
|
appState,
|
||||||
|
appearancePreference: computed(() => appState().appearancePreference),
|
||||||
|
setAppearancePreference,
|
||||||
|
},
|
||||||
|
},
|
||||||
],
|
],
|
||||||
});
|
});
|
||||||
|
|
||||||
@@ -202,6 +218,21 @@ describe('AppSidebarComponent', () => {
|
|||||||
expect(component.userInitials()).toBe('');
|
expect(component.userInitials()).toBe('');
|
||||||
});
|
});
|
||||||
|
|
||||||
|
it('updates the appearance preference without closing the appearance menu', () => {
|
||||||
|
const sidebar = component as unknown as {
|
||||||
|
appearanceMenuOpen: Signal<boolean>;
|
||||||
|
toggleAppearanceMenu(): void;
|
||||||
|
updateAppearancePreference(appearancePreference: AppearancePreference): void;
|
||||||
|
};
|
||||||
|
|
||||||
|
sidebar.toggleAppearanceMenu();
|
||||||
|
sidebar.updateAppearancePreference('dark');
|
||||||
|
|
||||||
|
expect(setAppearancePreference).toHaveBeenCalledWith('dark');
|
||||||
|
expect(appState().appearancePreference).toBe('dark');
|
||||||
|
expect(sidebar.appearanceMenuOpen()).toBe(true);
|
||||||
|
});
|
||||||
|
|
||||||
it('normalizes semantic version labels with or without a leading v', () => {
|
it('normalizes semantic version labels with or without a leading v', () => {
|
||||||
const sidebar = component as unknown as { appVersionLabel: () => string };
|
const sidebar = component as unknown as { appVersionLabel: () => string };
|
||||||
|
|
||||||
|
|||||||
@@ -38,6 +38,9 @@ import { MetadataProgressService } from '../../service/metadata-progress.service
|
|||||||
import { BookdropFileService } from '../../../features/bookdrop/service/bookdrop-file.service';
|
import { BookdropFileService } from '../../../features/bookdrop/service/bookdrop-file.service';
|
||||||
import { MetadataBatchStatus } from '../../model/metadata-batch-progress.model';
|
import { MetadataBatchStatus } from '../../model/metadata-batch-progress.model';
|
||||||
import { LibraryImportProgressService } from '../../service/library-import-progress.service';
|
import { LibraryImportProgressService } from '../../service/library-import-progress.service';
|
||||||
|
import { AppThemeService } from '../../service/app-theme.service';
|
||||||
|
import type { AppearancePreference } from '../../model/app-state.model';
|
||||||
|
import { APPEARANCE_OPTIONS } from '../theme/appearance-options';
|
||||||
|
|
||||||
const DOCUMENTATION_URL = 'https://grimmory.org/docs/getting-started';
|
const DOCUMENTATION_URL = 'https://grimmory.org/docs/getting-started';
|
||||||
const ABOVE_ALIGN_LEFT: ConnectedPosition[] = [
|
const ABOVE_ALIGN_LEFT: ConnectedPosition[] = [
|
||||||
@@ -140,6 +143,7 @@ export class AppSidebarComponent {
|
|||||||
private readonly metadataProgressService = inject(MetadataProgressService);
|
private readonly metadataProgressService = inject(MetadataProgressService);
|
||||||
private readonly bookdropFileService = inject(BookdropFileService);
|
private readonly bookdropFileService = inject(BookdropFileService);
|
||||||
private readonly libraryImportProgressService = inject(LibraryImportProgressService);
|
private readonly libraryImportProgressService = inject(LibraryImportProgressService);
|
||||||
|
private readonly themeService = inject(AppThemeService);
|
||||||
|
|
||||||
readonly currentUser = this.userService.currentUser;
|
readonly currentUser = this.userService.currentUser;
|
||||||
private readonly allAuthors = this.authorService.allAuthors;
|
private readonly allAuthors = this.authorService.allAuthors;
|
||||||
@@ -155,6 +159,14 @@ export class AppSidebarComponent {
|
|||||||
private readonly translate = (key: string): string => this.t.translate(key);
|
private readonly translate = (key: string): string => this.t.translate(key);
|
||||||
protected readonly userPopoverOpen = signal(false);
|
protected readonly userPopoverOpen = signal(false);
|
||||||
protected readonly userPopoverOrigin = signal<CdkOverlayOrigin | null>(null);
|
protected readonly userPopoverOrigin = signal<CdkOverlayOrigin | null>(null);
|
||||||
|
protected readonly appearanceMenuOpen = signal(false);
|
||||||
|
protected readonly appearanceOptions = APPEARANCE_OPTIONS;
|
||||||
|
protected readonly selectedAppearancePreference = this.themeService.appearancePreference;
|
||||||
|
protected readonly selectedAppearanceLabel = computed(() => {
|
||||||
|
this.activeLang();
|
||||||
|
const selectedOption = APPEARANCE_OPTIONS.find(option => option.value === this.selectedAppearancePreference());
|
||||||
|
return selectedOption ? this.translate(selectedOption.labelKey) : '';
|
||||||
|
});
|
||||||
protected readonly canAccessReadingStats = computed(() => {
|
protected readonly canAccessReadingStats = computed(() => {
|
||||||
const user = this.currentUser();
|
const user = this.currentUser();
|
||||||
return !!user && (user.permissions.admin || user.permissions.canAccessUserStats);
|
return !!user && (user.permissions.admin || user.permissions.canAccessUserStats);
|
||||||
@@ -267,6 +279,15 @@ export class AppSidebarComponent {
|
|||||||
|
|
||||||
protected closeUserPopover(): void {
|
protected closeUserPopover(): void {
|
||||||
this.userPopoverOpen.set(false);
|
this.userPopoverOpen.set(false);
|
||||||
|
this.appearanceMenuOpen.set(false);
|
||||||
|
}
|
||||||
|
|
||||||
|
protected toggleAppearanceMenu(): void {
|
||||||
|
this.appearanceMenuOpen.update(open => !open);
|
||||||
|
}
|
||||||
|
|
||||||
|
protected updateAppearancePreference(appearancePreference: AppearancePreference): void {
|
||||||
|
this.themeService.setAppearancePreference(appearancePreference);
|
||||||
}
|
}
|
||||||
|
|
||||||
protected openDocumentation(): void {
|
protected openDocumentation(): void {
|
||||||
|
|||||||
@@ -0,0 +1,13 @@
|
|||||||
|
import type {AppearancePreference} from '../../model/app-state.model';
|
||||||
|
|
||||||
|
export interface AppearanceOption {
|
||||||
|
value: AppearancePreference;
|
||||||
|
labelKey: string;
|
||||||
|
icon: string;
|
||||||
|
}
|
||||||
|
|
||||||
|
export const APPEARANCE_OPTIONS: readonly AppearanceOption[] = [
|
||||||
|
{value: 'light', labelKey: 'layout.theme.light', icon: 'pi pi-sun'},
|
||||||
|
{value: 'dark', labelKey: 'layout.theme.dark', icon: 'pi pi-moon'},
|
||||||
|
{value: 'system', labelKey: 'layout.theme.system', icon: 'pi pi-desktop'},
|
||||||
|
];
|
||||||
@@ -31,6 +31,14 @@ interface AppThemeColorScheme {
|
|||||||
|
|
||||||
interface AppThemePresetComponents {
|
interface AppThemePresetComponents {
|
||||||
components?: {
|
components?: {
|
||||||
|
inputtext?: {
|
||||||
|
root?: {
|
||||||
|
focusBorderColor?: string;
|
||||||
|
focusRing?: {
|
||||||
|
shadow?: string;
|
||||||
|
};
|
||||||
|
};
|
||||||
|
};
|
||||||
button?: {
|
button?: {
|
||||||
colorScheme?: {
|
colorScheme?: {
|
||||||
light?: {
|
light?: {
|
||||||
@@ -49,6 +57,13 @@ describe('theme-palette-extend', () => {
|
|||||||
expect(preset.semantic?.colorScheme?.dark?.content?.background).toBe('var(--color-page)');
|
expect(preset.semantic?.colorScheme?.dark?.content?.background).toBe('var(--color-page)');
|
||||||
});
|
});
|
||||||
|
|
||||||
|
it('bridges Prime input focus styles to app control tokens', () => {
|
||||||
|
const inputtext = (ExtendedAura as AppThemePresetComponents).components?.inputtext?.root;
|
||||||
|
|
||||||
|
expect(inputtext?.focusBorderColor).toBe('var(--control-focus-border)');
|
||||||
|
expect(inputtext?.focusRing?.shadow).toBe('none');
|
||||||
|
});
|
||||||
|
|
||||||
it('uses balanced light outlined button tokens', () => {
|
it('uses balanced light outlined button tokens', () => {
|
||||||
const outlined = (ExtendedAura as AppThemePreset & AppThemePresetComponents)
|
const outlined = (ExtendedAura as AppThemePreset & AppThemePresetComponents)
|
||||||
.components?.button?.colorScheme?.light?.outlined;
|
.components?.button?.colorScheme?.light?.outlined;
|
||||||
|
|||||||
@@ -51,6 +51,17 @@ const appHighlight = {
|
|||||||
focusColor: 'var(--color-primary-text)',
|
focusColor: 'var(--color-primary-text)',
|
||||||
};
|
};
|
||||||
|
|
||||||
|
const appInputText = {
|
||||||
|
focusBorderColor: 'var(--control-focus-border)',
|
||||||
|
focusRing: {
|
||||||
|
width: '0',
|
||||||
|
style: 'none',
|
||||||
|
color: 'transparent',
|
||||||
|
offset: '0',
|
||||||
|
shadow: 'none',
|
||||||
|
},
|
||||||
|
};
|
||||||
|
|
||||||
const contentSurface = {
|
const contentSurface = {
|
||||||
background: 'var(--color-page)',
|
background: 'var(--color-page)',
|
||||||
borderColor: 'var(--color-border)',
|
borderColor: 'var(--color-border)',
|
||||||
@@ -126,6 +137,7 @@ const AppPrimePreset = definePreset(Aura, {
|
|||||||
tieredmenu: { root: menuRoot },
|
tieredmenu: { root: menuRoot },
|
||||||
contextmenu: { root: menuRoot },
|
contextmenu: { root: menuRoot },
|
||||||
menubar: { submenu: menuRoot },
|
menubar: { submenu: menuRoot },
|
||||||
|
inputtext: { root: appInputText },
|
||||||
button: {
|
button: {
|
||||||
colorScheme: {
|
colorScheme: {
|
||||||
light: { outlined: lightOutlinedButton },
|
light: { outlined: lightOutlinedButton },
|
||||||
|
|||||||
@@ -1,5 +1,5 @@
|
|||||||
import { DOCUMENT, isPlatformBrowser } from '@angular/common';
|
import { DOCUMENT, isPlatformBrowser } from '@angular/common';
|
||||||
import { inject, Injectable, PLATFORM_ID, signal } from '@angular/core';
|
import { computed, inject, Injectable, PLATFORM_ID, signal } from '@angular/core';
|
||||||
import { FaviconService } from '../layout/theme/favicon-service';
|
import { FaviconService } from '../layout/theme/favicon-service';
|
||||||
import {applyPrimeTheme, primeThemeTokenPalettes} from '../layout/theme/theme-palette-extend';
|
import {applyPrimeTheme, primeThemeTokenPalettes} from '../layout/theme/theme-palette-extend';
|
||||||
import {
|
import {
|
||||||
@@ -38,6 +38,11 @@ export class AppThemeService {
|
|||||||
private readonly appStateSignal = signal<AppState>(this.withDefaults({}));
|
private readonly appStateSignal = signal<AppState>(this.withDefaults({}));
|
||||||
private readonly effectiveAppearanceSignal = signal<'light' | 'dark'>('dark');
|
private readonly effectiveAppearanceSignal = signal<'light' | 'dark'>('dark');
|
||||||
readonly appState = this.appStateSignal.asReadonly();
|
readonly appState = this.appStateSignal.asReadonly();
|
||||||
|
readonly themePreference = computed(() => this.appStateSignal().themePreference ?? DEFAULT_APP_THEME);
|
||||||
|
readonly appearancePreference = computed(() => this.appStateSignal().appearancePreference ?? DEFAULT_APPEARANCE_PREFERENCE);
|
||||||
|
readonly customPrimary = computed(() => this.appStateSignal().customPrimary ?? DEFAULT_CUSTOM_PRIMARY);
|
||||||
|
readonly themeSyncEnabled = computed(() => this.appStateSignal().themeSyncEnabled !== false);
|
||||||
|
readonly oledDarkMode = computed(() => this.appStateSignal().oledDarkMode);
|
||||||
readonly effectiveAppearance = this.effectiveAppearanceSignal.asReadonly();
|
readonly effectiveAppearance = this.effectiveAppearanceSignal.asReadonly();
|
||||||
document = inject(DOCUMENT);
|
document = inject(DOCUMENT);
|
||||||
platformId = inject(PLATFORM_ID);
|
platformId = inject(PLATFORM_ID);
|
||||||
|
|||||||
@@ -1,15 +1,37 @@
|
|||||||
{
|
{
|
||||||
"title": "View Preferences",
|
"title": "View Preferences",
|
||||||
"description": "Customize how books are displayed in your library, including grid layout, sorting options, and sidebar behavior.",
|
"description": "Customize how books are displayed in your library, including grid layout, sorting options, and sidebar behavior.",
|
||||||
|
"saveFailedDetail": "Unable to save your display preferences. Please try again.",
|
||||||
"language": {
|
"language": {
|
||||||
"sectionTitle": "Language",
|
"label": "Interface language",
|
||||||
"sectionDesc": "Choose the language used throughout the interface in this browser.",
|
"savedDetail": "Your language preference has been saved."
|
||||||
"label": "Interface language"
|
|
||||||
},
|
},
|
||||||
"theme": {
|
"theme": {
|
||||||
"sectionTitle": "Display",
|
"sectionTitle": "Display",
|
||||||
"sectionDesc": "Pick your preferred app theme and appearance mode for this browser.",
|
"sectionDesc": "Pick your preferred app theme and appearance mode for this user.",
|
||||||
"oledDarkMode": "OLED dark mode"
|
"oledDarkMode": "OLED dark mode",
|
||||||
|
"savedDetail": "Your display preferences have been saved.",
|
||||||
|
"syncSavedDetail": "Your theme sync preference has been saved.",
|
||||||
|
"customPrimaryOptionLabel": "{{color}} custom color",
|
||||||
|
"customPrimaryColors": {
|
||||||
|
"red": "Red",
|
||||||
|
"orange": "Orange",
|
||||||
|
"amber": "Amber",
|
||||||
|
"yellow": "Yellow",
|
||||||
|
"lime": "Lime",
|
||||||
|
"green": "Green",
|
||||||
|
"emerald": "Emerald",
|
||||||
|
"teal": "Teal",
|
||||||
|
"cyan": "Cyan",
|
||||||
|
"sky": "Sky",
|
||||||
|
"blue": "Blue",
|
||||||
|
"indigo": "Indigo",
|
||||||
|
"violet": "Violet",
|
||||||
|
"purple": "Purple",
|
||||||
|
"fuchsia": "Fuchsia",
|
||||||
|
"pink": "Pink",
|
||||||
|
"rose": "Rose"
|
||||||
|
}
|
||||||
},
|
},
|
||||||
"librarySort": {
|
"librarySort": {
|
||||||
"sectionTitle": "Library and Shelf View & Sort Preferences",
|
"sectionTitle": "Library and Shelf View & Sort Preferences",
|
||||||
|
|||||||
Reference in New Issue
Block a user