mirror of
https://github.com/booklore-app/booklore.git
synced 2025-12-23 22:28:11 -05:00
Display first book in series when collapsed
This commit is contained in:
committed by
Aditya Chandel
parent
7562ae65fd
commit
1c9c09628a
4
.github/release-drafter.yml
vendored
4
.github/release-drafter.yml
vendored
@@ -2,9 +2,11 @@ name-template: 'v$NEXT_PATCH_VERSION 🌟'
|
||||
tag-template: 'v$NEXT_PATCH_VERSION'
|
||||
|
||||
categories:
|
||||
- title: '🚀 Features'
|
||||
- title: '🚀 New Features'
|
||||
labels:
|
||||
- 'feature'
|
||||
- title: '✨ Enhancements'
|
||||
labels:
|
||||
- 'enhancement'
|
||||
- title: '🐛 Bug Fixes'
|
||||
labels:
|
||||
|
||||
@@ -49,24 +49,38 @@ export class SeriesCollapseFilter implements BookFilter {
|
||||
map(isCollapsed => {
|
||||
if (!isCollapsed || !bookState.books) return bookState;
|
||||
|
||||
const seenSeries = new Set<string>();
|
||||
const books = [...bookState.books];
|
||||
|
||||
const seriesMap = new Map<string, Book[]>();
|
||||
const collapsedBooks: Book[] = [];
|
||||
|
||||
for (const book of bookState.books) {
|
||||
const name = book.metadata?.seriesName?.trim();
|
||||
if (name && !seenSeries.has(name)) {
|
||||
const count = bookState.books.filter(b => b.metadata?.seriesName?.trim() === name).length;
|
||||
collapsedBooks.push({
|
||||
...book,
|
||||
seriesCount: count,
|
||||
});
|
||||
seenSeries.add(name);
|
||||
} else if (!name) {
|
||||
for (const book of books) {
|
||||
const seriesName = book.metadata?.seriesName?.trim();
|
||||
if (seriesName) {
|
||||
if (!seriesMap.has(seriesName)) {
|
||||
seriesMap.set(seriesName, []);
|
||||
}
|
||||
seriesMap.get(seriesName)!.push(book);
|
||||
} else {
|
||||
collapsedBooks.push(book);
|
||||
}
|
||||
}
|
||||
|
||||
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;
|
||||
});
|
||||
|
||||
return {...bookState, books: collapsedBooks};
|
||||
const firstBook = sortedGroup[0];
|
||||
collapsedBooks.push({
|
||||
...firstBook,
|
||||
seriesCount: group.length
|
||||
});
|
||||
}
|
||||
|
||||
return { ...bookState, books: collapsedBooks };
|
||||
})
|
||||
);
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user