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
@@ -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);
});
});
}