refactor(books): frontend book query service and pagination basics (#2094)
This commit is contained in:
@@ -0,0 +1,21 @@
|
||||
import {InfiniteData} from '@tanstack/angular-query-experimental';
|
||||
|
||||
import {BrowseFacetGroup, BrowsePage} from '../../../core/data/browse.models';
|
||||
import {BookSummary} from './book-response.models';
|
||||
|
||||
export type BookPage = BrowsePage<BookSummary>;
|
||||
export type BookFacetGroup = BrowseFacetGroup;
|
||||
|
||||
export function flattenBookPages(
|
||||
data: InfiniteData<BookPage> | undefined,
|
||||
): BookSummary[] {
|
||||
const books = data?.pages.flatMap(page => page.content) ?? [];
|
||||
const seen = new Set<number>();
|
||||
return books.filter(book => {
|
||||
if (seen.has(book.id)) {
|
||||
return false;
|
||||
}
|
||||
seen.add(book.id);
|
||||
return true;
|
||||
});
|
||||
}
|
||||
Reference in New Issue
Block a user