diff --git a/frontend/src/app/features/settings/user-management/user.service.ts b/frontend/src/app/features/settings/user-management/user.service.ts index aa40f5980..19b5b18f3 100644 --- a/frontend/src/app/features/settings/user-management/user.service.ts +++ b/frontend/src/app/features/settings/user-management/user.service.ts @@ -471,6 +471,13 @@ export class UserService { ); } + async updateCurrentUserProfile(updateData: UserProfileUpdateRequest): Promise { + const user = this.currentUser(); + if (!user) return null; + + return lastValueFrom(this.updateUserProfile(user.id, updateData)); + } + deleteUser(userId: number): Observable { return this.http.delete(`${this.userUrl}/${userId}`); } diff --git a/frontend/src/app/features/settings/user-profile-dialog/user-profile-dialog.component.html b/frontend/src/app/features/settings/user-profile-dialog/user-profile-dialog.component.html index d07ca084d..d9d7bc1ab 100644 --- a/frontend/src/app/features/settings/user-profile-dialog/user-profile-dialog.component.html +++ b/frontend/src/app/features/settings/user-profile-dialog/user-profile-dialog.component.html @@ -22,128 +22,6 @@
-
-

- - {{ 'settingsView.theme.sectionTitle' | transloco }} -

- -
- - - -
- - @if (showOledDarkModeToggle()) { -
- - - -
- } - -
- - - - @if (option) { - - @if (option.value !== 'custom') { - - } - {{ option.label }} - - } - - - - @if (option.value !== 'custom') { - - } - {{ option.label }} - - - -
- -
- - - -
- - @if (selectedThemePreference() === 'custom') { -
- {{ 'layout.theme.customPrimary' | transloco }} -
-
- @for (palette of customPrimaryOptions; track palette) { - - } -
-
-
- } -
- -
- -
-

- - {{ 'settingsView.language.sectionTitle' | transloco }} -

- - - -
- -
-

diff --git a/frontend/src/app/features/settings/user-profile-dialog/user-profile-dialog.component.scss b/frontend/src/app/features/settings/user-profile-dialog/user-profile-dialog.component.scss index 2ea8e48cf..6dac9aeae 100644 --- a/frontend/src/app/features/settings/user-profile-dialog/user-profile-dialog.component.scss +++ b/frontend/src/app/features/settings/user-profile-dialog/user-profile-dialog.component.scss @@ -67,14 +67,6 @@ } } -.preferences-section { - gap: 1rem; -} - -.preference-select { - width: 100%; -} - .form-field { display: flex; 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 { margin-top: 0.5rem; diff --git a/frontend/src/app/features/settings/user-profile-dialog/user-profile-dialog.component.ts b/frontend/src/app/features/settings/user-profile-dialog/user-profile-dialog.component.ts index af7c600fd..3035b6588 100644 --- a/frontend/src/app/features/settings/user-profile-dialog/user-profile-dialog.component.ts +++ b/frontend/src/app/features/settings/user-profile-dialog/user-profile-dialog.component.ts @@ -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 {AbstractControl, FormBuilder, FormGroup, FormsModule, ReactiveFormsModule, ValidationErrors, ValidatorFn, Validators} from '@angular/forms'; import {InputText} from 'primeng/inputtext'; import {Password} from 'primeng/password'; import {User, UserProfileUpdateRequest, UserService} from '../user-management/user.service'; -import {ToggleSwitch} from 'primeng/toggleswitch'; import {MessageService} from 'primeng/api'; import {DynamicDialogRef} from 'primeng/dynamicdialog'; 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 => { const newPassword = control.get('newPassword'); @@ -42,8 +27,6 @@ export const passwordMatchValidator: ValidatorFn = (control: AbstractControl): V ReactiveFormsModule, InputText, Password, - Select, - ToggleSwitch, TranslocoDirective, TranslocoPipe, ], @@ -56,44 +39,12 @@ export class UserProfileDialogComponent { currentUser: User | null = null; editUserData: Partial = {}; changePasswordForm: FormGroup; - readonly languageOptions = AVAILABLE_LANGS.map(value => ({ - value, - label: LANG_LABELS[value] ?? value, - })); protected readonly userService = inject(UserService); - protected readonly themeService = inject(AppThemeService); - protected readonly appLocaleService = inject(AppLocaleService); private readonly messageService = inject(MessageService); private readonly fb = inject(FormBuilder); private readonly dialogRef = inject(DynamicDialogRef); 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( - () => 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() { 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 { if (!this.currentUser) { this.messageService.add({ diff --git a/frontend/src/app/features/settings/view-preferences-parent/display-preferences/display-preferences.component.html b/frontend/src/app/features/settings/view-preferences-parent/display-preferences/display-preferences.component.html new file mode 100644 index 000000000..ce38992aa --- /dev/null +++ b/frontend/src/app/features/settings/view-preferences-parent/display-preferences/display-preferences.component.html @@ -0,0 +1,131 @@ + +
+
+

+ + {{ t('theme.sectionTitle') }} +

+

{{ t('theme.sectionDesc') }}

+
+ +
+
+
+ +
+
+ + +
+ + @if (showOledDarkModeToggle()) { +
+ + + +
+ } +
+ +
+
+ +
+
+ + + @if (option) { + + @if (option.value !== 'custom') { + + } + {{ option.label }} + + } + + + + @if (option.value !== 'custom') { + + } + {{ option.label }} + + + +
+ + @if (selectedThemePreference() === 'custom') { +
+
+ @for (option of customPrimaryOptions(); track option.value) { + + } +
+
+ } + +
+ + + +
+
+ +
+
+ +
+
+ + +
+
+ +
+
+
diff --git a/frontend/src/app/features/settings/view-preferences-parent/display-preferences/display-preferences.component.ts b/frontend/src/app/features/settings/view-preferences-parent/display-preferences/display-preferences.component.ts new file mode 100644 index 000000000..018fe214c --- /dev/null +++ b/frontend/src/app/features/settings/view-preferences-parent/display-preferences/display-preferences.component.ts @@ -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 { + 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 { + 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 { + 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 { + 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 { + 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), + }); + } +} diff --git a/frontend/src/app/features/settings/view-preferences-parent/view-preferences-parent.component.html b/frontend/src/app/features/settings/view-preferences-parent/view-preferences-parent.component.html index 379964248..815e36b5c 100644 --- a/frontend/src/app/features/settings/view-preferences-parent/view-preferences-parent.component.html +++ b/frontend/src/app/features/settings/view-preferences-parent/view-preferences-parent.component.html @@ -10,6 +10,8 @@

+ +


diff --git a/frontend/src/app/features/settings/view-preferences-parent/view-preferences-parent.component.ts b/frontend/src/app/features/settings/view-preferences-parent/view-preferences-parent.component.ts index 8385810a7..6719371c5 100644 --- a/frontend/src/app/features/settings/view-preferences-parent/view-preferences-parent.component.ts +++ b/frontend/src/app/features/settings/view-preferences-parent/view-preferences-parent.component.ts @@ -6,6 +6,7 @@ import {ViewPreferencesComponent} from './view-preferences/view-preferences.comp import {SidebarSortingPreferencesComponent} from './sidebar-sorting-preferences/sidebar-sorting-preferences.component'; import {MetaCenterViewModeComponent} from './meta-center-view-mode/meta-center-view-mode-component'; import {FilterPreferencesComponent} from './filter-preferences/filter-preferences.component'; +import {DisplayPreferencesComponent} from './display-preferences/display-preferences.component'; import {TranslocoDirective, TranslocoService} from '@jsverse/transloco'; import {Slider} from 'primeng/slider'; import {MessageService} from 'primeng/api'; @@ -21,6 +22,7 @@ import {LayoutService, SIDEBAR_MAX_WIDTH, SIDEBAR_MIN_WIDTH} from '../../../shar SidebarSortingPreferencesComponent, MetaCenterViewModeComponent, FilterPreferencesComponent, + DisplayPreferencesComponent, TranslocoDirective, Slider, ], diff --git a/frontend/src/app/shared/components/login/login.component.html b/frontend/src/app/shared/components/login/login.component.html index 33d737ae3..fd69d04e9 100644 --- a/frontend/src/app/shared/components/login/login.component.html +++ b/frontend/src/app/shared/components/login/login.component.html @@ -52,7 +52,6 @@ required [(ngModel)]="username" [placeholder]="t('usernamePlaceholder')" - class="form-input" autocomplete="username" />
diff --git a/frontend/src/app/shared/components/login/login.component.scss b/frontend/src/app/shared/components/login/login.component.scss index eeffa5ef4..a85b0c89d 100644 --- a/frontend/src/app/shared/components/login/login.component.scss +++ b/frontend/src/app/shared/components/login/login.component.scss @@ -91,10 +91,6 @@ @include auth.form-label; } -.form-input { - @include auth.form-input; -} - .login-button { @include auth.auth-button; diff --git a/frontend/src/app/shared/layout/layout-sidebar/app.sidebar.component.html b/frontend/src/app/shared/layout/layout-sidebar/app.sidebar.component.html index e5dd0aaf4..9ddcc1c81 100644 --- a/frontend/src/app/shared/layout/layout-sidebar/app.sidebar.component.html +++ b/frontend/src/app/shared/layout/layout-sidebar/app.sidebar.component.html @@ -404,6 +404,53 @@ {{ t('readingStats') }} } + +
+ + +
+
+
+ @for (option of appearanceOptions; track option.value) { + + } +
+
+
+