Улучшено отображение количества найденных результатов

This commit is contained in:
Book Pauk
2022-12-04 19:36:27 +07:00
parent c2e1d062e8
commit fd66034ba9
6 changed files with 42 additions and 11 deletions

View File

@@ -12,17 +12,22 @@ class AuthorPage extends BasePage {
sortBooks(bookList) {
//схлопывание серий
const books = [];
const seriesSet = new Set();
const seriesMap = new Map();
for (const book of bookList) {
if (book.series) {
if (!seriesSet.has(book.series)) {
let seriesIndex = seriesMap.get(book.series);
if (seriesIndex === undefined) {
seriesIndex = books.length;
books.push({
type: 'series',
book
book,
bookCount: 0,
});
seriesSet.add(book.series);
seriesMap.set(book.series, seriesIndex);
}
books[seriesIndex].bookCount++;
} else {
books.push({
type: 'book',
@@ -135,6 +140,10 @@ class AuthorPage extends BasePage {
link: this.navLink({
href: `/${this.id}?author=${encodeURIComponent(query.author)}` +
`&series=${encodeURIComponent(b.book.series)}&genre=${encodeURIComponent(query.genre)}`}),
content: {
'*ATTRS': {type: 'text'},
'*TEXT': `${b.bookCount} книг${utils.wordEnding(b.bookCount, 8)} по автору${(query.genre ? ' (в выбранном жанре)' : '')}`,
},
})
);
} else {
@@ -170,10 +179,16 @@ class AuthorPage extends BasePage {
link: this.navLink({href: `/${this.id}?author=${rec.q}&genre=${encodeURIComponent(query.genre)}`}),
};
if (rec.count) {
let countStr = '';
if (rec.count)
countStr = `${rec.count} автор${utils.wordEnding(rec.count, 0)}${(query.genre ? ' (в выбранном жанре)' : '')}`;
if (!countStr && rec.bookCount && !query.genre)
countStr = `${rec.bookCount} книг${utils.wordEnding(rec.bookCount, 8)}`;
if (countStr) {
e.content = {
'*ATTRS': {type: 'text'},
'*TEXT': `${rec.count} автор${utils.wordEnding(rec.count, 0)}`,
'*TEXT': countStr,
};
}

View File

@@ -140,6 +140,7 @@ class BasePage {
id: row.id,
title: (row[from] || 'Без автора'),
q: `=${encodeURIComponent(row[from])}`,
bookCount: row.bookCount,
};
result.push(rec);
@@ -171,6 +172,7 @@ class BasePage {
id: row.id,
title: row.name,
q: `=${encodeURIComponent(row.name)}`,
bookCount: row.bookCount,
};
} else {
rec = {

View File

@@ -103,10 +103,16 @@ class SeriesPage extends BasePage {
link: this.navLink({href: `/${this.id}?series=${rec.q}&genre=${encodeURIComponent(query.genre)}`}),
};
if (rec.count) {
let countStr = '';
if (rec.count)
countStr = `${rec.count} сери${utils.wordEnding(rec.count, 1)}${(query.genre ? ' (в выбранном жанре)' : '')}`;
if (!countStr && rec.bookCount && !query.genre)
countStr = `${rec.bookCount} книг${utils.wordEnding(rec.bookCount, 8)}`;
if (countStr) {
e.content = {
'*ATTRS': {type: 'text'},
'*TEXT': `${rec.count} сери${utils.wordEnding(rec.count, 1)}`,
'*TEXT': countStr,
};
}

View File

@@ -73,10 +73,16 @@ class TitlePage extends BasePage {
link: this.navLink({href: `/${this.id}?title=${rec.q}&genre=${encodeURIComponent(query.genre)}`}),
};
if (rec.count) {
let countStr = '';
if (rec.count)
countStr = `${rec.count} назван${utils.wordEnding(rec.count, 3)}${(query.genre ? ' (в выбранном жанре)' : '')}`;
if (!countStr && rec.bookCount && !query.genre)
countStr = `${rec.bookCount} книг${utils.wordEnding(rec.bookCount, 8)}`;
if (countStr) {
e.content = {
'*ATTRS': {type: 'text'},
'*TEXT': `${rec.count} назван${utils.wordEnding(rec.count, 3)}`,
'*TEXT': countStr,
};
}