Remove file name from subpath. Fix progress for pdf.
This commit is contained in:
@@ -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) {
|
||||
|
||||
Reference in New Issue
Block a user