Display first book in series when collapsed

This commit is contained in:
aditya.chandel
2025-07-02 23:13:54 -06:00
committed by Aditya Chandel
parent 7562ae65fd
commit 1c9c09628a
2 changed files with 29 additions and 13 deletions
+3 -1
View File
@@ -2,9 +2,11 @@ name-template: 'v$NEXT_PATCH_VERSION 🌟'
tag-template: 'v$NEXT_PATCH_VERSION' tag-template: 'v$NEXT_PATCH_VERSION'
categories: categories:
- title: '🚀 Features' - title: '🚀 New Features'
labels: labels:
- 'feature' - 'feature'
- title: '✨ Enhancements'
labels:
- 'enhancement' - 'enhancement'
- title: '🐛 Bug Fixes' - title: '🐛 Bug Fixes'
labels: labels:
@@ -49,24 +49,38 @@ export class SeriesCollapseFilter implements BookFilter {
map(isCollapsed => { map(isCollapsed => {
if (!isCollapsed || !bookState.books) return bookState; if (!isCollapsed || !bookState.books) return bookState;
const seenSeries = new Set<string>(); const books = [...bookState.books];
const seriesMap = new Map<string, Book[]>();
const collapsedBooks: Book[] = []; const collapsedBooks: Book[] = [];
for (const book of bookState.books) { for (const book of books) {
const name = book.metadata?.seriesName?.trim(); const seriesName = book.metadata?.seriesName?.trim();
if (name && !seenSeries.has(name)) { if (seriesName) {
const count = bookState.books.filter(b => b.metadata?.seriesName?.trim() === name).length; if (!seriesMap.has(seriesName)) {
collapsedBooks.push({ seriesMap.set(seriesName, []);
...book, }
seriesCount: count, seriesMap.get(seriesName)!.push(book);
}); } else {
seenSeries.add(name);
} else if (!name) {
collapsedBooks.push(book); collapsedBooks.push(book);
} }
} }
return {...bookState, books: collapsedBooks}; for (const [seriesName, group] of seriesMap.entries()) {
const sortedGroup = group.slice().sort((a, b) => {
const aNum = a.metadata?.seriesNumber ?? Number.MAX_VALUE;
const bNum = b.metadata?.seriesNumber ?? Number.MAX_VALUE;
return aNum - bNum;
});
const firstBook = sortedGroup[0];
collapsedBooks.push({
...firstBook,
seriesCount: group.length
});
}
return { ...bookState, books: collapsedBooks };
}) })
); );
} }