Remove file name from subpath. Fix progress for pdf.

This commit is contained in:
aditya.chandel
2025-01-19 15:57:08 -07:00
parent 5f7a5f55b4
commit 26b041e409
17 changed files with 98 additions and 62 deletions
@@ -4,7 +4,7 @@ import {NgxExtendedPdfViewerModule, ScrollModeType} from 'ngx-extended-pdf-viewe
import {BookService} from '../../service/book.service';
import {AppSettingsService} from '../../../core/service/app-settings.service';
import {filter, forkJoin, Subscription, take} from 'rxjs';
import {BookSetting, PdfViewerSetting} from '../../model/book.model';
import {BookSetting} from '../../model/book.model';
@Component({
selector: 'app-pdf-viewer',
@@ -65,21 +65,17 @@ export class PdfViewerComponent implements OnInit, OnDestroy {
}
this.isInitialLoad = false;
this.bookData = pdfData;
this.updateLastReadTime();
this.updateProgress();
});
});
});
}
private updateLastReadTime(): void {
this.bookService.updateLastReadTime(this.bookId).subscribe();
}
onPageChange(page: number): void {
if (page !== this.page) {
this.page = page;
this.updateViewerSetting();
}
this.updateProgress();
}
onZoomChange(zoom: string | number): void {
@@ -115,10 +111,14 @@ export class PdfViewerComponent implements OnInit, OnDestroy {
this.bookService.updateViewerSetting(bookSetting, this.bookId).subscribe();
}
updateProgress() {
this.bookService.savePdfProgress(this.bookId, this.page).subscribe();
}
ngOnDestroy(): void {
this.updateLastReadTime();
if (this.appSettingsSubscription) {
this.appSettingsSubscription.unsubscribe();
}
this.updateProgress();
}
}
@@ -98,15 +98,15 @@ export class BookService {
return this.http.put<void>(`${this.url}/${bookId}/book-viewer-setting`, bookSetting);
}
updateLastReadTime(bookId: number): Observable<Book> {
return this.http.put<Book>(`${this.url}/${bookId}/update-last-read`, {}).pipe(
switchMap(updatedBook => {
updateLastReadTime(bookId: number): Observable<void> {
const timestamp = Math.floor(Date.now() / 1000).toString();
return this.http.put<void>(`${this.url}/${bookId}/update-last-read/${timestamp}`, {}).pipe(
tap(() => {
const currentState = this.bookStateSubject.value;
const updatedBooks = (currentState.books || []).map(book =>
book.id === updatedBook.id ? {...book, lastReadTime: updatedBook.lastReadTime} : book
book.id === bookId ? {...book, lastReadTime: timestamp} : book
);
this.bookStateSubject.next({...currentState, books: updatedBooks});
return [updatedBook];
})
);
}
@@ -164,6 +164,10 @@ export class BookService {
});
}
savePdfProgress(bookId: number, progress: number): Observable<void> {
return this.http.post<void>(`${this.url}/progress`, {bookId: bookId, pdfProgress: progress});
}
saveEpubProgress(bookId: number, progress: string): Observable<void> {
return this.http.post<void>(`${this.url}/progress`, {bookId: bookId, epubProgress: progress});
}
@@ -185,7 +189,7 @@ export class BookService {
handleRemovedBookIds(removedBookIds: number[]): void {
const currentState = this.bookStateSubject.value;
const filteredBooks = (currentState.books || []).filter(book => !removedBookIds.includes(book.id)); // Check using includes() method
this.bookStateSubject.next({ ...currentState, books: filteredBooks });
this.bookStateSubject.next({...currentState, books: filteredBooks});
}
handleBookUpdate(updatedBook: Book) {
@@ -35,6 +35,7 @@ export class EpubViewerComponent implements OnInit, OnDestroy {
isSettingsDrawerVisible = false;
private book: any;
private rendition: any;
location: any;
private keyListener: (e: KeyboardEvent) => void = () => {
};
@@ -127,7 +128,6 @@ export class EpubViewerComponent implements OnInit, OnDestroy {
this.setupKeyListener();
this.trackProgress();
this.updateLastReadTime();
};
fileReader.readAsArrayBuffer(epubData);
@@ -136,13 +136,8 @@ export class EpubViewerComponent implements OnInit, OnDestroy {
});
}
private updateLastReadTime(): void {
this.bookService.updateLastReadTime(this.epub.id).subscribe();
}
changeThemes(): void {
if (this.rendition) {
console.log(this.selectedTheme)
this.rendition.themes.select(this.selectedTheme);
this.rendition.clear();
this.rendition.start();
@@ -204,14 +199,6 @@ export class EpubViewerComponent implements OnInit, OnDestroy {
document.addEventListener('keyup', this.keyListener);
}
private trackProgress(): void {
if (this.rendition) {
this.rendition.on('relocated', (location: any) => {
this.bookService.saveEpubProgress(this.epub.id, location.start.cfi).subscribe();
});
}
}
prevPage(): void {
if (this.rendition) {
this.rendition.prev();
@@ -227,6 +214,7 @@ export class EpubViewerComponent implements OnInit, OnDestroy {
navigateToChapter(chapter: { label: string; href: string }): void {
if (this.book && chapter.href) {
this.book.rendition.display(chapter.href);
this.trackProgress();
}
}
@@ -238,12 +226,20 @@ export class EpubViewerComponent implements OnInit, OnDestroy {
this.isSettingsDrawerVisible = !this.isSettingsDrawerVisible;
}
private trackProgress(): void {
if (this.rendition) {
this.rendition.on('relocated', (location: any) => {
this.bookService.saveEpubProgress(this.epub.id, location.start.cfi).subscribe();
});
}
}
ngOnDestroy(): void {
if (this.rendition) {
this.rendition.off('keyup', this.keyListener);
}
this.updateLastReadTime();
document.removeEventListener('keyup', this.keyListener);
this.trackProgress();
}
themesMap = new Map<string, any>([
@@ -101,10 +101,6 @@ export class MetadataPickerComponent implements OnInit {
return this.fetchedMetadata.categories ? this.fetchedMetadata.categories.map(category => category).join(', ') : '';
}
coverImageSrc(bookId: number): string {
return this.bookService.getBookCoverUrl(bookId);
}
onSave(): void {
const updatedBookMetadata: BookMetadata = {
bookId: this.currentBookId,