Skip to content

Commit 435ec7a

Browse files
committed
fix(unified-search): Smarter load more button
This commit introduces a change to prevent showing the load more button, if the length of existing results is not equal to the requested limit (which implies it is less than because we never expect it to be more) Additionally, there is an enhancment to override provider filders passed to the find method. This would improve speed. Signed-off-by: nfebe <[email protected]>
1 parent 2ea1248 commit 435ec7a

File tree

1 file changed

+5
-12
lines changed

1 file changed

+5
-12
lines changed

core/src/components/UnifiedSearch/UnifiedSearchModal.vue

Lines changed: 5 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -129,7 +129,7 @@
129129
v-bind="result" />
130130
</ul>
131131
<div class="result-footer">
132-
<NcButton type="tertiary-no-background" @click="loadMoreResultsForProvider(providerResult)">
132+
<NcButton v-if="providerResult.results.length === providerResult.limit" type="tertiary-no-background" @click="loadMoreResultsForProvider(providerResult)">
133133
{{ t('core', 'Load more results') }}
134134
<template #icon>
135135
<IconDotsHorizontal :size="20" />
@@ -367,7 +367,7 @@ export default defineComponent({
367367
this.$refs.searchInput?.focus()
368368
})
369369
},
370-
find(query: string) {
370+
find(query: string, providersToSearchOverride = null) {
371371
if (query.length === 0) {
372372
this.results = []
373373
this.searching = false
@@ -382,7 +382,7 @@ export default defineComponent({
382382
383383
this.searching = true
384384
const newResults = []
385-
const providersToSearch = this.filteredProviders.length > 0 ? this.filteredProviders : this.providers
385+
const providersToSearch = providersToSearchOverride || (this.filteredProviders.length > 0 ? this.filteredProviders : this.providers)
386386
const searchProvider = (provider) => {
387387
const params = {
388388
type: provider.searchFrom ?? provider.id,
@@ -424,6 +424,7 @@ export default defineComponent({
424424
newResults.push({
425425
...provider,
426426
results: response.data.ocs.data.entries,
427+
limit: params.limit ?? 5,
427428
})
428429
429430
unifiedSearchLogger.debug('Unified search results:', { results: this.results, newResults })
@@ -513,15 +514,7 @@ export default defineComponent({
513514
},
514515
async loadMoreResultsForProvider(provider) {
515516
this.providerResultLimit += 5
516-
// Remove all other providers from filteredProviders except the current "loadmore" provider
517-
this.filteredProviders = this.filteredProviders.filter(filteredProvider => filteredProvider.id === provider.id)
518-
// Plugin filters may have extra parameters, so we need to keep them
519-
// See method handlePluginFilter for more details
520-
if (this.filteredProviders.length > 0 && this.filteredProviders[0].isPluginFilter) {
521-
provider = this.filteredProviders[0]
522-
}
523-
this.addProviderFilter(provider, true)
524-
this.find(this.searchQuery)
517+
this.find(this.searchQuery, [provider])
525518
},
526519
addProviderFilter(providerFilter, loadMoreResultsForProvider = false) {
527520
unifiedSearchLogger.debug('Applying provider filter', { providerFilter, loadMoreResultsForProvider })

0 commit comments

Comments
 (0)