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"
[rotation]="rotation"
[scrollMode]="scrollMode"
[sidebarVisible]="sidebarVisible"
[sidebarVisible]="false"
[zoom]="zoom"
[spread]="spread"
(pageChange)="onPageChange($event)"
(zoomChange)="onZoomChange($event)"
(sidebarVisibleChange)="onSidebarVisibleChange($event)"
(spreadChange)="onSpreadChange($event)">
</ngx-extended-pdf-viewer>
@@ -19,7 +19,6 @@ export class PdfViewerComponent implements OnInit, OnDestroy {
rotation: 0 | 90 | 180 | 270 = 0;
scrollMode: ScrollModeType = ScrollModeType.page;
sidebarVisible!: boolean;
page!: number;
spread!: 'off' | 'even' | 'odd';
zoom!: number | string;
@@ -50,11 +49,9 @@ export class PdfViewerComponent implements OnInit, OnDestroy {
let globalOrIndividual = myself.bookPreferences.perBookSetting.pdf;
if (globalOrIndividual === 'Global') {
this.zoom = myself.bookPreferences.pdfReaderSetting.pageZoom || 'page-fit';
this.sidebarVisible = myself.bookPreferences.pdfReaderSetting.showSidebar ?? true;
this.spread = myself.bookPreferences.pdfReaderSetting.pageSpread || 'odd';
} else {
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.page = pdfMeta.pdfProgress || 1;
@@ -64,10 +61,10 @@ export class PdfViewerComponent implements OnInit, OnDestroy {
}
onPageChange(page: number): void {
if (page !== this.page) {
if (page !== 1 && page !== this.page) {
this.page = page;
this.updateProgress();
}
this.updateProgress();
}
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 {
if (spread !== this.spread) {
this.spread = spread;
@@ -94,7 +84,6 @@ export class PdfViewerComponent implements OnInit, OnDestroy {
private updateViewerSetting(): void {
const bookSetting: BookSetting = {
pdfSettings: {
sidebarVisible: this.sidebarVisible,
spread: this.spread,
zoom: this.zoom,
}
@@ -72,7 +72,6 @@ export interface Award {
export interface PdfViewerSetting {
zoom: string | number;
sidebarVisible: boolean;
spread: 'off' | 'even' | 'odd';
}
@@ -11,6 +11,7 @@ import {BookService} from '../../book/service/book.service';
import {filter, forkJoin, take} from 'rxjs';
import {AppSettingsService} from '../../core/service/app-settings.service';
import {Select} from 'primeng/select';
import {UserService} from '../../user.service';
const FALLBACK_EPUB_SETTINGS = {
fontSize: 150,
@@ -35,7 +36,6 @@ export class EpubViewerComponent implements OnInit, OnDestroy {
isSettingsDrawerVisible = false;
private book: any;
private rendition: any;
location: any;
private keyListener: (e: KeyboardEvent) => void = () => {
};
@@ -59,79 +59,77 @@ export class EpubViewerComponent implements OnInit, OnDestroy {
];
private route = inject(ActivatedRoute);
private userService = inject(UserService);
private bookService = inject(BookService);
private appSettingsService = inject(AppSettingsService);
epub!: Book;
ngOnInit(): void {
this.route.paramMap.subscribe((params) => {
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 epub = results[0];
const epubData = results[1];
const individualSetting = results[2]?.epubSettings;
const globalSetting = appSettings.epub;
const epubScope = appSettings?.readerSettings?.epubScope;
const myself$ = this.userService.getMyself();
const epub$ = this.bookService.getBookByIdFromAPI(bookId, false);
const epubData$ = this.bookService.getFileContent(bookId);
const bookSetting$ = this.bookService.getBookSetting(bookId);
this.epub = epub;
const fileReader = new FileReader();
forkJoin([myself$, epub$, epubData$, bookSetting$]).subscribe((results) => {
const myself = results[0];
const epub = results[1];
const epubData = results[2];
const individualSetting = results[3]?.epubSettings;
fileReader.onload = () => {
this.book = ePub(fileReader.result as ArrayBuffer);
this.epub = epub;
const fileReader = new FileReader();
this.book.loaded.navigation.then((nav: any) => {
this.chapters = nav.toc.map((chapter: any) => ({
label: chapter.label,
href: chapter.href,
}));
});
fileReader.onload = () => {
this.book = ePub(fileReader.result as ArrayBuffer);
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);
});
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.book.loaded.navigation.then((nav: any) => {
this.chapters = nav.toc.map((chapter: any) => ({
label: chapter.label,
href: chapter.href,
}));
});
});
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);
});
});
}