From 3117623f3000eed03ec7828c3ed112bd67366620 Mon Sep 17 00:00:00 2001 From: Ekaterina Vaartis Date: Mon, 16 Aug 2021 21:30:07 +0300 Subject: [PATCH 1/5] Implement loading more statuses when searching --- src/components/search/search.js | 20 ++++++++++++---- src/components/search/search.vue | 40 ++++++++++++++++++++++++++------ src/i18n/en.json | 3 ++- 3 files changed, 51 insertions(+), 12 deletions(-) diff --git a/src/components/search/search.js b/src/components/search/search.js index b62bc2c5..6347febf 100644 --- a/src/components/search/search.js +++ b/src/components/search/search.js @@ -30,7 +30,11 @@ const Search = { userIds: [], statuses: [], hashtags: [], - currenResultTab: 'statuses' + currenResultTab: 'statuses', + + statusesOffset: 0, + lastStatusFetchCount: 0, + lastQuery: '' } }, computed: { @@ -67,18 +71,26 @@ const Search = { this.loading = true this.userIds = [] - this.statuses = [] this.hashtags = [] this.$refs.searchInput.blur() + if (this.lastQuery !== query) { + this.statuses = [] + this.statusesOffset = 0 + this.lastStatusFetchCount = 0 + } - this.$store.dispatch('search', { q: query, resolve: true }) + this.$store.dispatch('search', { q: query, resolve: true, offset: this.statusesOffset }) .then(data => { this.loading = false this.userIds = map(data.accounts, 'id') - this.statuses = data.statuses + this.statuses = this.statuses.concat(data.statuses) this.hashtags = data.hashtags this.currenResultTab = this.getActiveTab() this.loaded = true + + this.statusesOffset += data.statuses.length + this.lastStatusFetchCount = data.statuses.length + this.lastQuery = query }) }, resultCount (tabName) { diff --git a/src/components/search/search.vue b/src/components/search/search.vue index b7bfc1f3..5d8a6715 100644 --- a/src/components/search/search.vue +++ b/src/components/search/search.vue @@ -55,12 +55,6 @@
-
-

{{ $t('search.no_results') }}

-
+ +
+ +
+
+

+ {{ $t('search.no_results') }} +

+
diff --git a/src/i18n/en.json b/src/i18n/en.json index b31e4880..6026b33e 100644 --- a/src/i18n/en.json +++ b/src/i18n/en.json @@ -827,7 +827,8 @@ "hashtags": "Hashtags", "person_talking": "{count} person talking", "people_talking": "{count} people talking", - "no_results": "No results" + "no_results": "No results", + "load_more": "Load more results" }, "password_reset": { "forgot_password": "Forgot password?", From ca7fa67997de81710f96944ccdbd080dcd3b0bf9 Mon Sep 17 00:00:00 2001 From: Ekaterina Vaartis Date: Sun, 22 Aug 2021 15:36:03 +0300 Subject: [PATCH 2/5] Amend status search results, and introduce searchType Use searchType to only search for statuses when searching for more results --- src/components/search/search.js | 16 ++++++++++------ src/components/search/search.vue | 2 +- 2 files changed, 11 insertions(+), 7 deletions(-) diff --git a/src/components/search/search.js b/src/components/search/search.js index 6347febf..751a9c37 100644 --- a/src/components/search/search.js +++ b/src/components/search/search.js @@ -63,28 +63,32 @@ const Search = { this.$router.push({ name: 'search', query: { query } }) this.$refs.searchInput.focus() }, - search (query) { + search (query, searchType = null) { if (!query) { this.loading = false return } this.loading = true - this.userIds = [] - this.hashtags = [] this.$refs.searchInput.blur() if (this.lastQuery !== query) { + this.userIds = [] + this.hashtags = [] this.statuses = [] + this.statusesOffset = 0 this.lastStatusFetchCount = 0 } - this.$store.dispatch('search', { q: query, resolve: true, offset: this.statusesOffset }) + this.$store.dispatch('search', { q: query, resolve: true, offset: this.statusesOffset, 'type': searchType }) .then(data => { this.loading = false - this.userIds = map(data.accounts, 'id') + + // Always append to old results. If new results are empty, this doesn't change anything + this.userIds = this.userIds.concat(map(data.accounts, 'id')) this.statuses = this.statuses.concat(data.statuses) - this.hashtags = data.hashtags + this.hashtags = this.hashtags.concat(data.hashtags) + this.currenResultTab = this.getActiveTab() this.loaded = true diff --git a/src/components/search/search.vue b/src/components/search/search.vue index 5d8a6715..f3076f65 100644 --- a/src/components/search/search.vue +++ b/src/components/search/search.vue @@ -68,7 +68,7 @@
Date: Fri, 15 Jul 2022 20:22:39 -0400 Subject: [PATCH 4/5] Fix search() not honouring type param --- src/modules/statuses.js | 4 ++-- src/services/api/api.service.js | 6 +++++- 2 files changed, 7 insertions(+), 3 deletions(-) diff --git a/src/modules/statuses.js b/src/modules/statuses.js index ac5d25c4..69f8af3a 100644 --- a/src/modules/statuses.js +++ b/src/modules/statuses.js @@ -747,8 +747,8 @@ const statuses = { rootState.api.backendInteractor.fetchRebloggedByUsers({ id }) .then(rebloggedByUsers => commit('addRepeats', { id, rebloggedByUsers, currentUser: rootState.users.currentUser })) }, - search (store, { q, resolve, limit, offset, following }) { - return store.rootState.api.backendInteractor.search2({ q, resolve, limit, offset, following }) + search (store, { q, resolve, limit, offset, following, type }) { + return store.rootState.api.backendInteractor.search2({ q, resolve, limit, offset, following, type }) .then((data) => { store.commit('addNewUsers', data.accounts) store.commit('addNewStatuses', { statuses: data.statuses }) diff --git a/src/services/api/api.service.js b/src/services/api/api.service.js index 436b8b0a..8341112b 100644 --- a/src/services/api/api.service.js +++ b/src/services/api/api.service.js @@ -1002,7 +1002,7 @@ const searchUsers = ({ credentials, query }) => { .then((data) => data.map(parseUser)) } -const search2 = ({ credentials, q, resolve, limit, offset, following }) => { +const search2 = ({ credentials, q, resolve, limit, offset, following, type }) => { let url = MASTODON_SEARCH_2 let params = [] @@ -1026,6 +1026,10 @@ const search2 = ({ credentials, q, resolve, limit, offset, following }) => { params.push(['following', true]) } + if (type) { + params.push(['following', type]) + } + params.push(['with_relationships', true]) let queryString = map(params, (param) => `${param[0]}=${param[1]}`).join('&') From b09912d2f91a410a3b50ee408dd4a0621eba2ff4 Mon Sep 17 00:00:00 2001 From: Tusooa Zhu Date: Fri, 15 Jul 2022 20:26:05 -0400 Subject: [PATCH 5/5] Make search say No more results when there are current results --- src/components/search/search.vue | 2 +- src/i18n/en.json | 1 + 2 files changed, 2 insertions(+), 1 deletion(-) diff --git a/src/components/search/search.vue b/src/components/search/search.vue index 4373a94b..6fc6a0de 100644 --- a/src/components/search/search.vue +++ b/src/components/search/search.vue @@ -89,7 +89,7 @@ class="search-result-heading" >

- {{ $t('search.no_results') }} + {{ visibleStatuses.length === 0 ? $t('search.no_results') : $t('search.no_more_results') }}

diff --git a/src/i18n/en.json b/src/i18n/en.json index 6026b33e..167a3e0f 100644 --- a/src/i18n/en.json +++ b/src/i18n/en.json @@ -828,6 +828,7 @@ "person_talking": "{count} person talking", "people_talking": "{count} people talking", "no_results": "No results", + "no_more_results": "No more results", "load_more": "Load more results" }, "password_reset": {