Build a lazy-loading PDF viewer for large files
This commit is contained in:
committed by
Aditya Chandel
parent
38487f8e5d
commit
fce5ccf22c
@@ -116,6 +116,25 @@ export class BookService {
|
||||
this.bookStateSubject.next({...currentState, books: updatedBooks});
|
||||
}
|
||||
|
||||
readPdf(bookId: number, reader: "ngx" | "streaming") {
|
||||
const currentBooks = this.bookStateSubject.value.books;
|
||||
const book = currentBooks?.find(book => book.id === bookId);
|
||||
if (book) {
|
||||
if (book.bookType === "PDF") {
|
||||
if (reader === "ngx") {
|
||||
const url = `/pdf-viewer/book/${book.id}`;
|
||||
window.open(url, '_blank');
|
||||
} else {
|
||||
const url = `/cbx-viewer/book/${book.id}`;
|
||||
window.open(url, '_blank');
|
||||
}
|
||||
this.updateLastReadTime(book.id);
|
||||
}
|
||||
} else {
|
||||
console.error('Book not found');
|
||||
}
|
||||
}
|
||||
|
||||
readBook(bookId: number): void {
|
||||
const currentBooks = this.bookStateSubject.value.books;
|
||||
const book = currentBooks?.find(book => book.id === bookId);
|
||||
@@ -377,9 +396,9 @@ export class BookService {
|
||||
const currentState = this.bookStateSubject.value;
|
||||
const updatedBooks = (currentState.books || []).map(book => {
|
||||
const updatedMetadata = updatedMetadataList.find(meta => meta.bookId === book.id);
|
||||
return updatedMetadata ? { ...book, metadata: updatedMetadata } : book;
|
||||
return updatedMetadata ? {...book, metadata: updatedMetadata} : book;
|
||||
});
|
||||
this.bookStateSubject.next({ ...currentState, books: updatedBooks });
|
||||
this.bookStateSubject.next({...currentState, books: updatedBooks});
|
||||
}),
|
||||
map(() => void 0),
|
||||
catchError((error) => {
|
||||
|
||||
@@ -0,0 +1,21 @@
|
||||
import { Injectable } from '@angular/core';
|
||||
import {API_CONFIG} from '../../config/api-config';
|
||||
import {HttpClient} from '@angular/common/http';
|
||||
|
||||
@Injectable({
|
||||
providedIn: 'root'
|
||||
})
|
||||
export class NewPdfReaderService {
|
||||
|
||||
private readonly url = `${API_CONFIG.BASE_URL}/api/v1/pdf`;
|
||||
|
||||
constructor(private http: HttpClient) {}
|
||||
|
||||
getAvailablePages(bookId: number) {
|
||||
return this.http.get<number[]>(`${this.url}/${bookId}/pages`);
|
||||
}
|
||||
|
||||
getPageImageUrl(bookId: number, page: number): string {
|
||||
return `${this.url}/${bookId}/pages/${page}`;
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user