Buggy sidebar

This commit is contained in:
aditya.chandel
2025-03-07 23:58:41 -07:00
parent b0ae188310
commit f8ce3349c9
4 changed files with 62 additions and 77 deletions
@@ -5,11 +5,10 @@
[page]="page" [page]="page"
[rotation]="rotation" [rotation]="rotation"
[scrollMode]="scrollMode" [scrollMode]="scrollMode"
[sidebarVisible]="sidebarVisible" [sidebarVisible]="false"
[zoom]="zoom" [zoom]="zoom"
[spread]="spread" [spread]="spread"
(pageChange)="onPageChange($event)" (pageChange)="onPageChange($event)"
(zoomChange)="onZoomChange($event)" (zoomChange)="onZoomChange($event)"
(sidebarVisibleChange)="onSidebarVisibleChange($event)"
(spreadChange)="onSpreadChange($event)"> (spreadChange)="onSpreadChange($event)">
</ngx-extended-pdf-viewer> </ngx-extended-pdf-viewer>
@@ -19,7 +19,6 @@ export class PdfViewerComponent implements OnInit, OnDestroy {
rotation: 0 | 90 | 180 | 270 = 0; rotation: 0 | 90 | 180 | 270 = 0;
scrollMode: ScrollModeType = ScrollModeType.page; scrollMode: ScrollModeType = ScrollModeType.page;
sidebarVisible!: boolean;
page!: number; page!: number;
spread!: 'off' | 'even' | 'odd'; spread!: 'off' | 'even' | 'odd';
zoom!: number | string; zoom!: number | string;
@@ -50,11 +49,9 @@ export class PdfViewerComponent implements OnInit, OnDestroy {
let globalOrIndividual = myself.bookPreferences.perBookSetting.pdf; let globalOrIndividual = myself.bookPreferences.perBookSetting.pdf;
if (globalOrIndividual === 'Global') { if (globalOrIndividual === 'Global') {
this.zoom = myself.bookPreferences.pdfReaderSetting.pageZoom || 'page-fit'; this.zoom = myself.bookPreferences.pdfReaderSetting.pageZoom || 'page-fit';
this.sidebarVisible = myself.bookPreferences.pdfReaderSetting.showSidebar ?? true;
this.spread = myself.bookPreferences.pdfReaderSetting.pageSpread || 'odd'; this.spread = myself.bookPreferences.pdfReaderSetting.pageSpread || 'odd';
} else { } else {
this.zoom = pdfPrefs.pdfSettings?.zoom || myself.bookPreferences.pdfReaderSetting.pageZoom || 'page-fit'; this.zoom = pdfPrefs.pdfSettings?.zoom || myself.bookPreferences.pdfReaderSetting.pageZoom || 'page-fit';
this.sidebarVisible = pdfPrefs.pdfSettings?.sidebarVisible ?? myself.bookPreferences.pdfReaderSetting.showSidebar ?? true;
this.spread = pdfPrefs.pdfSettings?.spread || myself.bookPreferences.pdfReaderSetting.pageSpread || 'odd'; this.spread = pdfPrefs.pdfSettings?.spread || myself.bookPreferences.pdfReaderSetting.pageSpread || 'odd';
} }
this.page = pdfMeta.pdfProgress || 1; this.page = pdfMeta.pdfProgress || 1;
@@ -64,10 +61,10 @@ export class PdfViewerComponent implements OnInit, OnDestroy {
} }
onPageChange(page: number): void { onPageChange(page: number): void {
if (page !== this.page) { if (page !== 1 && page !== this.page) {
this.page = page; this.page = page;
this.updateProgress();
} }
this.updateProgress();
} }
onZoomChange(zoom: string | number): void { onZoomChange(zoom: string | number): void {
@@ -77,13 +74,6 @@ export class PdfViewerComponent implements OnInit, OnDestroy {
} }
} }
onSidebarVisibleChange(visible: boolean): void {
if (visible !== this.sidebarVisible) {
this.sidebarVisible = visible;
this.updateViewerSetting();
}
}
onSpreadChange(spread: 'off' | 'even' | 'odd'): void { onSpreadChange(spread: 'off' | 'even' | 'odd'): void {
if (spread !== this.spread) { if (spread !== this.spread) {
this.spread = spread; this.spread = spread;
@@ -94,7 +84,6 @@ export class PdfViewerComponent implements OnInit, OnDestroy {
private updateViewerSetting(): void { private updateViewerSetting(): void {
const bookSetting: BookSetting = { const bookSetting: BookSetting = {
pdfSettings: { pdfSettings: {
sidebarVisible: this.sidebarVisible,
spread: this.spread, spread: this.spread,
zoom: this.zoom, zoom: this.zoom,
} }
@@ -72,7 +72,6 @@ export interface Award {
export interface PdfViewerSetting { export interface PdfViewerSetting {
zoom: string | number; zoom: string | number;
sidebarVisible: boolean;
spread: 'off' | 'even' | 'odd'; spread: 'off' | 'even' | 'odd';
} }
@@ -11,6 +11,7 @@ import {BookService} from '../../book/service/book.service';
import {filter, forkJoin, take} from 'rxjs'; import {filter, forkJoin, take} from 'rxjs';
import {AppSettingsService} from '../../core/service/app-settings.service'; import {AppSettingsService} from '../../core/service/app-settings.service';
import {Select} from 'primeng/select'; import {Select} from 'primeng/select';
import {UserService} from '../../user.service';
const FALLBACK_EPUB_SETTINGS = { const FALLBACK_EPUB_SETTINGS = {
fontSize: 150, fontSize: 150,
@@ -35,7 +36,6 @@ export class EpubViewerComponent implements OnInit, OnDestroy {
isSettingsDrawerVisible = false; isSettingsDrawerVisible = false;
private book: any; private book: any;
private rendition: any; private rendition: any;
location: any;
private keyListener: (e: KeyboardEvent) => void = () => { private keyListener: (e: KeyboardEvent) => void = () => {
}; };
@@ -59,79 +59,77 @@ export class EpubViewerComponent implements OnInit, OnDestroy {
]; ];
private route = inject(ActivatedRoute); private route = inject(ActivatedRoute);
private userService = inject(UserService);
private bookService = inject(BookService); private bookService = inject(BookService);
private appSettingsService = inject(AppSettingsService);
epub!: Book; epub!: Book;
ngOnInit(): void { ngOnInit(): void {
this.route.paramMap.subscribe((params) => { this.route.paramMap.subscribe((params) => {
const bookId = +params.get('bookId')!; const bookId = +params.get('bookId')!;
this.appSettingsService.appSettings$
.pipe(filter((appSettings) => appSettings !== null), take(1))
.subscribe((appSettings) => {
const epub$ = this.bookService.getBookByIdFromAPI(bookId, false);
const epubData$ = this.bookService.getFileContent(bookId);
const bookSetting$ = this.bookService.getBookSetting(bookId);
forkJoin([epub$, epubData$, bookSetting$]).subscribe((results) => { const myself$ = this.userService.getMyself();
const epub = results[0]; const epub$ = this.bookService.getBookByIdFromAPI(bookId, false);
const epubData = results[1]; const epubData$ = this.bookService.getFileContent(bookId);
const individualSetting = results[2]?.epubSettings; const bookSetting$ = this.bookService.getBookSetting(bookId);
const globalSetting = appSettings.epub;
const epubScope = appSettings?.readerSettings?.epubScope;
this.epub = epub; forkJoin([myself$, epub$, epubData$, bookSetting$]).subscribe((results) => {
const fileReader = new FileReader(); const myself = results[0];
const epub = results[1];
const epubData = results[2];
const individualSetting = results[3]?.epubSettings;
fileReader.onload = () => { this.epub = epub;
this.book = ePub(fileReader.result as ArrayBuffer); const fileReader = new FileReader();
this.book.loaded.navigation.then((nav: any) => { fileReader.onload = () => {
this.chapters = nav.toc.map((chapter: any) => ({ this.book = ePub(fileReader.result as ArrayBuffer);
label: chapter.label,
href: chapter.href,
}));
});
this.rendition = this.book.renderTo(this.epubContainer.nativeElement, { this.book.loaded.navigation.then((nav: any) => {
flow: 'paginated', this.chapters = nav.toc.map((chapter: any) => ({
width: '100%', label: chapter.label,
height: '100%', href: chapter.href,
allowScriptedContent: true, }));
});
if (this.epub?.epubProgress) {
this.rendition.display(this.epub.epubProgress);
} else {
this.rendition.display();
}
this.themesMap.forEach((theme, name) => {
this.rendition.themes.register(name, theme);
});
if (epubScope === 'Global') {
this.selectedTheme = globalSetting?.theme || FALLBACK_EPUB_SETTINGS.theme;
this.selectedFontType = globalSetting?.font || FALLBACK_EPUB_SETTINGS.fontType;
this.fontSize = globalSetting?.fontSize || FALLBACK_EPUB_SETTINGS.fontSize;
} else {
this.selectedTheme = individualSetting?.theme || globalSetting?.theme || FALLBACK_EPUB_SETTINGS.theme;
this.selectedFontType = individualSetting?.font || globalSetting?.font || FALLBACK_EPUB_SETTINGS.fontType;
this.fontSize = individualSetting?.fontSize || globalSetting?.fontSize || FALLBACK_EPUB_SETTINGS.fontSize;
}
this.rendition.themes.select(this.selectedTheme);
this.rendition.themes.fontSize(`${this.fontSize}%`);
this.rendition.themes.font(this.selectedFontType);
this.setupKeyListener();
this.trackProgress();
};
fileReader.readAsArrayBuffer(epubData);
}); });
});
this.rendition = this.book.renderTo(this.epubContainer.nativeElement, {
flow: 'paginated',
width: '100%',
height: '100%',
allowScriptedContent: true,
});
if (this.epub?.epubProgress) {
this.rendition.display(this.epub.epubProgress);
} else {
this.rendition.display();
}
this.themesMap.forEach((theme, name) => {
this.rendition.themes.register(name, theme);
});
let globalOrIndividual = myself.bookPreferences.perBookSetting.pdf;
if (globalOrIndividual === 'Global') {
this.selectedTheme = myself.bookPreferences.epubReaderSetting.theme || FALLBACK_EPUB_SETTINGS.theme;
this.selectedFontType = myself.bookPreferences.epubReaderSetting.font || FALLBACK_EPUB_SETTINGS.fontType;
this.fontSize = myself.bookPreferences.epubReaderSetting.fontSize || FALLBACK_EPUB_SETTINGS.fontSize;
} else {
this.selectedTheme = individualSetting?.theme || myself.bookPreferences.epubReaderSetting.theme || FALLBACK_EPUB_SETTINGS.theme;
this.selectedFontType = individualSetting?.font || myself.bookPreferences.epubReaderSetting.font || FALLBACK_EPUB_SETTINGS.fontType;
this.fontSize = individualSetting?.fontSize || myself.bookPreferences.epubReaderSetting.fontSize || FALLBACK_EPUB_SETTINGS.fontSize;
}
this.rendition.themes.select(this.selectedTheme);
this.rendition.themes.fontSize(`${this.fontSize}%`);
this.rendition.themes.font(this.selectedFontType);
this.setupKeyListener();
this.trackProgress();
};
fileReader.readAsArrayBuffer(epubData);
});
}); });
} }