WIP: Checkpoint for global and individual book settings
This commit is contained in:
@@ -3,7 +3,8 @@ import {ActivatedRoute} from '@angular/router';
|
||||
import {NgxExtendedPdfViewerModule, ScrollModeType} from 'ngx-extended-pdf-viewer';
|
||||
import {BookService} from '../../service/book.service';
|
||||
import {AppSettingsService} from '../../../core/service/app-settings.service';
|
||||
import {Subscription} from 'rxjs';
|
||||
import {filter, forkJoin, Subscription, take} from 'rxjs';
|
||||
import {PdfViewerSetting} from '../../model/book.model';
|
||||
|
||||
@Component({
|
||||
selector: 'app-pdf-viewer',
|
||||
@@ -33,36 +34,34 @@ export class PdfViewerComponent implements OnInit, OnDestroy {
|
||||
ngOnInit(): void {
|
||||
this.route.paramMap.subscribe((params) => {
|
||||
this.bookId = +params.get('bookId')!;
|
||||
this.loadBook(this.bookId);
|
||||
this.updateLastReadTime();
|
||||
});
|
||||
}
|
||||
this.appSettingsService.appSettings$
|
||||
.pipe(
|
||||
filter((appSettings) => appSettings !== null),
|
||||
take(1))
|
||||
.subscribe((appSettings) => {
|
||||
const book$ = this.bookService.getBookByIdFromAPI(this.bookId, false);
|
||||
const pdf$ = this.bookService.getPdfData(this.bookId);
|
||||
const bookSetting$ = this.bookService.getBookSetting(this.bookId);
|
||||
|
||||
forkJoin([book$, pdf$, bookSetting$]).subscribe((results) => {
|
||||
const pdf = results[0];
|
||||
const pdfData = results[1];
|
||||
const individualPdfSettings = results[2]?.pdfSettings;
|
||||
const globalPdfSettings = appSettings.pdf;
|
||||
|
||||
console.log(individualPdfSettings);
|
||||
console.log(globalPdfSettings);
|
||||
|
||||
this.page = pdf.pdfProgress || 1;
|
||||
this.zoom = individualPdfSettings?.zoom || globalPdfSettings?.zoom || 'page-fit';
|
||||
this.sidebarVisible = individualPdfSettings?.sidebarVisible ?? globalPdfSettings?.sidebar ?? true;
|
||||
this.spread = individualPdfSettings?.spread || globalPdfSettings?.spread || 'odd';
|
||||
|
||||
private loadBook(bookId: number): void {
|
||||
this.appSettingsSubscription = this.appSettingsService.appSettings$.subscribe((appSettings) => {
|
||||
if (appSettings) {
|
||||
this.bookService.getBookSetting(bookId).subscribe({
|
||||
next: (bookSetting) => {
|
||||
const {pageNumber, zoom, sidebar_visible, spread} = bookSetting;
|
||||
this.page = pageNumber || 1;
|
||||
this.zoom = zoom || appSettings.pdf?.zoom || 'page-fit';
|
||||
this.sidebarVisible = sidebar_visible ?? appSettings.pdf?.sidebar ?? true;
|
||||
this.spread = spread || appSettings.pdf?.spread || 'odd';
|
||||
this.isInitialLoad = false;
|
||||
this.bookService.getBookData(bookId).subscribe({
|
||||
next: (bookData) => {
|
||||
this.bookData = bookData;
|
||||
},
|
||||
error: (e) => {
|
||||
console.error('Error loading book data:', e);
|
||||
},
|
||||
});
|
||||
},
|
||||
error: (e) => {
|
||||
console.error('Error loading book settings:', e);
|
||||
},
|
||||
this.bookData = pdfData;
|
||||
this.updateLastReadTime();
|
||||
});
|
||||
});
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
@@ -100,8 +99,8 @@ export class PdfViewerComponent implements OnInit, OnDestroy {
|
||||
|
||||
private updateViewerSetting(): void {
|
||||
if (this.isInitialLoad) return;
|
||||
const updatedViewerSetting = {
|
||||
sidebar_visible: this.sidebarVisible,
|
||||
const updatedViewerSetting: PdfViewerSetting = {
|
||||
sidebarVisible: this.sidebarVisible,
|
||||
spread: this.spread,
|
||||
zoom: this.zoom,
|
||||
};
|
||||
|
||||
@@ -10,13 +10,11 @@ import {Shelf} from '../../model/shelf.model';
|
||||
import {IconPickerComponent} from '../../../utilities/component/icon-picker/icon-picker.component';
|
||||
import {ShelfState} from '../../model/state/shelf-state.model';
|
||||
import {Button} from 'primeng/button';
|
||||
import {Divider} from 'primeng/divider';
|
||||
import {AsyncPipe, NgForOf, NgIf} from '@angular/common';
|
||||
import {Checkbox} from 'primeng/checkbox';
|
||||
import {FormsModule} from '@angular/forms';
|
||||
import {Dialog} from 'primeng/dialog';
|
||||
import {InputText} from 'primeng/inputtext';
|
||||
import {Router} from '@angular/router';
|
||||
|
||||
@Component({
|
||||
selector: 'app-shelf-assigner',
|
||||
@@ -24,7 +22,6 @@ import {Router} from '@angular/router';
|
||||
templateUrl: './shelf-assigner.component.html',
|
||||
imports: [
|
||||
Button,
|
||||
Divider,
|
||||
NgForOf,
|
||||
Checkbox,
|
||||
AsyncPipe,
|
||||
|
||||
Reference in New Issue
Block a user