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
@@ -1,7 +1,7 @@
import {inject, Injectable} from '@angular/core';
import {BehaviorSubject, Observable, of} from 'rxjs';
import {BehaviorSubject, first, Observable, of} from 'rxjs';
import {HttpClient, HttpParams} from '@angular/common/http';
import {catchError, map, tap} from 'rxjs/operators';
import {catchError, filter, map, tap} from 'rxjs/operators';
import {Book, BookMetadata, BookRecommendation, BookSetting} from '../model/book.model';
import {BookState} from '../model/state/book-state.model';
import {API_CONFIG} from '../../config/api-config';
@@ -280,6 +280,27 @@ export class BookService {
});
}
getBooksInSeries(bookId: number): Observable<Book[]> {
return this.bookStateSubject.asObservable().pipe(
filter(state => state.loaded),
first(),
map(state => {
const allBooks = state.books || [];
const currentBook = allBooks.find(b => b.id === bookId);
if (!currentBook || !currentBook.metadata?.seriesName) {
return [];
}
const seriesName = currentBook.metadata.seriesName.toLowerCase();
return allBooks.filter(b =>
b.id !== bookId &&
b.metadata?.seriesName?.toLowerCase() === seriesName
);
})
);
}
/*------------------ All the websocket handlers go below ------------------*/