Compare commits

..

4 commits

Author SHA1 Message Date
Tusooa Zhu
bd3f71b030 Make search say No more results when there are current results 2023-08-11 05:07:36 +09:00
Ekaterina Vaartis
f3254129e1 Ensure uniqueness of found statuses & ensure only one loading circle 2023-08-11 04:52:21 +09:00
Ekaterina Vaartis
2ae33191ac Amend status search results, and introduce searchType
Use searchType to only search for statuses when searching for more results
2023-08-11 04:52:20 +09:00
Ekaterina Vaartis
45f3bf1848 Implement loading more statuses when searching 2023-08-11 04:46:53 +09:00
3 changed files with 68 additions and 18 deletions

View file

@ -8,6 +8,7 @@ import {
faCircleNotch, faCircleNotch,
faSearch faSearch
} from '@fortawesome/free-solid-svg-icons' } from '@fortawesome/free-solid-svg-icons'
import { uniqBy } from 'lodash'
library.add( library.add(
faCircleNotch, faCircleNotch,
@ -32,7 +33,11 @@ const Search = {
userIds: [], userIds: [],
statuses: [], statuses: [],
hashtags: [], hashtags: [],
currenResultTab: 'statuses' currenResultTab: 'statuses',
statusesOffset: 0,
lastStatusFetchCount: 0,
lastQuery: ''
} }
}, },
computed: { computed: {
@ -61,26 +66,42 @@ 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.statuses = []
this.hashtags = []
this.$refs.searchInput.blur() this.$refs.searchInput.blur()
if (this.lastQuery !== query) {
this.userIds = []
this.hashtags = []
this.statuses = []
this.$store.dispatch('search', { q: query, resolve: true }) this.statusesOffset = 0
this.lastStatusFetchCount = 0
}
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')
this.statuses = data.statuses let oldLength = this.statuses.length
this.hashtags = data.hashtags
// 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.currenResultTab = this.getActiveTab()
this.loaded = true 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) { resultCount (tabName) {

View file

@ -24,7 +24,7 @@
</button> </button>
</div> </div>
<div <div
v-if="loading" v-if="loading && statusesOffset == 0"
class="text-center loading-icon" class="text-center loading-icon"
> >
<FAIcon <FAIcon
@ -57,12 +57,6 @@
</div> </div>
<div class="panel-body"> <div class="panel-body">
<div v-if="currenResultTab === 'statuses'"> <div v-if="currenResultTab === 'statuses'">
<div
v-if="visibleStatuses.length === 0 && !loading && loaded"
class="search-result-heading"
>
<h4>{{ $t('search.no_results') }}</h4>
</div>
<Status <Status
v-for="status in visibleStatuses" v-for="status in visibleStatuses"
:key="status.id" :key="status.id"
@ -73,6 +67,33 @@
:statusoid="status" :statusoid="status"
:no-heading="false" :no-heading="false"
/> />
<button
v-if="!loading && loaded && lastStatusFetchCount > 0"
class="more-statuses-button button-unstyled -link -fullwidth"
@click.prevent="search(searchTerm, 'statuses')"
>
<div class="new-status-notification text-center">
{{ $t('search.load_more') }}
</div>
</button>
<div
v-else-if="loading && statusesOffset > 0"
class="text-center loading-icon"
>
<FAIcon
icon="circle-notch"
spin
size="lg"
/>
</div>
<div
v-if="(visibleStatuses.length === 0 || lastStatusFetchCount === 0) && !loading && loaded"
class="search-result-heading"
>
<h4>
{{ visibleStatuses.length === 0 ? $t('search.no_results') : $t('search.no_more_results') }}
</h4>
</div>
</div> </div>
<div v-else-if="currenResultTab === 'people'"> <div v-else-if="currenResultTab === 'people'">
<div <div
@ -220,4 +241,10 @@
color: var(--text, $fallback--text); color: var(--text, $fallback--text);
} }
} }
.more-statuses-button {
height: 3.5em;
line-height: 3.5em;
}
</style> </style>

View file

@ -448,7 +448,9 @@
"no_results": "No results", "no_results": "No results",
"people": "People", "people": "People",
"people_talking": "{count} people talking", "people_talking": "{count} people talking",
"person_talking": "{count} person talking" "person_talking": "{count} person talking",
"no_more_results": "No more results",
"load_more": "Load more results"
}, },
"selectable_list": { "selectable_list": {
"select_all": "Select all" "select_all": "Select all"
@ -1212,5 +1214,5 @@
"who_to_follow": { "who_to_follow": {
"more": "More", "more": "More",
"who_to_follow": "Who to follow" "who_to_follow": "Who to follow"
} }
} }