Tie BE and UI for epub viewing
This commit is contained in:
@@ -3,6 +3,7 @@ import {PdfViewerComponent} from './book/components/pdf-viewer/pdf-viewer.compon
|
||||
import {BookBrowserComponent} from './book/components/book-browser/book-browser.component';
|
||||
import {MainDashboardComponent} from './dashboard/components/main-dashboard/main-dashboard.component';
|
||||
import {AppLayoutComponent} from './layout/component/layout-main/app.layout.component';
|
||||
import {EpubViewerComponent} from './epub-viewer/component/epub-viewer.component';
|
||||
|
||||
export const routes: Routes = [
|
||||
{
|
||||
@@ -25,5 +26,9 @@ export const routes: Routes = [
|
||||
{
|
||||
path: 'pdf-viewer/book/:bookId',
|
||||
component: PdfViewerComponent
|
||||
},
|
||||
{
|
||||
path: 'epub-viewer/book/:bookId',
|
||||
component: EpubViewerComponent
|
||||
}
|
||||
];
|
||||
|
||||
@@ -39,7 +39,7 @@ export class BookCardComponent implements OnInit {
|
||||
}
|
||||
|
||||
readBook(book: Book): void {
|
||||
this.bookService.readBook(book.id);
|
||||
this.bookService.readBook(book);
|
||||
}
|
||||
|
||||
toggleSelection(selected: boolean): void {
|
||||
|
||||
@@ -1,5 +1,7 @@
|
||||
import {Shelf} from './shelf.model';
|
||||
|
||||
export type BookType = "PDF" | "EPUB";
|
||||
|
||||
export interface Book {
|
||||
id: number;
|
||||
libraryId: number;
|
||||
@@ -7,6 +9,7 @@ export interface Book {
|
||||
shelves?: Shelf[];
|
||||
lastReadTime?: string;
|
||||
addedOn?: string;
|
||||
bookType: BookType;
|
||||
}
|
||||
|
||||
export interface BookMetadata {
|
||||
|
||||
@@ -2,7 +2,7 @@ import {Injectable} from '@angular/core';
|
||||
import {BehaviorSubject, Observable, of} from 'rxjs';
|
||||
import {HttpClient} from '@angular/common/http';
|
||||
import {catchError, map, switchMap, tap} from 'rxjs/operators';
|
||||
import {Book, BookMetadata, BookSetting} from '../model/book.model';
|
||||
import {Book, BookMetadata, BookSetting, BookType} from '../model/book.model';
|
||||
import {BookState} from '../model/state/book-state.model';
|
||||
|
||||
@Injectable({
|
||||
@@ -113,12 +113,21 @@ export class BookService {
|
||||
);
|
||||
}
|
||||
|
||||
readBook(bookId: number): void {
|
||||
const url = `/pdf-viewer/book/${bookId}`;
|
||||
window.open(url, '_blank');
|
||||
this.updateLastReadTime(bookId).subscribe({
|
||||
error: err => console.error('Failed to update last read time', err),
|
||||
});
|
||||
readBook(book: Book): void {
|
||||
if (book.bookType === "PDF") {
|
||||
const url = `/pdf-viewer/book/${book.id}`;
|
||||
window.open(url, '_blank');
|
||||
this.updateLastReadTime(book.id).subscribe({
|
||||
next: () => console.log('Last read time updated successfully'),
|
||||
error: err => console.error('Failed to update last read time', err),
|
||||
});
|
||||
} else if (book.bookType === "EPUB") {
|
||||
const url = `/epub-viewer/book/${book.id}`;
|
||||
window.open(url, '_blank');
|
||||
} else {
|
||||
console.error('Unsupported book type:', book.bookType);
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
searchBooks(query: string): Observable<Book[]> {
|
||||
|
||||
@@ -7,6 +7,7 @@ import {NgForOf} from '@angular/common';
|
||||
import {FormsModule} from '@angular/forms';
|
||||
import {Divider} from 'primeng/divider';
|
||||
import {DropdownModule} from 'primeng/dropdown';
|
||||
import {ActivatedRoute} from '@angular/router';
|
||||
|
||||
@Component({
|
||||
selector: 'app-epub-viewer',
|
||||
@@ -24,14 +25,12 @@ import {DropdownModule} from 'primeng/dropdown';
|
||||
export class EpubViewerComponent implements OnInit, OnDestroy {
|
||||
|
||||
@ViewChild('epubContainer', {static: true}) epubContainer!: ElementRef;
|
||||
bookId = 1;
|
||||
chapters: { label: string; href: string }[] = [];
|
||||
isDrawerVisible = false;
|
||||
isSettingsDrawerVisible: boolean = false;
|
||||
private book: any;
|
||||
private rendition: any;
|
||||
private keyListener: (e: KeyboardEvent) => void = () => {
|
||||
};
|
||||
private keyListener: (e: KeyboardEvent) => void = () => {};
|
||||
fontSize: number = 100;
|
||||
|
||||
fontTypes: any[] = [
|
||||
@@ -43,15 +42,17 @@ export class EpubViewerComponent implements OnInit, OnDestroy {
|
||||
];
|
||||
selectedFontType: string = 'serif';
|
||||
|
||||
constructor(private epubService: EpubService) {
|
||||
constructor(private epubService: EpubService, private route: ActivatedRoute) {
|
||||
}
|
||||
|
||||
ngOnInit(): void {
|
||||
this.loadEpub();
|
||||
this.route.paramMap.subscribe((params) => {
|
||||
this.loadEpub(+params.get('bookId')!);
|
||||
});
|
||||
}
|
||||
|
||||
loadEpub(): void {
|
||||
this.epubService.downloadEpub(this.bookId).subscribe(
|
||||
loadEpub(bookId: number): void {
|
||||
this.epubService.downloadEpub(bookId).subscribe(
|
||||
(data: Blob) => {
|
||||
const fileReader = new FileReader();
|
||||
fileReader.onload = () => {
|
||||
|
||||
+1
-1
@@ -66,7 +66,7 @@ export class MetadataViewerComponent implements OnInit {
|
||||
}
|
||||
|
||||
readBook(bookId: number) {
|
||||
this.bookService.readBook(bookId);
|
||||
/*this.bookService.readBook(bookId);*/
|
||||
}
|
||||
|
||||
closeDialog() {
|
||||
|
||||
Reference in New Issue
Block a user