aboutsummaryrefslogtreecommitdiff
path: root/src/components/search/search.js
diff options
context:
space:
mode:
authorHJ <30-hj@users.noreply.git.pleroma.social>2022-11-21 19:48:24 +0000
committerHJ <30-hj@users.noreply.git.pleroma.social>2022-11-21 19:48:24 +0000
commitd1885d45e79e313644d24a8741a20265099a129b (patch)
treec983436984815ffee4b824519af2a6c32f70df10 /src/components/search/search.js
parent72a5eaf40af20275a052a25b7aa911d3ef4bdcd7 (diff)
parentb09912d2f91a410a3b50ee408dd4a0621eba2ff4 (diff)
Merge branch 'search-pagination' into 'develop'
Implement loading more statuses when searching See merge request pleroma/pleroma-fe!1410
Diffstat (limited to 'src/components/search/search.js')
-rw-r--r--src/components/search/search.js39
1 files changed, 30 insertions, 9 deletions
diff --git a/src/components/search/search.js b/src/components/search/search.js
index 76ac30ef..8d4212cd 100644
--- a/src/components/search/search.js
+++ b/src/components/search/search.js
@@ -8,6 +8,7 @@ import {
faCircleNotch,
faSearch
} from '@fortawesome/free-solid-svg-icons'
+import { uniqBy } from 'lodash'
library.add(
faCircleNotch,
@@ -32,7 +33,11 @@ const Search = {
userIds: [],
statuses: [],
hashtags: [],
- currenResultTab: 'statuses'
+ currenResultTab: 'statuses',
+
+ statusesOffset: 0,
+ lastStatusFetchCount: 0,
+ lastQuery: ''
}
},
computed: {
@@ -61,26 +66,42 @@ 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.statuses = []
- 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 })
+ this.$store.dispatch('search', { q: query, resolve: true, offset: this.statusesOffset, 'type': searchType })
.then(data => {
this.loading = false
- this.userIds = map(data.accounts, 'id')
- this.statuses = data.statuses
- this.hashtags = data.hashtags
+
+ let oldLength = this.statuses.length
+
+ // 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 = uniqBy(this.statuses.concat(data.statuses), 'id')
+ this.hashtags = this.hashtags.concat(data.hashtags)
+
this.currenResultTab = this.getActiveTab()
this.loaded = true
+
+ // Offset from whatever we already have
+ this.statusesOffset = this.statuses.length
+ // Because the amount of new statuses can actually be zero, compare to old lenght instead
+ this.lastStatusFetchCount = this.statuses.length - oldLength
+ this.lastQuery = query
})
},
resultCount (tabName) {