Display other books from the same series on the metadata viewer page (#151)

* Display other books from the same series on the metadata viewer page

* feat(recommendations): filter out books from the same series as the target book

---------

Co-authored-by: adityachandelgit <>
This commit is contained in:
Aditya Chandel
2025-04-20 12:56:20 -06:00
committed by GitHub
co-authored by adityachandelgit
parent fd4b3c2bee
commit b8a493d264
6 changed files with 102 additions and 41 deletions
@@ -42,6 +42,7 @@ export class BookMetadataCenterComponent implements OnInit, OnDestroy {
private routeSubscription: Subscription = Subscription.EMPTY;
ngOnInit(): void {
this.bookService.loadBooks();
this.routeSubscription = this.route.paramMap
.pipe(
switchMap(params => {
@@ -1,7 +1,6 @@
<div class="pt-2 flex flex-col h-full">
<div class="pt-2 flex flex-col h-full overflow-hidden">
<div *ngIf="metadata$ | async as metadata">
<div class="flex flex-row">
<img [attr.src]="urlHelper.getCoverUrl(metadata.bookId, metadata?.coverUpdatedOn)"
class="book-cover placeholder"
alt="Cover of {{ metadata.title }}"
@@ -12,7 +11,7 @@
<div class="pl-6 flex flex-col w-full">
<div class="flex flex-row items-center justify-between">
<div>
<p *ngIf="metadata.seriesName" class="italic">{{ metadata.seriesName }} #{{ metadata.seriesNumber }} </p>
<p *ngIf="metadata.seriesName" class="italic">{{ metadata.seriesName }} #{{ metadata.seriesNumber }}</p>
<div class="flex items-center gap-2">
<p class="text-2xl font-bold m-0">{{ metadata.title }}</p>
<i
@@ -61,7 +60,6 @@
</div>
<p class="pt-2"><span class="font-bold">File Path:</span> {{ book?.filePath }}</p>
</div>
<div *ngIf="userService.userData$ | async as userData" class="pl-6 pt-4 flex flex-row w-full gap-4">
@@ -71,13 +69,12 @@
<p-splitbutton *ngIf="userData.permissions.canEmailBook" label="Quick Send" icon="pi pi-send" [model]="items" (onClick)="quickSend(metadata.bookId)" outlined severity="info"/>
</div>
</div>
</div>
</div>
<p-divider></p-divider>
<div *ngIf="metadata$ | async as metadata" class="space-y-2 px-2">
<div *ngIf="metadata$ | async as metadata" class="flex-1 overflow-auto space-y-2 px-2 pb-4">
<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>
@@ -93,28 +90,47 @@
(click)="toggleExpand()">
</button>
</div>
<p-divider></p-divider>
<ng-container *ngIf="recommendedBooks.length > 0">
<div>
<h3 class="text-xl font-semibold">Similar Books</h3>
<div class="dashboard-scroller-infinite"
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>
</ng-container>
<ng-container *ngIf="bookInSeries.length > 0">
<div>
<h3 class="text-xl font-semibold pt-2">More in the Series</h3>
<div class="dashboard-scroller-infinite"
infiniteScroll
[infiniteScrollDistance]="2"
[infiniteScrollThrottle]="50"
[horizontal]="true">
<div class="dashboard-scroller-card" *ngFor="let book of bookInSeries">
<app-book-card
[book]="book"
[isCheckboxEnabled]="false"
[readButtonHidden]="true"
[bottomBarHidden]="true">
</app-book-card>
</div>
</div>
</div>
</ng-container>
</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>
@@ -36,7 +36,6 @@
}
.dashboard-scroller-card {
height: 165px;
width: 101px;
flex-shrink: 0;
flex-grow: 0;
@@ -45,16 +45,9 @@ export class MetadataViewerComponent implements OnInit {
metadata$: Observable<BookMetadata | null> = this.metadataCenterService.currentMetadata$;
items: MenuItem[] | undefined;
recommendedBooks: BookRecommendation[] = [];
bookInSeries: Book[] = [];
isExpanded = false;
toggleExpand(): void {
this.isExpanded = !this.isExpanded;
}
shouldShowToggle(description?: string): boolean {
return (description?.length || 0) > 300;
}
ngOnInit(): void {
this.items = [
@@ -88,6 +81,18 @@ export class MetadataViewerComponent implements OnInit {
this.getBookRecommendations(metadata.bookId);
}
});
this.metadata$
.pipe(takeUntilDestroyed(this.destroyRef))
.subscribe((metadata) => {
if (metadata) {
this.getBooksInSeries(metadata.bookId);
}
});
}
toggleExpand(): void {
this.isExpanded = !this.isExpanded;
}
getBookRecommendations(bookId: number): void {
@@ -96,6 +101,12 @@ export class MetadataViewerComponent implements OnInit {
});
}
getBooksInSeries(bookId: number): void {
this.bookService.getBooksInSeries(bookId).subscribe((bookInSeries) => {
this.bookInSeries = bookInSeries;
});
}
read(bookId: number): void {
this.bookService.readBook(bookId);
}