Improve EPUB Reader: UI Enhancements (Line Height, Letter Spacing, Flow, Fonts)
This commit is contained in:
committed by
Aditya Chandel
parent
fc328a7711
commit
df5ebbe7c4
+41
@@ -0,0 +1,41 @@
|
||||
<div class="p-4 pb-12">
|
||||
<p class="text-lg pb-6 pt-4 ">
|
||||
CBX Reader: Global Preferences
|
||||
<i class="pi pi-info-circle text-sky-600"
|
||||
pTooltip="Configure global PDF reading options such as page spread, zoom level, and sidebar visibility that apply to all PDFs."
|
||||
tooltipPosition="right"
|
||||
style="cursor: pointer;"></i>
|
||||
</p>
|
||||
|
||||
<div class="grid grid-cols-[auto,1fr] pl-6 gap-y-4 gap-x-4 items-center">
|
||||
<p class="py-1">Page Spread:</p>
|
||||
<div class="flex gap-4 justify-start">
|
||||
@for (spread of cbxSpreads; track spread) {
|
||||
<div class="flex items-center gap-2">
|
||||
<p-radiobutton
|
||||
[inputId]="spread.key"
|
||||
name="spread"
|
||||
[value]="spread.key"
|
||||
[(ngModel)]="selectedCbxSpread">
|
||||
</p-radiobutton>
|
||||
<label [for]="spread.key">{{ spread.name }}</label>
|
||||
</div>
|
||||
}
|
||||
</div>
|
||||
|
||||
<p class="py-1">Page Zoom:</p>
|
||||
<div class="flex gap-4 justify-start">
|
||||
@for (mode of cbxViewModes; track mode) {
|
||||
<div class="flex items-center gap-2">
|
||||
<p-radiobutton
|
||||
[inputId]="mode.key"
|
||||
name="zoom"
|
||||
[value]="mode.key"
|
||||
[(ngModel)]="selectedCbxViewMode">
|
||||
</p-radiobutton>
|
||||
<label [for]="mode.key">{{ mode.name }}</label>
|
||||
</div>
|
||||
}
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
+50
@@ -0,0 +1,50 @@
|
||||
import {Component, inject, Input} from '@angular/core';
|
||||
import {RadioButton} from 'primeng/radiobutton';
|
||||
import {Tooltip} from 'primeng/tooltip';
|
||||
import {FormsModule} from '@angular/forms';
|
||||
import {CbxPageSpread, CbxPageViewMode} from '../../../book/model/book.model';
|
||||
import {UserSettings} from '../../user-management/user.service';
|
||||
import {ReaderPreferencesService} from '../reader-preferences-service';
|
||||
|
||||
@Component({
|
||||
selector: 'app-cbx-reader-preferences-component',
|
||||
imports: [
|
||||
RadioButton,
|
||||
Tooltip,
|
||||
FormsModule
|
||||
],
|
||||
templateUrl: './cbx-reader-preferences-component.html',
|
||||
styleUrl: './cbx-reader-preferences-component.scss'
|
||||
})
|
||||
export class CbxReaderPreferencesComponent {
|
||||
|
||||
@Input() userSettings!: UserSettings;
|
||||
|
||||
private readonly readerPreferencesService = inject(ReaderPreferencesService);
|
||||
|
||||
readonly cbxSpreads = [
|
||||
{ name: 'Even', key: 'EVEN' },
|
||||
{ name: 'Odd', key: 'ODD' }
|
||||
];
|
||||
|
||||
readonly cbxViewModes = [
|
||||
{ name: 'Single Page', key: 'SINGLE_PAGE' },
|
||||
{ name: 'Two Page', key: 'TWO_PAGE' },
|
||||
];
|
||||
|
||||
get selectedCbxSpread(): CbxPageSpread {
|
||||
return this.userSettings.cbxReaderSetting.pageSpread;
|
||||
}
|
||||
set selectedCbxSpread(value: CbxPageSpread) {
|
||||
this.userSettings.cbxReaderSetting.pageSpread = value;
|
||||
this.readerPreferencesService.updatePreference(['cbxReaderSetting', 'pageSpread'], value);
|
||||
}
|
||||
|
||||
get selectedCbxViewMode(): CbxPageViewMode {
|
||||
return this.userSettings.cbxReaderSetting.pageViewMode;
|
||||
}
|
||||
set selectedCbxViewMode(value: CbxPageViewMode) {
|
||||
this.userSettings.cbxReaderSetting.pageViewMode = value;
|
||||
this.readerPreferencesService.updatePreference(['cbxReaderSetting', 'pageViewMode'], value);
|
||||
}
|
||||
}
|
||||
+58
@@ -0,0 +1,58 @@
|
||||
<div class="p-4">
|
||||
<p class="text-lg pb-6 pt-4">
|
||||
Epub Reader: Global Preferences
|
||||
<i class="pi pi-info-circle text-sky-600"
|
||||
pTooltip="Set global EPUB reader options such as themes, font families, font sizes, and spacing applied to all EPUBs."
|
||||
tooltipPosition="right"
|
||||
style="cursor: pointer;"></i>
|
||||
</p>
|
||||
|
||||
<div class="grid grid-cols-[auto,1fr] pl-6 gap-y-4 gap-x-4 items-center">
|
||||
|
||||
<p>Theme:</p>
|
||||
<div class="flex gap-4 justify-start">
|
||||
<p-select
|
||||
size="small"
|
||||
[options]="themes"
|
||||
[(ngModel)]="selectedTheme"
|
||||
optionLabel="name"
|
||||
optionValue="key"
|
||||
placeholder="Select a Theme"
|
||||
class="w-full md:w-44">
|
||||
</p-select>
|
||||
</div>
|
||||
|
||||
<p>Font:</p>
|
||||
<div class="flex gap-4 justify-start">
|
||||
<p-select
|
||||
size="small"
|
||||
[options]="fonts"
|
||||
[(ngModel)]="selectedFont"
|
||||
optionLabel="name"
|
||||
optionValue="key"
|
||||
placeholder="Select a Font"
|
||||
class="w-full md:w-44">
|
||||
</p-select>
|
||||
</div>
|
||||
|
||||
<p>Flow:</p>
|
||||
<div class="flex gap-4 justify-start">
|
||||
<p-select
|
||||
size="small"
|
||||
[options]="flowOptions"
|
||||
[(ngModel)]="selectedFlow"
|
||||
optionLabel="name"
|
||||
optionValue="key"
|
||||
placeholder="Select a Flow"
|
||||
class="w-full md:w-44">
|
||||
</p-select>
|
||||
</div>
|
||||
|
||||
<p class="py-1">Font Size:</p>
|
||||
<div class="flex gap-4 justify-start items-center">
|
||||
<p-button icon="pi pi-minus" size="small" (click)="decreaseFontSize()"></p-button>
|
||||
<p>{{ fontSize }}%</p>
|
||||
<p-button icon="pi pi-plus" size="small" (click)="increaseFontSize()"></p-button>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
+102
@@ -0,0 +1,102 @@
|
||||
import {Component, inject, Input} from '@angular/core';
|
||||
import {Button} from 'primeng/button';
|
||||
import {Select} from 'primeng/select';
|
||||
import {Tooltip} from 'primeng/tooltip';
|
||||
import {FormsModule} from '@angular/forms';
|
||||
import {ReaderPreferencesService} from '../reader-preferences-service';
|
||||
import {UserSettings} from '../../user-management/user.service';
|
||||
|
||||
@Component({
|
||||
selector: 'app-epub-reader-preferences-component',
|
||||
imports: [
|
||||
Button,
|
||||
Select,
|
||||
Tooltip,
|
||||
FormsModule
|
||||
],
|
||||
templateUrl: './epub-reader-preferences-component.html',
|
||||
styleUrl: './epub-reader-preferences-component.scss'
|
||||
})
|
||||
export class EpubReaderPreferencesComponent {
|
||||
|
||||
@Input() userSettings!: UserSettings;
|
||||
|
||||
private readonly readerPreferencesService = inject(ReaderPreferencesService);
|
||||
|
||||
readonly fonts = [
|
||||
{name: 'Book Default', key: null},
|
||||
{name: 'Serif', key: 'serif'},
|
||||
{name: 'Sans Serif', key: 'sans-serif'},
|
||||
{name: 'Roboto', key: 'roboto'},
|
||||
{name: 'Cursive', key: 'cursive'},
|
||||
{name: 'Monospace', key: 'monospace'}
|
||||
];
|
||||
|
||||
readonly flowOptions = [
|
||||
{name: 'Book Default', key: null},
|
||||
{name: 'Paginated', key: 'paginated'},
|
||||
{name: 'Scrolled', key: 'scrolled'}
|
||||
];
|
||||
|
||||
readonly themes = [
|
||||
{name: 'Book Default', key: null},
|
||||
{name: 'White', key: 'white'},
|
||||
{name: 'Black', key: 'black'},
|
||||
{name: 'Grey', key: 'grey'},
|
||||
{name: 'Sepia', key: 'sepia'}
|
||||
];
|
||||
|
||||
get selectedTheme(): string | null {
|
||||
return this.userSettings.epubReaderSetting.theme;
|
||||
}
|
||||
|
||||
set selectedTheme(value: string | null) {
|
||||
if (typeof value === "string") {
|
||||
this.userSettings.epubReaderSetting.theme = value;
|
||||
}
|
||||
this.readerPreferencesService.updatePreference(['epubReaderSetting', 'theme'], value);
|
||||
}
|
||||
|
||||
get selectedFont(): string | null {
|
||||
return this.userSettings.epubReaderSetting.font;
|
||||
}
|
||||
|
||||
set selectedFont(value: string | null) {
|
||||
if (typeof value === "string") {
|
||||
this.userSettings.epubReaderSetting.font = value;
|
||||
}
|
||||
this.readerPreferencesService.updatePreference(['epubReaderSetting', 'font'], value);
|
||||
}
|
||||
|
||||
get selectedFlow(): string | null {
|
||||
return this.userSettings.epubReaderSetting.flow;
|
||||
}
|
||||
|
||||
set selectedFlow(value: string | null) {
|
||||
if (typeof value === "string") {
|
||||
this.userSettings.epubReaderSetting.flow = value;
|
||||
}
|
||||
this.readerPreferencesService.updatePreference(['epubReaderSetting', 'flow'], value);
|
||||
}
|
||||
|
||||
get fontSize(): number {
|
||||
return this.userSettings.epubReaderSetting.fontSize;
|
||||
}
|
||||
|
||||
set fontSize(value: number) {
|
||||
this.userSettings.epubReaderSetting.fontSize = value;
|
||||
this.readerPreferencesService.updatePreference(['epubReaderSetting', 'fontSize'], value);
|
||||
}
|
||||
|
||||
increaseFontSize() {
|
||||
if (this.fontSize < 250) {
|
||||
this.fontSize += 10;
|
||||
}
|
||||
}
|
||||
|
||||
decreaseFontSize() {
|
||||
if (this.fontSize > 50) {
|
||||
this.fontSize -= 10;
|
||||
}
|
||||
}
|
||||
}
|
||||
+41
@@ -0,0 +1,41 @@
|
||||
<div class="p-4">
|
||||
<p class="text-lg pb-6 pt-4 ">
|
||||
PDF Reader: Global Preferences
|
||||
<i class="pi pi-info-circle text-sky-600"
|
||||
pTooltip="Configure global PDF reading options such as page spread, zoom level, and sidebar visibility that apply to all PDFs."
|
||||
tooltipPosition="right"
|
||||
style="cursor: pointer;"></i>
|
||||
</p>
|
||||
|
||||
<div class="grid grid-cols-[auto,1fr] pl-6 gap-y-4 gap-x-4 items-center">
|
||||
<p class="py-1">Page Spread:</p>
|
||||
<div class="flex gap-4 justify-start">
|
||||
@for (spread of spreads; track spread) {
|
||||
<div class="flex items-center gap-2">
|
||||
<p-radiobutton
|
||||
[inputId]="spread.key"
|
||||
name="spread"
|
||||
[value]="spread.key"
|
||||
[(ngModel)]="selectedSpread">
|
||||
</p-radiobutton>
|
||||
<label [for]="spread.key">{{ spread.name }}</label>
|
||||
</div>
|
||||
}
|
||||
</div>
|
||||
|
||||
<p class="py-1">Page Zoom:</p>
|
||||
<div class="flex gap-4 justify-start">
|
||||
@for (zoom of zooms; track zoom) {
|
||||
<div class="flex items-center gap-2">
|
||||
<p-radiobutton
|
||||
[inputId]="zoom.key"
|
||||
name="zoom"
|
||||
[value]="zoom.key"
|
||||
[(ngModel)]="selectedZoom">
|
||||
</p-radiobutton>
|
||||
<label [for]="zoom.key">{{ zoom.name }}</label>
|
||||
</div>
|
||||
}
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
+53
@@ -0,0 +1,53 @@
|
||||
import {Component, inject, Input} from '@angular/core';
|
||||
import {RadioButton} from 'primeng/radiobutton';
|
||||
import {FormsModule} from '@angular/forms';
|
||||
import {Tooltip} from 'primeng/tooltip';
|
||||
import {ReaderPreferencesService} from '../reader-preferences-service';
|
||||
import {UserSettings} from '../../user-management/user.service';
|
||||
|
||||
@Component({
|
||||
selector: 'app-pdf-reader-preferences-component',
|
||||
imports: [
|
||||
RadioButton,
|
||||
FormsModule,
|
||||
Tooltip
|
||||
],
|
||||
templateUrl: './pdf-reader-preferences-component.html',
|
||||
styleUrl: './pdf-reader-preferences-component.scss'
|
||||
})
|
||||
export class PdfReaderPreferencesComponent {
|
||||
private readonly readerPreferencesService = inject(ReaderPreferencesService);
|
||||
|
||||
@Input() userSettings!: UserSettings;
|
||||
|
||||
readonly spreads = [
|
||||
{name: 'Even', key: 'even'},
|
||||
{name: 'Odd', key: 'odd'},
|
||||
{name: 'None', key: 'off'}
|
||||
];
|
||||
|
||||
readonly zooms = [
|
||||
{name: 'Auto Zoom', key: 'auto'},
|
||||
{name: 'Page Fit', key: 'page-fit'},
|
||||
{name: 'Page Width', key: 'page-width'},
|
||||
{name: 'Actual Size', key: 'page-actual'}
|
||||
];
|
||||
|
||||
get selectedSpread(): 'even' | 'odd' | 'off' {
|
||||
return this.userSettings.pdfReaderSetting.pageSpread;
|
||||
}
|
||||
|
||||
set selectedSpread(value: 'even' | 'odd' | 'off') {
|
||||
this.userSettings.pdfReaderSetting.pageSpread = value;
|
||||
this.readerPreferencesService.updatePreference(['pdfReaderSetting', 'pageSpread'], value);
|
||||
}
|
||||
|
||||
get selectedZoom(): string {
|
||||
return this.userSettings.pdfReaderSetting.pageZoom;
|
||||
}
|
||||
|
||||
set selectedZoom(value: string) {
|
||||
this.userSettings.pdfReaderSetting.pageZoom = value;
|
||||
this.readerPreferencesService.updatePreference(['pdfReaderSetting', 'pageZoom'], value);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,35 @@
|
||||
import {inject, Injectable} from '@angular/core';
|
||||
import {User, UserService, UserSettings} from '../user-management/user.service';
|
||||
import {MessageService} from 'primeng/api';
|
||||
|
||||
@Injectable({ providedIn: 'root' })
|
||||
export class ReaderPreferencesService {
|
||||
private readonly userService = inject(UserService);
|
||||
private readonly messageService = inject(MessageService);
|
||||
private currentUser: User | null = null;
|
||||
|
||||
constructor() {
|
||||
this.userService.userState$.subscribe(user => this.currentUser = user);
|
||||
}
|
||||
|
||||
updatePreference(path: string[], value: any): void {
|
||||
if (!this.currentUser) return;
|
||||
|
||||
let target: any = this.currentUser.userSettings;
|
||||
for (let i = 0; i < path.length - 1; i++) {
|
||||
target = target[path[i]] ||= {};
|
||||
}
|
||||
target[path.at(-1)!] = value;
|
||||
|
||||
const [rootKey] = path;
|
||||
const updatedValue = this.currentUser.userSettings[rootKey as keyof UserSettings];
|
||||
|
||||
this.userService.updateUserSetting(this.currentUser.id, rootKey, updatedValue);
|
||||
this.messageService.add({
|
||||
severity: 'success',
|
||||
summary: 'Preferences Updated',
|
||||
detail: 'Your preferences have been saved successfully.',
|
||||
life: 2000
|
||||
});
|
||||
}
|
||||
}
|
||||
+15
-156
@@ -1,13 +1,11 @@
|
||||
<div class="w-full h-[calc(100vh-12.1rem)] overflow-y-auto border rounded-lg enclosing-container">
|
||||
|
||||
|
||||
<div class="p-4">
|
||||
<p class="text-lg pb-4 pt-4 ">
|
||||
Book Reader Settings: Global or Per-Book
|
||||
<i class="pi pi-info-circle text-sky-600"
|
||||
pTooltip="Select whether to apply the same reader settings (font, theme, spread, zoom, etc.) globally for all books or individually per book."
|
||||
tooltipPosition="right"
|
||||
style="cursor: pointer;">
|
||||
pTooltip="Select whether to apply the same reader settings (font, theme, spread, zoom, etc.) globally for all books or individually per book."
|
||||
tooltipPosition="right"
|
||||
style="cursor: pointer;">
|
||||
</i>
|
||||
</p>
|
||||
<div class="grid grid-cols-[auto,1fr] pl-6 gap-y-4 gap-x-4 items-center">
|
||||
@@ -26,7 +24,6 @@
|
||||
</div>
|
||||
}
|
||||
</div>
|
||||
|
||||
<p class="py-1">Epub:</p>
|
||||
<div class="flex gap-4 justify-start">
|
||||
@for (item of scopeOptions; track item) {
|
||||
@@ -42,7 +39,6 @@
|
||||
</div>
|
||||
}
|
||||
</div>
|
||||
|
||||
<p class="py-1">CBX:</p>
|
||||
<div class="flex gap-4 justify-start">
|
||||
@for (item of scopeOptions; track item) {
|
||||
@@ -60,159 +56,22 @@
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
<p-divider></p-divider>
|
||||
|
||||
<app-epub-reader-preferences-component
|
||||
[userSettings]="userSettings">
|
||||
</app-epub-reader-preferences-component>
|
||||
|
||||
<p-divider></p-divider>
|
||||
|
||||
<div class="p-4">
|
||||
<p class="text-lg pb-6 pt-4 ">
|
||||
PDF Reader: Global Preferences
|
||||
<i class="pi pi-info-circle text-sky-600"
|
||||
pTooltip="Configure global PDF reading options such as page spread, zoom level, and sidebar visibility that apply to all PDFs."
|
||||
tooltipPosition="right"
|
||||
style="cursor: pointer;"></i>
|
||||
</p>
|
||||
|
||||
<div class="grid grid-cols-[auto,1fr] pl-6 gap-y-4 gap-x-4 items-center">
|
||||
<p class="py-1">Page Spread:</p>
|
||||
<div class="flex gap-4 justify-start">
|
||||
@for (spread of spreads; track spread) {
|
||||
<div class="flex items-center gap-2">
|
||||
<p-radiobutton
|
||||
[inputId]="spread.key"
|
||||
name="spread"
|
||||
[value]="spread.key"
|
||||
[(ngModel)]="selectedSpread"
|
||||
(ngModelChange)="onSpreadChange()">
|
||||
</p-radiobutton>
|
||||
<label [for]="spread.key">{{ spread.name }}</label>
|
||||
</div>
|
||||
}
|
||||
</div>
|
||||
|
||||
<p class="py-1">Page Zoom:</p>
|
||||
<div class="flex gap-4 justify-start">
|
||||
@for (zoom of zooms; track zoom) {
|
||||
<div class="flex items-center gap-2">
|
||||
<p-radiobutton
|
||||
[inputId]="zoom.key"
|
||||
name="zoom"
|
||||
[value]="zoom.key"
|
||||
[(ngModel)]="selectedZoom"
|
||||
(ngModelChange)="onZoomChange()">
|
||||
</p-radiobutton>
|
||||
<label [for]="zoom.key">{{ zoom.name }}</label>
|
||||
</div>
|
||||
}
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
<app-pdf-reader-preferences-component
|
||||
[userSettings]="userSettings">
|
||||
</app-pdf-reader-preferences-component>
|
||||
|
||||
<p-divider></p-divider>
|
||||
|
||||
<div class="p-4">
|
||||
<p class="text-lg pb-6 pt-4 ">
|
||||
Epub Reader: Global Preferences
|
||||
<i class="pi pi-info-circle text-sky-600"
|
||||
pTooltip="Set global EPUB reader options such as themes, font families, and font sizes applied to all EPUBs."
|
||||
tooltipPosition="right"
|
||||
style="cursor: pointer;"></i></p>
|
||||
<app-cbx-reader-preferences-component
|
||||
[userSettings]="userSettings">
|
||||
</app-cbx-reader-preferences-component>
|
||||
|
||||
<div class="grid grid-cols-[auto,1fr] pl-6 gap-y-4 gap-x-4 items-center">
|
||||
<p>Theme:</p>
|
||||
<div class="flex gap-4 justify-start">
|
||||
<p-select
|
||||
size="small"
|
||||
[options]="themes"
|
||||
[(ngModel)]="selectedTheme"
|
||||
optionLabel="name"
|
||||
optionValue="key"
|
||||
placeholder="Select a Theme"
|
||||
class="w-full md:w-32"
|
||||
(ngModelChange)="onThemeChange()">
|
||||
</p-select>
|
||||
</div>
|
||||
|
||||
<p>Font:</p>
|
||||
<div class="flex gap-4 justify-start">
|
||||
<p-select
|
||||
size="small"
|
||||
[options]="fonts"
|
||||
[(ngModel)]="selectedFont"
|
||||
optionLabel="name"
|
||||
optionValue="key"
|
||||
placeholder="Select a Font"
|
||||
class="w-full md:w-32"
|
||||
(ngModelChange)="onFontChange()">
|
||||
</p-select>
|
||||
</div>
|
||||
|
||||
<p>Flow:</p>
|
||||
<div class="flex gap-4 justify-start">
|
||||
<p-select
|
||||
size="small"
|
||||
[options]="flowOptions"
|
||||
[(ngModel)]="selectedFlow"
|
||||
optionLabel="name"
|
||||
optionValue="key"
|
||||
placeholder="Select a Flow"
|
||||
class="w-full md:w-32"
|
||||
(ngModelChange)="onFlowChange()">
|
||||
</p-select>
|
||||
</div>
|
||||
|
||||
<p class="py-1">Font Size:</p>
|
||||
<div class="flex gap-4 justify-start items-center">
|
||||
<p-button icon="pi pi-minus" size="small" (click)="decreaseFontSize()"></p-button>
|
||||
<p>{{ fontSize }}%</p>
|
||||
<p-button icon="pi pi-plus" size="small" (click)="increaseFontSize()"></p-button>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<p-divider></p-divider>
|
||||
|
||||
<div class="p-4">
|
||||
<p class="text-lg pb-6 pt-4 ">
|
||||
CBX Reader: Global Preferences
|
||||
<i class="pi pi-info-circle text-sky-600"
|
||||
pTooltip="Configure global PDF reading options such as page spread, zoom level, and sidebar visibility that apply to all PDFs."
|
||||
tooltipPosition="right"
|
||||
style="cursor: pointer;"></i>
|
||||
</p>
|
||||
|
||||
<div class="grid grid-cols-[auto,1fr] pl-6 gap-y-4 gap-x-4 items-center">
|
||||
<p class="py-1">Page Spread:</p>
|
||||
<div class="flex gap-4 justify-start">
|
||||
@for (spread of cbxSpreads; track spread) {
|
||||
<div class="flex items-center gap-2">
|
||||
<p-radiobutton
|
||||
[inputId]="spread.key"
|
||||
name="spread"
|
||||
[value]="spread.key"
|
||||
[(ngModel)]="selectedCbxSpread"
|
||||
(ngModelChange)="onCbxSpreadChange()">
|
||||
</p-radiobutton>
|
||||
<label [for]="spread.key">{{ spread.name }}</label>
|
||||
</div>
|
||||
}
|
||||
</div>
|
||||
|
||||
<p class="py-1">Page Zoom:</p>
|
||||
<div class="flex gap-4 justify-start">
|
||||
@for (mode of cbxViewModes; track mode) {
|
||||
<div class="flex items-center gap-2">
|
||||
<p-radiobutton
|
||||
[inputId]="mode.key"
|
||||
name="zoom"
|
||||
[value]="mode.key"
|
||||
[(ngModel)]="selectedCbxViewMode"
|
||||
(ngModelChange)="onCbxViewModeChange()">
|
||||
</p-radiobutton>
|
||||
<label [for]="mode.key">{{ mode.name }}</label>
|
||||
</div>
|
||||
}
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
</div>
|
||||
</div>
|
||||
|
||||
@@ -2,96 +2,40 @@ import {Component, inject, OnDestroy, OnInit} from '@angular/core';
|
||||
import {FormsModule} from '@angular/forms';
|
||||
|
||||
import {Observable, Subscription} from 'rxjs';
|
||||
import {Select} from 'primeng/select';
|
||||
import {RadioButton} from 'primeng/radiobutton';
|
||||
import {Divider} from 'primeng/divider';
|
||||
import {Button} from 'primeng/button';
|
||||
import {Tooltip} from 'primeng/tooltip';
|
||||
import {User, UserService, UserSettings} from '../user-management/user.service';
|
||||
import {MessageService} from 'primeng/api';
|
||||
import {CbxPageSpread, CbxPageViewMode} from '../../book/model/book.model';
|
||||
import {EpubReaderPreferencesComponent} from './epub-reader-preferences-component/epub-reader-preferences-component';
|
||||
import {PdfReaderPreferencesComponent} from './pdf-reader-preferences-component/pdf-reader-preferences-component';
|
||||
import {CbxReaderPreferencesComponent} from './cbx-reader-preferences-component/cbx-reader-preferences-component';
|
||||
import {ReaderPreferencesService} from './reader-preferences-service';
|
||||
|
||||
@Component({
|
||||
selector: 'app-reader-preferences',
|
||||
templateUrl: './reader-preferences.component.html',
|
||||
standalone: true,
|
||||
styleUrls: ['./reader-preferences.component.scss'],
|
||||
imports: [Select, FormsModule, RadioButton, Divider, Button, Tooltip]
|
||||
imports: [FormsModule, RadioButton, Divider, Tooltip, EpubReaderPreferencesComponent, PdfReaderPreferencesComponent, CbxReaderPreferencesComponent]
|
||||
})
|
||||
export class ReaderPreferences implements OnInit, OnDestroy {
|
||||
|
||||
readonly cbxSpreads = [
|
||||
{name: 'Even', key: 'EVEN'},
|
||||
{name: 'Odd', key: 'ODD'}
|
||||
];
|
||||
|
||||
readonly cbxViewModes = [
|
||||
{name: 'Single Page', key: 'SINGLE_PAGE'},
|
||||
{name: 'Two Page', key: 'TWO_PAGE'},
|
||||
];
|
||||
|
||||
|
||||
readonly spreads = [
|
||||
{name: 'Even', key: 'even'},
|
||||
{name: 'Odd', key: 'odd'},
|
||||
{name: 'None', key: 'off'}
|
||||
];
|
||||
|
||||
readonly zooms = [
|
||||
{name: 'Auto Zoom', key: 'auto'},
|
||||
{name: 'Page Fit', key: 'page-fit'},
|
||||
{name: 'Page Width', key: 'page-width'},
|
||||
{name: 'Actual Size', key: 'page-actual'}
|
||||
];
|
||||
|
||||
readonly themes = [
|
||||
{name: 'White', key: 'white'},
|
||||
{name: 'Black', key: 'black'},
|
||||
{name: 'Grey', key: 'grey'},
|
||||
{name: 'Sepia', key: 'sepia'}
|
||||
];
|
||||
|
||||
readonly fonts = [
|
||||
{name: 'Serif', key: 'serif'},
|
||||
{name: 'Sans Serif', key: 'sans-serif'},
|
||||
{name: 'Roboto', key: 'roboto'},
|
||||
{name: 'Cursive', key: 'cursive'},
|
||||
{name: 'Monospace', key: 'monospace'}
|
||||
];
|
||||
|
||||
readonly flowOptions = [
|
||||
{name: 'Paginated', key: 'paginated'},
|
||||
{name: 'Scrolled', key: 'scrolled'}
|
||||
];
|
||||
|
||||
readonly scopeOptions = ['Global', 'Individual'];
|
||||
|
||||
selectedCbxSpread!: CbxPageSpread;
|
||||
selectedCbxViewMode!: CbxPageViewMode;
|
||||
|
||||
selectedSpread!: 'even' | 'odd' | 'off';
|
||||
selectedZoom!: string;
|
||||
selectedTheme!: string;
|
||||
selectedFont!: string;
|
||||
selectedFlow!: string;
|
||||
fontSize = 100;
|
||||
showSidebar = false;
|
||||
|
||||
selectedPdfScope!: string;
|
||||
selectedEpubScope!: string;
|
||||
selectedCbxScope!: string;
|
||||
|
||||
private readonly userService = inject(UserService);
|
||||
private readonly messageService = inject(MessageService);
|
||||
private readonly readerPreferencesService = inject(ReaderPreferencesService);
|
||||
|
||||
userData$: Observable<User | null> = this.userService.userState$;
|
||||
private subscription?: Subscription;
|
||||
private currentUser: User | null = null;
|
||||
userSettings!: UserSettings;
|
||||
|
||||
ngOnInit(): void {
|
||||
this.subscription = this.userData$.subscribe(user => {
|
||||
if (user) {
|
||||
this.currentUser = user;
|
||||
this.userSettings = user.userSettings;
|
||||
this.loadPreferences(user.userSettings);
|
||||
}
|
||||
});
|
||||
@@ -105,94 +49,17 @@ export class ReaderPreferences implements OnInit, OnDestroy {
|
||||
this.selectedPdfScope = settings.perBookSetting.pdf;
|
||||
this.selectedEpubScope = settings.perBookSetting.epub;
|
||||
this.selectedCbxScope = settings.perBookSetting.cbx;
|
||||
|
||||
this.selectedSpread = settings.pdfReaderSetting.pageSpread;
|
||||
this.selectedZoom = settings.pdfReaderSetting.pageZoom;
|
||||
this.showSidebar = settings.pdfReaderSetting.showSidebar;
|
||||
|
||||
this.selectedTheme = settings.epubReaderSetting.theme;
|
||||
this.selectedFlow = settings.epubReaderSetting.flow;
|
||||
this.fontSize = settings.epubReaderSetting.fontSize;
|
||||
this.selectedFont = settings.epubReaderSetting.font;
|
||||
|
||||
this.selectedCbxSpread = settings.cbxReaderSetting.pageSpread;
|
||||
this.selectedCbxViewMode = settings.cbxReaderSetting.pageViewMode;
|
||||
}
|
||||
|
||||
private updatePreference(path: string[], value: any): void {
|
||||
if (!this.currentUser) return;
|
||||
let target: any = this.currentUser.userSettings;
|
||||
for (let i = 0; i < path.length - 1; i++) {
|
||||
target = target[path[i]] ||= {};
|
||||
}
|
||||
target[path.at(-1)!] = value;
|
||||
|
||||
const [rootKey] = path;
|
||||
const updatedValue = this.currentUser.userSettings[rootKey as keyof UserSettings];
|
||||
this.userService.updateUserSetting(this.currentUser.id, rootKey, updatedValue);
|
||||
this.messageService.add({
|
||||
severity: 'success',
|
||||
summary: 'Preferences Updated',
|
||||
detail: 'Your preferences have been saved successfully.',
|
||||
life: 2000
|
||||
});
|
||||
}
|
||||
|
||||
onThemeChange() {
|
||||
this.updatePreference(['epubReaderSetting', 'theme'], this.selectedTheme);
|
||||
}
|
||||
|
||||
onFontChange() {
|
||||
this.updatePreference(['epubReaderSetting', 'font'], this.selectedFont);
|
||||
}
|
||||
|
||||
onFlowChange() {
|
||||
this.updatePreference(['epubReaderSetting', 'flow'], this.selectedFlow);
|
||||
}
|
||||
|
||||
onFontSizeChange() {
|
||||
this.updatePreference(['epubReaderSetting', 'fontSize'], this.fontSize);
|
||||
}
|
||||
|
||||
onSpreadChange() {
|
||||
this.updatePreference(['pdfReaderSetting', 'pageSpread'], this.selectedSpread);
|
||||
}
|
||||
|
||||
onCbxSpreadChange() {
|
||||
this.updatePreference(['cbxReaderSetting', 'pageSpread'], this.selectedCbxSpread);
|
||||
}
|
||||
|
||||
onCbxViewModeChange() {
|
||||
this.updatePreference(['cbxReaderSetting', 'pageViewMode'], this.selectedCbxViewMode);
|
||||
}
|
||||
|
||||
onZoomChange() {
|
||||
this.updatePreference(['pdfReaderSetting', 'pageZoom'], this.selectedZoom);
|
||||
}
|
||||
|
||||
onPdfScopeChange() {
|
||||
this.updatePreference(['perBookSetting', 'pdf'], this.selectedPdfScope);
|
||||
this.readerPreferencesService.updatePreference(['perBookSetting', 'pdf'], this.selectedPdfScope);
|
||||
}
|
||||
|
||||
onEpubScopeChange() {
|
||||
this.updatePreference(['perBookSetting', 'epub'], this.selectedEpubScope);
|
||||
this.readerPreferencesService.updatePreference(['perBookSetting', 'epub'], this.selectedEpubScope);
|
||||
}
|
||||
|
||||
onCbxScopeChange() {
|
||||
this.updatePreference(['perBookSetting', 'cbx'], this.selectedCbxScope);
|
||||
}
|
||||
|
||||
increaseFontSize() {
|
||||
if (this.fontSize < 250) {
|
||||
this.fontSize += 10;
|
||||
this.onFontSizeChange();
|
||||
}
|
||||
}
|
||||
|
||||
decreaseFontSize() {
|
||||
if (this.fontSize > 50) {
|
||||
this.fontSize -= 10;
|
||||
this.onFontSizeChange();
|
||||
}
|
||||
this.readerPreferencesService.updatePreference(['perBookSetting', 'cbx'], this.selectedCbxScope);
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user