Move book metadata view to tab and remove the routed page

This commit is contained in:
aditya.chandel
2025-01-04 17:59:26 -07:00
parent 82b7cca0a5
commit 77fb080757
16 changed files with 156 additions and 343 deletions
@@ -50,7 +50,7 @@ export class BookCardComponent implements OnInit {
}
readBook(book: Book): void {
this.bookService.readBook(book);
this.bookService.readBook(book.id);
}
toggleSelection(selected: boolean): void {
@@ -1,66 +0,0 @@
<div class="book-metadata-container">
<div class="book-metadata">
<div class="book-header">
<div>
<div class="cover-wrapper cover-container">
<img [src]="coverImageSrc(book?.id)" class="book-cover placeholder" alt="Cover of {{ book?.metadata?.title }}" loading="lazy"/>
<div class="overlay" (click)="readBook(book!)">
<p-button icon="pi pi-book" [rounded]="true"></p-button>
</div>
</div>
<div>
<div class="book-navigation">
<p-button
icon="pi pi-arrow-left"
class="navigation-button"
severity="help"
(click)="navigateToBook(previousBookId, book?.libraryId!)"
[rounded]="true"
[outlined]="true"
[disabled]="!canGoPrevious()">
</p-button>
<p-button
icon="pi pi-arrow-right"
class="navigation-button"
severity="help"
(click)="navigateToBook(nextBookId, book?.libraryId!)"
[rounded]="true"
[outlined]="true"
[disabled]="!canGoNext()">
</p-button>
</div>
</div>
</div>
<div class="metadata">
<div class="title-row">
<h1 class="book-title">
{{ book?.metadata?.title }}<span *ngIf="book?.metadata?.subtitle">: {{ book?.metadata?.subtitle }}</span>
</h1>
<div class="button-group">
<p-button [rounded]="true" [raised]="true" [outlined]="true" (onClick)="openEditDialog(book?.id!)" icon="pi pi-pencil"></p-button>
<p-button [rounded]="true" [raised]="true" [outlined]="true" (onClick)="readBook(book!)" icon="pi pi-eye"></p-button>
<p-button [rounded]="true" [raised]="true" [outlined]="true" icon="pi pi-download"></p-button>
</div>
</div>
<p class="author">Author — {{ getAuthorNames(book) }}</p>
<div class="categories">
<p-button *ngFor="let category of book?.metadata?.categories" label="{{category.name}}" severity="info" [rounded]="true" [outlined]="true" size="small"></p-button>
</div>
<div class="details">
<p><strong>Publisher:</strong> {{ book?.metadata?.publisher || 'N/A' }}</p>
<p><strong>Published:</strong> {{ book?.metadata?.publishedDate || 'Unknown' }}</p>
<p><strong>Language:</strong> {{ book?.metadata?.language || 'Unknown' }}</p>
<p *ngIf="book?.metadata?.googleBookId">
<strong>Google Book:</strong>
<a [href]="'https://books.google.com/books?id=' + book?.metadata?.googleBookId" target="_blank">
Link
</a>
</p>
</div>
</div>
</div>
<div class="book-description">
<p [innerHTML]="book?.metadata?.description || 'No description available.'"></p>
</div>
</div>
</div>
@@ -1,123 +0,0 @@
.book-metadata-container {
height: calc(100vh - 6.5rem);
overflow-y: auto;
transition: transform 0.2s, left 0.2s;
background-color: var(--card-background);
border-radius: 12px;
padding: 1.5rem 2rem;
}
.book-metadata {
color: var(--text-color);
}
.book-header {
display: flex;
gap: 16px;
}
.cover-container {
position: relative;
max-width: 200px;
flex-shrink: 0;
}
.cover-wrapper {
position: relative;
}
.book-cover {
width: 100%;
border-radius: 8px;
box-shadow: 0 2px 8px rgba(0, 0, 0, 0.2);
transition: filter 0.3s ease;
}
.cover-container:hover .book-cover {
filter: blur(1px);
}
.overlay {
position: absolute;
top: 50%;
left: 50%;
transform: translate(-50%, -50%);
display: none;
}
.cover-container:hover .overlay {
display: block;
}
.metadata {
flex-grow: 1;
}
.title-row {
display: flex;
justify-content: space-between;
align-items: center;
margin-bottom: 0.6rem;
}
.book-title {
font-size: 1.25rem;
font-weight: bold;
margin: 0;
}
.button-group {
display: flex;
gap: 1.5rem;
}
.p-button-sm {
font-size: 0.8rem;
padding: 0.5rem;
}
.p-button-text {
color: var(--primary-color);
}
.author {
font-size: 1.1rem;
color: var(--text-color-secondary);
margin: 9px 0;
}
.categories {
display: flex;
flex-wrap: wrap;
gap: 8px;
margin-bottom: 12px;
}
.category {
background-color: var(--text-color);
color: #555;
font-size: 0.8rem;
padding: 4px 8px;
border-radius: 16px;
}
.details p {
margin: 4px 0;
}
.book-description {
margin-top: 16px;
}
.book-navigation {
display: flex;
justify-content: space-between;
margin: 0.8rem 1rem 0;
}
.book-subtitle {
font-size: 1rem;
color: var(--text-color-secondary);
margin-top: 0.25rem;
font-weight: normal;
}
@@ -1,138 +0,0 @@
import {Component, OnDestroy, OnInit} from '@angular/core';
import {ActivatedRoute, Router} from '@angular/router';
import {Book} from '../../model/book.model';
import {Button} from 'primeng/button';
import {NgForOf, NgIf} from '@angular/common';
import {DialogService, DynamicDialogRef} from 'primeng/dynamicdialog';
import {forkJoin, Subscription} from 'rxjs';
import {TagModule} from 'primeng/tag';
import {BookService} from '../../service/book.service';
import {LibraryService} from '../../service/library.service';
import {MetadataSearcherComponent} from '../../../book-info-tabs/metadata-searcher/metadata-searcher.component';
import {LoadingService} from '../../../loading.service';
@Component({
selector: 'app-book-metadata',
templateUrl: './book-metadata.component.html',
styleUrls: ['./book-metadata.component.scss'],
imports: [
Button,
NgForOf,
TagModule,
NgIf
]
})
export class BookMetadataComponent implements OnInit, OnDestroy {
book: Book | null = null;
nextBookId: number | null = null;
previousBookId: number | null = null;
private routeSubscription!: Subscription;
private dialogRef!: DynamicDialogRef;
private dialogSubscription?: Subscription;
constructor(
private bookService: BookService, private activatedRoute: ActivatedRoute,
private dialogService: DialogService, private router: Router,
private libraryService: LibraryService, private loadingService: LoadingService,) {
}
ngOnInit(): void {
this.routeSubscription = this.activatedRoute.paramMap.subscribe((paramMap) => {
const bookId = +paramMap.get('bookId')!;
const libraryId = +paramMap.get('libraryId')!;
if (bookId && libraryId) {
this.loadBookWithNeighbors(bookId, libraryId);
}
});
}
private loadBookWithNeighbors(libraryId: number, bookId: number): void {
this.libraryService.getBookWithNeighbours(bookId, libraryId).subscribe((response) => {
this.book = response.currentBook;
this.nextBookId = response.nextBookId;
this.previousBookId = response.previousBookId;
});
}
navigateToBook(bookId: number | null, libraryId: number | null): void {
if (bookId && libraryId) {
this.router.navigate(['/library', libraryId, 'book', bookId, 'info']);
}
}
canGoNext(): boolean {
return this.nextBookId !== null;
}
canGoPrevious(): boolean {
return this.previousBookId !== null;
}
getAuthorNames(book: Book | null): string {
if (book && book.metadata && book.metadata.authors) {
return book.metadata.authors.map((author) => author.name).join(', ');
}
return 'No authors available';
}
openEditDialog(bookId: number) {
/*this.loadingService.show();
forkJoin({
book: this.bookService.getBookByIdFromAPI(bookId, true),
fetchedMetadata: this.bookService.fetchMetadataFromSource(bookId)
}).subscribe({
next: ({ book, fetchedMetadata }) => {
this.loadingService.hide();
this.dialogRef = this.dialogService.open(MetadataSearcherComponent, {
header: 'Update Book Metadata',
modal: true,
closable: true,
width: '1350px',
height: '1000px',
contentStyle: {
'overflow-y': 'auto',
'max-height': 'calc(100vh - 150px)',
'padding': '1.25rem 1.25rem 0',
},
data: {
currentMetadata: book.metadata,
fetchedMetadata: fetchedMetadata,
book: this.book
}
});
if (this.dialogRef) {
this.dialogSubscription = this.dialogRef.onClose.subscribe(() => {
if (this.book?.id && this.book?.libraryId) {
this.loadBookWithNeighbors(this.book.id, this.book.libraryId);
}
});
} else {
console.error('DialogRef is undefined or null');
}
},
error: (error) => {
this.loadingService.hide();
console.error('Error fetching metadata:', error);
}
});*/
}
coverImageSrc(bookId: number | undefined): string {
if (bookId === null) {
return 'assets/book-cover-metadata.png';
}
return this.bookService.getBookCoverUrl(bookId!);
}
ngOnDestroy(): void {
if (this.routeSubscription) {
this.routeSubscription.unsubscribe();
}
}
readBook(book: Book) {
this.bookService.readBook(book);
}
}