Instead of navigating to book details via the router, use dialog instead

This commit is contained in:
aditya.chandel
2025-01-04 19:17:59 -07:00
parent d6e1e23261
commit 6f7be0d94c
2 changed files with 25 additions and 7 deletions
@@ -119,8 +119,6 @@ export class BookCardComponent implements OnInit {
}
openBookInfo(book: Book): void {
setTimeout(() => {
this.router.navigate(['/library', book.libraryId, 'book', book.id, 'info']);
}, 10);
this.openBookDetailsDialog(book.id)
}
}
@@ -8,6 +8,8 @@ import {NgForOf, NgIf} from '@angular/common';
import {Button} from 'primeng/button';
import {Router} from '@angular/router';
import {BookService} from '../../service/book.service';
import {BookMetadataCenterComponent} from '../../../book-metadata-center/book-metadata-center.component';
import {DialogService} from 'primeng/dynamicdialog';
@Component({
selector: 'app-search',
@@ -27,7 +29,7 @@ export class SearchComponent implements OnInit, OnDestroy {
#searchSubject = new Subject<string>();
#subscription!: Subscription;
constructor(private bookService: BookService, private router: Router) {}
constructor(private bookService: BookService, private router: Router, private dialogService: DialogService) {}
ngOnInit(): void {
this.initializeSearch();
@@ -55,11 +57,29 @@ export class SearchComponent implements OnInit, OnDestroy {
onBookClick(book: Book): void {
this.clearSearch();
this.openBook(book.id, book.libraryId);
this.openBook(book.id);
}
openBook(bookId: number, libraryId: number): void {
this.router.navigate(['/library', libraryId, 'book', bookId, 'info']);
openBook(bookId: number): void {
this.bookService.getBookByIdFromAPI(bookId, true).subscribe(({
next: (book) => {
this.dialogService.open(BookMetadataCenterComponent, {
header: 'Open book details',
modal: true,
closable: true,
width: '1200px',
height: '835px',
showHeader: false,
closeOnEscape: true,
data: {
book: book
}
});
},
error: (error) => {
console.error('Error fetching book:', error);
}
}))
}
getBookCoverUrl(bookId: number): string {