From 6eae46eaa17a9e7df13f6d62750070b57fa56e91 Mon Sep 17 00:00:00 2001 From: Book Pauk Date: Tue, 25 Oct 2022 14:44:30 +0700 Subject: [PATCH] =?UTF-8?q?=D0=A0=D0=B5=D1=84=D0=B0=D0=BA=D1=82=D0=BE?= =?UTF-8?q?=D1=80=D0=B8=D0=BD=D0=B3?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../Search/AuthorList/AuthorList.vue | 8 ++- client/components/Search/Search.vue | 69 +++++++++---------- 2 files changed, 38 insertions(+), 39 deletions(-) diff --git a/client/components/Search/AuthorList/AuthorList.vue b/client/components/Search/AuthorList/AuthorList.vue index 345dd04..41364d9 100644 --- a/client/components/Search/AuthorList/AuthorList.vue +++ b/client/components/Search/AuthorList/AuthorList.vue @@ -462,7 +462,7 @@ class AuthorList extends BaseList { let result; if (this.abCacheEnabled) { - const key = `${authorId}-${this.list.inpxHash}`; + const key = `author-${authorId}-${this.list.inpxHash}`; const data = await authorBooksStorage.getData(key); if (data) { result = JSON.parse(data); @@ -811,7 +811,9 @@ class AuthorList extends BaseList { async refresh() { //параметры запроса - const newQuery = _.cloneDeep(this.search); + let newQuery = _.cloneDeep(this.search); + newQuery = newQuery.setDefaults(newQuery); + delete newQuery.setDefaults; newQuery.offset = (newQuery.page - 1)*newQuery.limit; if (_.isEqual(newQuery, this.prevQuery)) @@ -824,7 +826,7 @@ class AuthorList extends BaseList { const author = this.cachedAuthors[authorSearch]; if (author) { - const key = `${author.id}-${this.list.inpxHash}`; + const key = `author-${author.id}-${this.list.inpxHash}`; let data = await authorBooksStorage.getData(key); if (data) { diff --git a/client/components/Search/Search.vue b/client/components/Search/Search.vue index 9de6a60..213e7a0 100644 --- a/client/components/Search/Search.vue +++ b/client/components/Search/Search.vue @@ -97,13 +97,6 @@ - -
@@ -296,13 +289,17 @@ class Search { //search fields search = { - author: '', - series: '', - title: '', - genre: '', - lang: '', - page: 1, - limit: 50, + setDefaults(search) { + return Object.assign({}, search, { + author: search.author || '', + series: search.series || '', + title: search.title || '', + genre: search.genre || '', + lang: search.lang || '', + page: search.page || 1, + limit: search.limit || 50, + }); + }, }; //settings @@ -346,6 +343,9 @@ class Search { this.commit = this.$store.commit; this.api = this.$root.api; + this.search = this.search.setDefaults(this.search); + this.search.lang = this.langDefault; + this.loadSettings(); } @@ -367,7 +367,6 @@ class Search { if (!this.$root.isMobileDevice) this.$refs.authorInput.focus(); - this.setDefaults(); this.updateListFromRoute(this.$route); this.updateSearchFromRouteQuery(this.$route); @@ -699,16 +698,6 @@ class Search { this.commit('setSettings', {[name]: _.cloneDeep(newValue)}); } - setDefaults() { - this.search = Object.assign({}, this.search, { - author: '', - series: '', - title: '', - genre: '', - lang: this.langDefault, - }); - } - highlightPageScroller(query) { const q = _.cloneDeep(query); delete q.limit; @@ -728,31 +717,39 @@ class Search { updateSearchFromRouteQuery(to) { if (this.list.liberamaReady) this.sendCurrentUrl(); - + if (this.routeUpdating) return; const query = to.query; - this.search = Object.assign({}, this.search, { - author: query.author || '', - series: query.series || '', - title: query.title || '', - genre: query.genre || '', - lang: (typeof(query.lang) == 'string' ? query.lang : this.langDefault), - page: parseInt(query.page, 10) || 1, - limit: parseInt(query.limit, 10) || this.search.limit, - }); + this.search = this.search.setDefaults( + Object.assign({}, this.search, { + author: query.author, + series: query.series, + title: query.title, + genre: query.genre, + lang: (typeof(query.lang) == 'string' ? query.lang : this.langDefault), + page: parseInt(query.page, 10), + limit: parseInt(query.limit, 10) || this.search.limit, + }) + ); if (this.search.limit > 1000) this.search.limit = 1000; } updateRouteQueryFromSearch() { + if (!this.ready) + return; + this.routeUpdating = true; try { const oldQuery = this.$route.query; - const query = _.pickBy(this.search); + const cloned = _.cloneDeep(this.search); + delete cloned.setDefaults; + + const query = _.pickBy(cloned); if (this.search.lang == this.langDefault) { delete query.lang;