refactor(ui): new standard and accessible UI font (#1777)
This commit is contained in:
+4
@@ -347,6 +347,7 @@
|
||||
.rating-value {
|
||||
font-weight: 600;
|
||||
font-size: var(--app-text-sm);
|
||||
font-variant-numeric: tabular-nums;
|
||||
color: var(--color-text);
|
||||
}
|
||||
|
||||
@@ -440,6 +441,7 @@
|
||||
|
||||
.metadata-value {
|
||||
color: var(--color-text-secondary);
|
||||
font-variant-numeric: tabular-nums;
|
||||
overflow: hidden;
|
||||
text-overflow: ellipsis;
|
||||
}
|
||||
@@ -773,6 +775,7 @@
|
||||
|
||||
.navigation-position {
|
||||
font-size: var(--app-text-sm);
|
||||
font-variant-numeric: tabular-nums;
|
||||
color: var(--color-text-secondary);
|
||||
}
|
||||
|
||||
@@ -830,6 +833,7 @@
|
||||
font-size: 0.8313rem;
|
||||
color: var(--color-text);
|
||||
font-weight: 500;
|
||||
font-variant-numeric: tabular-nums;
|
||||
}
|
||||
|
||||
.comic-volume-number,
|
||||
|
||||
@@ -242,12 +242,12 @@ describe('UserService', () => {
|
||||
httpTestingController.expectOne(req => req.url.endsWith('/api/v1/users/me')).flush(buildUser());
|
||||
await flushCurrentUserQuery();
|
||||
|
||||
service.updateUserProfile(7, {locale: 'de', theme: 'custom', themeAccent: 'teal', themeSyncEnabled: true}).subscribe();
|
||||
service.updateUserProfile(7, {locale: 'de', theme: 'custom', themeAccent: 'teal', themeSyncEnabled: true, uiFont: 'atkinson'}).subscribe();
|
||||
|
||||
const request = httpTestingController.expectOne(req => req.url.endsWith('/api/v1/users/7/profile'));
|
||||
expect(request.request.method).toBe('PUT');
|
||||
expect(request.request.body).toEqual({locale: 'de', theme: 'custom', themeAccent: 'teal', themeSyncEnabled: true});
|
||||
request.flush(buildUser({locale: 'de', theme: 'custom', themeAccent: 'teal', themeSyncEnabled: true}));
|
||||
expect(request.request.body).toEqual({locale: 'de', theme: 'custom', themeAccent: 'teal', themeSyncEnabled: true, uiFont: 'atkinson'});
|
||||
request.flush(buildUser({locale: 'de', theme: 'custom', themeAccent: 'teal', themeSyncEnabled: true, uiFont: 'atkinson'}));
|
||||
await flushCurrentUserQuery();
|
||||
|
||||
expect(service.currentUser()).toEqual(expect.objectContaining({
|
||||
@@ -255,6 +255,7 @@ describe('UserService', () => {
|
||||
theme: 'custom',
|
||||
themeAccent: 'teal',
|
||||
themeSyncEnabled: true,
|
||||
uiFont: 'atkinson',
|
||||
}));
|
||||
});
|
||||
});
|
||||
|
||||
@@ -9,6 +9,7 @@ import { DashboardConfig } from '../../dashboard/models/dashboard-config.model';
|
||||
import { injectQuery, queryOptions, QueryClient } from '@tanstack/angular-query-experimental';
|
||||
import { CURRENT_USER_QUERY_KEY } from './user-query-keys';
|
||||
import { AppTheme, CustomPrimary } from '../../../shared/model/app-state.model';
|
||||
import {DEFAULT_UI_FONT, normalizeUiFont, type UiFontPreference} from '../../../shared/model/ui-font.model';
|
||||
|
||||
export interface EntityViewPreferences {
|
||||
global: EntityViewPreference;
|
||||
@@ -324,6 +325,7 @@ export interface User {
|
||||
theme: AppTheme;
|
||||
themeAccent: CustomPrimary | null;
|
||||
themeSyncEnabled: boolean;
|
||||
uiFont?: UiFontPreference;
|
||||
assignedLibraries: Library[];
|
||||
permissions: {
|
||||
admin: boolean;
|
||||
@@ -382,6 +384,7 @@ export interface UserProfileUpdateRequest {
|
||||
theme?: AppTheme;
|
||||
themeAccent?: CustomPrimary | null;
|
||||
themeSyncEnabled?: boolean;
|
||||
uiFont?: UiFontPreference;
|
||||
}
|
||||
|
||||
@Injectable({
|
||||
@@ -535,6 +538,7 @@ export class UserService {
|
||||
theme,
|
||||
themeAccent: theme === 'custom' ? user.themeAccent ?? 'orange' : null,
|
||||
themeSyncEnabled: user.themeSyncEnabled ?? true,
|
||||
uiFont: normalizeUiFont(user.uiFont ?? DEFAULT_UI_FONT),
|
||||
permissions: {
|
||||
...permissions,
|
||||
canBulkResetGrimmoryReadProgress: permissions.canBulkResetGrimmoryReadProgress ?? permissions.canBulkResetBookloreReadProgress,
|
||||
|
||||
+14
@@ -108,6 +108,20 @@
|
||||
</div>
|
||||
</section>
|
||||
|
||||
<section class="w-full max-w-2xl rounded-md border-l-[3px] border-l-primary bg-[color-mix(in_srgb,var(--color-card)_35%,var(--color-page))] p-3.5 transition-[background,border-color] duration-200 hover:bg-[color-mix(in_srgb,var(--color-card)_20%,var(--color-page))] max-md:p-2.5">
|
||||
<div class="mb-1">
|
||||
<span class="text-sm font-medium text-text">{{ t('uiFont.label') }}</span>
|
||||
</div>
|
||||
<div class="mt-2.5 flex max-w-lg items-center gap-2.5 border-t border-dashed border-border pt-2.5">
|
||||
<p-toggleswitch
|
||||
inputId="interface-font"
|
||||
[ngModel]="useAccessibleUiFont()"
|
||||
(ngModelChange)="updateAccessibleUiFont($event)">
|
||||
</p-toggleswitch>
|
||||
<label class="text-sm font-medium text-text" for="interface-font">{{ t('uiFont.accessibleLabel') }}</label>
|
||||
</div>
|
||||
</section>
|
||||
|
||||
<section class="w-full max-w-2xl rounded-md border-l-[3px] border-l-primary bg-[color-mix(in_srgb,var(--color-card)_35%,var(--color-page))] p-3.5 transition-[background,border-color] duration-200 hover:bg-[color-mix(in_srgb,var(--color-card)_20%,var(--color-page))] max-md:p-2.5">
|
||||
<div class="mb-1">
|
||||
<label class="text-sm font-medium text-text" for="interface-language">{{ t('language.label') }}</label>
|
||||
|
||||
+20
@@ -17,6 +17,8 @@ import type {AppearancePreference, AppTheme, CustomPrimary} from '../../../../sh
|
||||
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';
|
||||
import {AppUiFontService} from '../../../../shared/service/app-ui-font.service';
|
||||
import {ACCESSIBLE_UI_FONT, DEFAULT_UI_FONT} from '../../../../shared/model/ui-font.model';
|
||||
|
||||
@Component({
|
||||
selector: 'app-display-preferences',
|
||||
@@ -34,6 +36,7 @@ import type {User, UserProfileUpdateRequest} from '../../user-management/user.se
|
||||
export class DisplayPreferencesComponent {
|
||||
private readonly themeService = inject(AppThemeService);
|
||||
private readonly localeService = inject(AppLocaleService);
|
||||
private readonly uiFontService = inject(AppUiFontService);
|
||||
private readonly userService = inject(UserService);
|
||||
private readonly messageService = inject(MessageService);
|
||||
private readonly t = inject(TranslocoService);
|
||||
@@ -51,6 +54,8 @@ export class DisplayPreferencesComponent {
|
||||
label: LANG_LABELS[value] ?? value,
|
||||
}));
|
||||
protected readonly selectedAppearancePreference = this.themeService.appearancePreference;
|
||||
protected readonly selectedUiFont = this.uiFontService.uiFont;
|
||||
protected readonly useAccessibleUiFont = computed(() => this.selectedUiFont() === ACCESSIBLE_UI_FONT);
|
||||
protected readonly selectedThemePreference = this.themeService.themePreference;
|
||||
protected readonly oledDarkMode = this.themeService.oledDarkMode;
|
||||
protected readonly showOledDarkModeToggle = computed(() => this.themeService.effectiveAppearance() === 'dark');
|
||||
@@ -84,6 +89,21 @@ export class DisplayPreferencesComponent {
|
||||
this.showSavedToast('settingsView.language.savedDetail');
|
||||
}
|
||||
|
||||
protected async updateAccessibleUiFont(useAccessibleFont: boolean): Promise<void> {
|
||||
const uiFont = useAccessibleFont ? ACCESSIBLE_UI_FONT : DEFAULT_UI_FONT;
|
||||
if (uiFont === this.selectedUiFont()) return;
|
||||
|
||||
const previousUiFont = this.selectedUiFont();
|
||||
this.uiFontService.applyUiFont(uiFont);
|
||||
|
||||
if (!await this.updateCurrentUserProfile({uiFont})) {
|
||||
this.uiFontService.applyUiFont(previousUiFont);
|
||||
return;
|
||||
}
|
||||
|
||||
this.showSavedToast('settingsView.uiFont.savedDetail');
|
||||
}
|
||||
|
||||
protected async updateThemePreference(themePreference: AppTheme): Promise<void> {
|
||||
if (!this.selectedThemeSyncEnabled()) {
|
||||
this.themeService.applyDeviceTheme(themePreference, this.selectedCustomPrimary());
|
||||
|
||||
@@ -0,0 +1,10 @@
|
||||
export const UI_FONT_VALUES = ['default', 'atkinson'] as const;
|
||||
|
||||
export type UiFontPreference = (typeof UI_FONT_VALUES)[number];
|
||||
|
||||
export const DEFAULT_UI_FONT: UiFontPreference = 'default';
|
||||
export const ACCESSIBLE_UI_FONT: UiFontPreference = 'atkinson';
|
||||
|
||||
export function normalizeUiFont(value: string | null | undefined): UiFontPreference {
|
||||
return UI_FONT_VALUES.includes(value as UiFontPreference) ? value as UiFontPreference : DEFAULT_UI_FONT;
|
||||
}
|
||||
@@ -0,0 +1,62 @@
|
||||
import {DOCUMENT} from '@angular/common';
|
||||
import {TestBed} from '@angular/core/testing';
|
||||
import {afterEach, beforeEach, describe, expect, it} from 'vitest';
|
||||
|
||||
import {AppUiFontService} from './app-ui-font.service';
|
||||
|
||||
describe('AppUiFontService', () => {
|
||||
let service: AppUiFontService;
|
||||
let document: Document;
|
||||
|
||||
beforeEach(() => {
|
||||
localStorage.clear();
|
||||
TestBed.configureTestingModule({});
|
||||
document = TestBed.inject(DOCUMENT);
|
||||
});
|
||||
|
||||
afterEach(() => {
|
||||
delete document.documentElement.dataset['uiFont'];
|
||||
localStorage.clear();
|
||||
TestBed.resetTestingModule();
|
||||
});
|
||||
|
||||
it('applies an accessible UI font to the document root', () => {
|
||||
service = TestBed.inject(AppUiFontService);
|
||||
|
||||
service.applyUiFont('atkinson');
|
||||
|
||||
expect(service.uiFont()).toBe('atkinson');
|
||||
expect(document.documentElement.dataset['uiFont']).toBe('atkinson');
|
||||
expect(localStorage.getItem('appUiFont')).toBe('atkinson');
|
||||
});
|
||||
|
||||
it('falls back to the default UI font for unsupported values', () => {
|
||||
service = TestBed.inject(AppUiFontService);
|
||||
|
||||
service.applyUiFont('unsupported');
|
||||
|
||||
expect(service.uiFont()).toBe('default');
|
||||
expect(document.documentElement.dataset['uiFont']).toBeUndefined();
|
||||
expect(localStorage.getItem('appUiFont')).toBe('default');
|
||||
});
|
||||
|
||||
it('loads a stored accessible UI font on creation', () => {
|
||||
localStorage.setItem('appUiFont', 'atkinson');
|
||||
|
||||
service = TestBed.inject(AppUiFontService);
|
||||
|
||||
expect(service.uiFont()).toBe('atkinson');
|
||||
expect(document.documentElement.dataset['uiFont']).toBe('atkinson');
|
||||
expect(localStorage.getItem('appUiFont')).toBe('atkinson');
|
||||
});
|
||||
|
||||
it('normalizes an unsupported stored UI font on creation', () => {
|
||||
localStorage.setItem('appUiFont', 'unsupported');
|
||||
|
||||
service = TestBed.inject(AppUiFontService);
|
||||
|
||||
expect(service.uiFont()).toBe('default');
|
||||
expect(document.documentElement.dataset['uiFont']).toBeUndefined();
|
||||
expect(localStorage.getItem('appUiFont')).toBe('default');
|
||||
});
|
||||
});
|
||||
@@ -0,0 +1,47 @@
|
||||
import {DOCUMENT, isPlatformBrowser} from '@angular/common';
|
||||
import {inject, Injectable, PLATFORM_ID, signal} from '@angular/core';
|
||||
|
||||
import {DEFAULT_UI_FONT, normalizeUiFont, type UiFontPreference} from '../model/ui-font.model';
|
||||
|
||||
const STORAGE_KEY = 'appUiFont';
|
||||
|
||||
@Injectable({providedIn: 'root'})
|
||||
export class AppUiFontService {
|
||||
private readonly document = inject(DOCUMENT);
|
||||
private readonly platformId = inject(PLATFORM_ID);
|
||||
private readonly uiFontSignal = signal<UiFontPreference>(DEFAULT_UI_FONT);
|
||||
|
||||
readonly uiFont = this.uiFontSignal.asReadonly();
|
||||
|
||||
constructor() {
|
||||
this.applyUiFont(this.getStoredUiFont());
|
||||
}
|
||||
|
||||
private getStoredUiFont(): UiFontPreference {
|
||||
if (!isPlatformBrowser(this.platformId)) {
|
||||
return DEFAULT_UI_FONT;
|
||||
}
|
||||
|
||||
return normalizeUiFont(localStorage.getItem(STORAGE_KEY));
|
||||
}
|
||||
|
||||
applyUiFont(uiFont: string | null | undefined): void {
|
||||
const nextUiFont = normalizeUiFont(uiFont);
|
||||
this.uiFontSignal.set(nextUiFont);
|
||||
this.applyRootAttribute(nextUiFont);
|
||||
|
||||
if (isPlatformBrowser(this.platformId)) {
|
||||
localStorage.setItem(STORAGE_KEY, nextUiFont);
|
||||
}
|
||||
}
|
||||
|
||||
private applyRootAttribute(uiFont: UiFontPreference): void {
|
||||
const root = this.document.documentElement;
|
||||
if (uiFont === DEFAULT_UI_FONT) {
|
||||
delete root.dataset['uiFont'];
|
||||
return;
|
||||
}
|
||||
|
||||
root.dataset['uiFont'] = uiFont;
|
||||
}
|
||||
}
|
||||
@@ -9,6 +9,7 @@ import {StartupService} from './startup.service';
|
||||
import {UserService} from '../../features/settings/user-management/user.service';
|
||||
import {AppThemeService} from './app-theme.service';
|
||||
import {AppLocaleService} from './app-locale.service';
|
||||
import {AppUiFontService} from './app-ui-font.service';
|
||||
|
||||
describe('StartupService', () => {
|
||||
beforeEach(() => {
|
||||
@@ -62,6 +63,7 @@ describe('StartupService', () => {
|
||||
const applySyncedTheme = vi.fn();
|
||||
const applyLocale = vi.fn().mockResolvedValue(undefined);
|
||||
const getDisplayLocale = vi.fn().mockReturnValue('de');
|
||||
const applyUiFont = vi.fn();
|
||||
|
||||
TestBed.configureTestingModule({
|
||||
providers: [
|
||||
@@ -79,6 +81,7 @@ describe('StartupService', () => {
|
||||
{provide: QueryClient, useValue: {fetchQuery}},
|
||||
{provide: AppThemeService, useValue: {applySyncedTheme, appState: () => ({themeSyncEnabled: true})}},
|
||||
{provide: AppLocaleService, useValue: {applyLocale, getDisplayLocale}},
|
||||
{provide: AppUiFontService, useValue: {applyUiFont}},
|
||||
]
|
||||
});
|
||||
|
||||
@@ -86,16 +89,18 @@ describe('StartupService', () => {
|
||||
|
||||
await expect(service.load()).resolves.toBeUndefined();
|
||||
expect(fetchQuery).not.toHaveBeenCalled();
|
||||
expect(applyUiFont).not.toHaveBeenCalled();
|
||||
expect(getDisplayLocale).toHaveBeenCalledOnce();
|
||||
expect(applyLocale).toHaveBeenCalledWith('de');
|
||||
});
|
||||
|
||||
it('uses the backend locale for authenticated users', async () => {
|
||||
const fetchQuery = vi.fn().mockResolvedValue({id: 1, username: 'admin', locale: 'en', theme: 'custom', themeAccent: 'teal', themeSyncEnabled: true});
|
||||
const fetchQuery = vi.fn().mockResolvedValue({id: 1, username: 'admin', locale: 'en', theme: 'custom', themeAccent: 'teal', themeSyncEnabled: true, uiFont: 'atkinson'});
|
||||
const updateUserProfile = vi.fn().mockReturnValue(of({id: 1, username: 'admin', locale: 'de', theme: 'custom', themeAccent: 'teal', themeSyncEnabled: true}));
|
||||
const applySyncedTheme = vi.fn();
|
||||
const applyLocale = vi.fn().mockResolvedValue(undefined);
|
||||
const getDisplayLocale = vi.fn().mockReturnValue('de');
|
||||
const applyUiFont = vi.fn();
|
||||
|
||||
TestBed.configureTestingModule({
|
||||
providers: [
|
||||
@@ -106,7 +111,7 @@ describe('StartupService', () => {
|
||||
useValue: {
|
||||
getUserQueryOptions: () => queryOptions({
|
||||
queryKey: ['user'],
|
||||
queryFn: async () => ({id: 1, username: 'admin', locale: 'en', theme: 'custom', themeAccent: 'teal', themeSyncEnabled: true}),
|
||||
queryFn: async () => ({id: 1, username: 'admin', locale: 'en', theme: 'custom', themeAccent: 'teal', themeSyncEnabled: true, uiFont: 'atkinson'}),
|
||||
}),
|
||||
updateUserProfile,
|
||||
},
|
||||
@@ -114,6 +119,7 @@ describe('StartupService', () => {
|
||||
{provide: QueryClient, useValue: {fetchQuery}},
|
||||
{provide: AppThemeService, useValue: {applySyncedTheme, appState: () => ({themeSyncEnabled: true})}},
|
||||
{provide: AppLocaleService, useValue: {applyLocale, getDisplayLocale}},
|
||||
{provide: AppUiFontService, useValue: {applyUiFont}},
|
||||
]
|
||||
});
|
||||
|
||||
@@ -123,6 +129,7 @@ describe('StartupService', () => {
|
||||
|
||||
expect(updateUserProfile).not.toHaveBeenCalled();
|
||||
expect(applySyncedTheme).toHaveBeenCalledWith('custom', 'teal');
|
||||
expect(applyUiFont).toHaveBeenCalledWith('atkinson');
|
||||
expect(applyLocale).toHaveBeenCalledWith('en');
|
||||
});
|
||||
|
||||
|
||||
@@ -5,6 +5,7 @@ import {QueryClient} from '@tanstack/angular-query-experimental';
|
||||
import {AppThemeService} from './app-theme.service';
|
||||
import {DEFAULT_CUSTOM_PRIMARY} from '../model/app-state.model';
|
||||
import {AppLocaleService} from './app-locale.service';
|
||||
import {AppUiFontService} from './app-ui-font.service';
|
||||
|
||||
@Injectable({providedIn: 'root'})
|
||||
export class StartupService {
|
||||
@@ -13,6 +14,7 @@ export class StartupService {
|
||||
private queryClient = inject(QueryClient);
|
||||
private appThemeService = inject(AppThemeService);
|
||||
private appLocaleService = inject(AppLocaleService);
|
||||
private appUiFontService = inject(AppUiFontService);
|
||||
|
||||
async load(): Promise<void> {
|
||||
if (this.authService.token()) {
|
||||
@@ -26,6 +28,7 @@ export class StartupService {
|
||||
|
||||
private async applyUserPreferences(user: User): Promise<void> {
|
||||
this.applyTheme(user);
|
||||
this.appUiFontService.applyUiFont(user.uiFont);
|
||||
await this.appLocaleService.applyLocale(user.locale);
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user