Integrate Similar Book Recommendations in Book Metadata Center UI
This commit is contained in:
committed by
Aditya Chandel
parent
6fa394e1ed
commit
fd4b3c2bee
@@ -13,5 +13,4 @@ export class BookMetadataCenterService {
|
||||
emit(bookMetadata: BookMetadata) {
|
||||
this.bookMetadataSubject.next(bookMetadata);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
+40
-5
@@ -6,7 +6,7 @@
|
||||
class="book-cover placeholder"
|
||||
alt="Cover of {{ metadata.title }}"
|
||||
loading="lazy"
|
||||
width="250"/>
|
||||
width="225"/>
|
||||
|
||||
<div class="flex flex-col justify-between">
|
||||
<div class="pl-6 flex flex-col w-full">
|
||||
@@ -68,8 +68,7 @@
|
||||
<p-button label="Read" icon="pi pi-book" severity="info" (onClick)="read(metadata.bookId)"></p-button>
|
||||
<p-button label="Assign Shelf" icon="pi pi-folder" severity="info" outlined (onClick)="assignShelf(metadata.bookId)"></p-button>
|
||||
<p-button *ngIf="userData.permissions.canDownload" label="Download" icon="pi pi-download" severity="info" outlined (onClick)="download(metadata.bookId)"></p-button>
|
||||
<p-splitbutton *ngIf="userData.permissions.canEmailBook" label="Quick Send" icon="pi pi-send" [model]="items" (onClick)="quickSend(metadata.bookId)" outlined
|
||||
severity="info"/>
|
||||
<p-splitbutton *ngIf="userData.permissions.canEmailBook" label="Quick Send" icon="pi pi-send" [model]="items" (onClick)="quickSend(metadata.bookId)" outlined severity="info"/>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
@@ -78,8 +77,44 @@
|
||||
|
||||
<p-divider></p-divider>
|
||||
|
||||
<div *ngIf="metadata$ | async as metadata" class="book-description space-y-4 overflow-y-auto flex-1">
|
||||
<p class="pt-2 px-2" [innerHTML]="metadata.description || 'No description available.'"></p>
|
||||
<div *ngIf="metadata$ | async as metadata" class="space-y-2 px-2">
|
||||
<div [ngClass]="{ 'line-clamp-5': !isExpanded, 'line-clamp-none': isExpanded }"
|
||||
class="transition-all duration-300 overflow-hidden description-container">
|
||||
<div class="description-content" [innerHTML]="metadata.description || 'No description available.'"></div>
|
||||
</div>
|
||||
|
||||
<div *ngIf="metadata.description && metadata.description.length > 100" class="text-left">
|
||||
<button pButton
|
||||
type="button"
|
||||
[label]="isExpanded ? 'Show less' : 'Show more'"
|
||||
[icon]="isExpanded ? 'pi pi-chevron-up' : 'pi pi-chevron-down'"
|
||||
iconPos="right"
|
||||
class="p-button-text p-button-sm"
|
||||
(click)="toggleExpand()">
|
||||
</button>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<p-divider></p-divider>
|
||||
|
||||
<div class="recommended-books-header pb-2">
|
||||
<h3 class="text-xl font-semibold">Similar Books</h3>
|
||||
</div>
|
||||
|
||||
<div class="dashboard-scroller-infinite"
|
||||
*ngIf="recommendedBooks.length > 0"
|
||||
infiniteScroll
|
||||
[infiniteScrollDistance]="2"
|
||||
[infiniteScrollThrottle]="50"
|
||||
[horizontal]="true">
|
||||
<div class="dashboard-scroller-card" *ngFor="let book of recommendedBooks">
|
||||
<app-book-card
|
||||
[book]="book.book"
|
||||
[isCheckboxEnabled]="false"
|
||||
[readButtonHidden]="true"
|
||||
[bottomBarHidden]="true">
|
||||
</app-book-card>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
</div>
|
||||
|
||||
+17
-1
@@ -31,8 +31,8 @@
|
||||
scroll-snap-type: x mandatory;
|
||||
padding: 0.25rem;
|
||||
gap: 1.25rem;
|
||||
height: 100%;
|
||||
width: 100%;
|
||||
height: 100%;
|
||||
}
|
||||
|
||||
.dashboard-scroller-card {
|
||||
@@ -42,3 +42,19 @@
|
||||
flex-grow: 0;
|
||||
flex-basis: 101px;
|
||||
}
|
||||
|
||||
.description-container {
|
||||
max-height: 60px;
|
||||
overflow: hidden;
|
||||
transition: max-height 0.3s ease-in-out;
|
||||
}
|
||||
|
||||
.description-container .description-content {
|
||||
max-height: 250px;
|
||||
overflow-y: auto;
|
||||
}
|
||||
|
||||
.line-clamp-none {
|
||||
max-height: none;
|
||||
overflow: visible;
|
||||
}
|
||||
|
||||
+33
-5
@@ -1,5 +1,5 @@
|
||||
import {Component, inject, Input, OnInit} from '@angular/core';
|
||||
import {Button} from 'primeng/button';
|
||||
import {Component, DestroyRef, inject, Input, OnInit} from '@angular/core';
|
||||
import {Button, ButtonDirective} from 'primeng/button';
|
||||
import {AsyncPipe, DecimalPipe, NgClass, NgForOf, NgIf} from '@angular/common';
|
||||
import {first, Observable} from 'rxjs';
|
||||
import {BookService} from '../../../book/service/book.service';
|
||||
@@ -7,7 +7,7 @@ import {BookMetadataCenterService} from '../book-metadata-center.service';
|
||||
import {Rating} from 'primeng/rating';
|
||||
import {FormsModule} from '@angular/forms';
|
||||
import {Tag} from 'primeng/tag';
|
||||
import {Book, BookMetadata} from '../../../book/model/book.model';
|
||||
import {Book, BookMetadata, BookRecommendation} from '../../../book/model/book.model';
|
||||
import {Divider} from 'primeng/divider';
|
||||
import {UrlHelperService} from '../../../utilities/service/url-helper.service';
|
||||
import {UserService} from '../../../user.service';
|
||||
@@ -18,13 +18,16 @@ import {DialogService} from 'primeng/dynamicdialog';
|
||||
import {EmailService} from '../../../settings/email/email.service';
|
||||
import {ShelfAssignerComponent} from '../../../book/components/shelf-assigner/shelf-assigner.component';
|
||||
import {Tooltip} from 'primeng/tooltip';
|
||||
import {InfiniteScrollDirective} from 'ngx-infinite-scroll';
|
||||
import {BookCardComponent} from '../../../book/components/book-browser/book-card/book-card.component';
|
||||
import {takeUntilDestroyed} from '@angular/core/rxjs-interop';
|
||||
|
||||
@Component({
|
||||
selector: 'app-metadata-viewer',
|
||||
standalone: true,
|
||||
templateUrl: './metadata-viewer.component.html',
|
||||
styleUrl: './metadata-viewer.component.scss',
|
||||
imports: [Button, NgForOf, NgIf, AsyncPipe, Rating, FormsModule, Tag, Divider, SplitButton, NgClass, Tooltip, DecimalPipe]
|
||||
imports: [Button, NgForOf, NgIf, AsyncPipe, Rating, FormsModule, Tag, Divider, SplitButton, NgClass, Tooltip, DecimalPipe, InfiniteScrollDirective, BookCardComponent, ButtonDirective]
|
||||
})
|
||||
export class MetadataViewerComponent implements OnInit {
|
||||
|
||||
@@ -35,12 +38,23 @@ export class MetadataViewerComponent implements OnInit {
|
||||
private messageService = inject(MessageService);
|
||||
private bookService = inject(BookService);
|
||||
private metadataCenterService = inject(BookMetadataCenterService);
|
||||
|
||||
protected urlHelper = inject(UrlHelperService);
|
||||
protected userService = inject(UserService);
|
||||
private destroyRef = inject(DestroyRef);
|
||||
|
||||
metadata$: Observable<BookMetadata | null> = this.metadataCenterService.currentMetadata$;
|
||||
items: MenuItem[] | undefined;
|
||||
recommendedBooks: BookRecommendation[] = [];
|
||||
|
||||
isExpanded = false;
|
||||
|
||||
toggleExpand(): void {
|
||||
this.isExpanded = !this.isExpanded;
|
||||
}
|
||||
|
||||
shouldShowToggle(description?: string): boolean {
|
||||
return (description?.length || 0) > 300;
|
||||
}
|
||||
|
||||
ngOnInit(): void {
|
||||
this.items = [
|
||||
@@ -66,6 +80,20 @@ export class MetadataViewerComponent implements OnInit {
|
||||
}
|
||||
}
|
||||
];
|
||||
|
||||
this.metadata$
|
||||
.pipe(takeUntilDestroyed(this.destroyRef))
|
||||
.subscribe((metadata) => {
|
||||
if (metadata) {
|
||||
this.getBookRecommendations(metadata.bookId);
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
getBookRecommendations(bookId: number): void {
|
||||
this.bookService.getBookRecommendations(bookId).subscribe((recommendations) => {
|
||||
this.recommendedBooks = recommendations;
|
||||
});
|
||||
}
|
||||
|
||||
read(bookId: number): void {
|
||||
|
||||
Reference in New Issue
Block a user