-
-
-
-
-
+
+
- {{ item.name }}
+ {{ item.name }}
+
+
+
+ ({{ item.books.length }})
@@ -276,6 +282,9 @@ class Search {
}
onScroll() {
+ if (this.ignoreScrolling)
+ return;
+
const curScrollTop = this.$refs.scroller.scrollTop;
if (!this.lastScrollTop)
this.lastScrollTop = 0;
@@ -294,6 +303,12 @@ class Search {
this.lastScrollTop = curScrollTop;
}
+ async ignoreScroll(ms) {
+ this.ignoreScrolling = true;
+ await utils.sleep(ms);
+ this.ignoreScrolling = false;
+ }
+
scrollToTop() {
this.$refs.scroller.scrollTop = 0;
const curScrollTop = this.$refs.scroller.scrollTop;
@@ -324,17 +339,16 @@ class Search {
const author = item.author;
if (!this.isExpanded(item)) {
- if (expanded.indexOf(author) < 0) {
- expanded.push(author);
+ expanded.push(author);
- this.getBooks(item);
+ this.getBooks(item);
- if (expanded.length > 100) {
- expanded.shift();
- }
-
- this.expanded = expanded;
+ if (expanded.length > 10) {
+ expanded.shift();
}
+
+ this.expanded = expanded;
+ this.ignoreScroll(50);
} else {
const i = expanded.indexOf(author);
if (i >= 0) {
@@ -345,23 +359,12 @@ class Search {
}
async loadBooks(authorId) {
- let inSearch = true;
- (async() => {
- await utils.sleep(500);
- if (inSearch)
- this.loadingMessage = 'Загрузка списка книг...';
- })();
-
try {
const result = await this.api.getBookList(authorId);
- return result;
+ return result.books;
} catch (e) {
this.$root.stdDialog.alert(e.message, 'Ошибка');
- return;
- } finally {
- inSearch = false;
- this.loadingMessage = '';
}
}
@@ -369,7 +372,26 @@ class Search {
if (item.books)
return;
- item.books = await this.loadBooks(item.key);
+ if (!this.getBooksFlag)
+ this.getBooksFlag = 0;
+
+ this.getBooksFlag++;
+
+ try {
+ if (this.getBooksFlag == 1) {
+ (async() => {
+ await utils.sleep(500);
+ if (this.getBooksFlag > 0)
+ this.loadingMessage = 'Загрузка списка книг...';
+ })();
+ }
+
+ item.books = await this.loadBooks(item.key);
+ } finally {
+ this.getBooksFlag--;
+ if (this.getBooksFlag == 0)
+ this.loadingMessage = '';
+ }
}
async updateTableData() {
@@ -448,7 +470,6 @@ class Search {
this.scrollToTop();
} catch (e) {
this.$root.stdDialog.alert(e.message, 'Ошибка');
- return;
} finally {
inSearch = false;
this.loadingMessage = '';