Amend status search results, and introduce searchType

Use searchType to only search for statuses when searching for more results
This commit is contained in:
Ekaterina Vaartis 2021-08-22 15:36:03 +03:00 committed by itepechi
parent 45f3bf1848
commit 2ae33191ac
2 changed files with 11 additions and 7 deletions

View File

@ -65,28 +65,32 @@ const Search = {
this.$router.push({ name: 'search', query: { query } }) this.$router.push({ name: 'search', query: { query } })
this.$refs.searchInput.focus() this.$refs.searchInput.focus()
}, },
search (query) { search (query, searchType = null) {
if (!query) { if (!query) {
this.loading = false this.loading = false
return return
} }
this.loading = true this.loading = true
this.userIds = []
this.hashtags = []
this.$refs.searchInput.blur() this.$refs.searchInput.blur()
if (this.lastQuery !== query) { if (this.lastQuery !== query) {
this.userIds = []
this.hashtags = []
this.statuses = [] this.statuses = []
this.statusesOffset = 0 this.statusesOffset = 0
this.lastStatusFetchCount = 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 => { .then(data => {
this.loading = false 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.statuses = this.statuses.concat(data.statuses)
this.hashtags = data.hashtags this.hashtags = this.hashtags.concat(data.hashtags)
this.currenResultTab = this.getActiveTab() this.currenResultTab = this.getActiveTab()
this.loaded = true this.loaded = true

View File

@ -70,7 +70,7 @@
<button <button
v-if="!loading && loaded && lastStatusFetchCount > 0" v-if="!loading && loaded && lastStatusFetchCount > 0"
class="more-statuses-button button-unstyled -link -fullwidth" class="more-statuses-button button-unstyled -link -fullwidth"
@click.prevent="search(searchTerm)" @click.prevent="search(searchTerm, 'statuses')"
> >
<div class="new-status-notification text-center"> <div class="new-status-notification text-center">
{{ $t('search.load_more') }} {{ $t('search.load_more') }}