Skip to content

Commit 93eb584

Browse files
committed
Make typeahead and search limit/length configurable
Signed-off-by: Julius Härtl <jus@bitgrid.net>
1 parent de72801 commit 93eb584

File tree

5 files changed

+36
-11
lines changed

5 files changed

+36
-11
lines changed

core/src/services/UnifiedSearchService.js

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,9 @@ import { loadState } from '@nextcloud/initial-state'
2828
import axios from '@nextcloud/axios'
2929

3030
export const defaultLimit = loadState('unified-search', 'limit-default')
31-
export const minSearchLength = 2
31+
export const minSearchLength = loadState('unified-search', 'min-search-length', 2)
32+
export const enableLiveSearch = loadState('unified-search', 'live-search', true)
33+
3234
export const regexFilterIn = /[^-]in:([a-z_-]+)/ig
3335
export const regexFilterNot = /-in:([a-z_-]+)/ig
3436

core/src/views/UnifiedSearch.vue

Lines changed: 27 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -57,6 +57,12 @@
5757
class="unified-search__form-reset icon-close"
5858
:aria-label="t('core','Reset search')"
5959
value="">
60+
61+
<input v-if="!!query && !isLoading && !enableLiveSearch"
62+
type="submit"
63+
class="unified-search__form-submit icon-confirm"
64+
:aria-label="t('core','Start search')"
65+
value="">
6066
</form>
6167

6268
<!-- Search filters -->
@@ -76,7 +82,10 @@
7682
<SearchResultPlaceholders v-if="isLoading" />
7783

7884
<EmptyContent v-else-if="isValidQuery" icon="icon-search">
79-
<Highlight :text="t('core', 'No results for {query}', { query })" :search="query" />
85+
<Highlight v-if="triggered" :text="t('core', 'No results for {query}', { query })" :search="query" />
86+
<div v-else>
87+
{{ t('core', 'Press enter to start searching') }}
88+
</div>
8089
</EmptyContent>
8190

8291
<EmptyContent v-else-if="!isLoading || isShortQuery" icon="icon-search">
@@ -124,7 +133,7 @@
124133

125134
<script>
126135
import { emit } from '@nextcloud/event-bus'
127-
import { minSearchLength, getTypes, search, defaultLimit, regexFilterIn, regexFilterNot } from '../services/UnifiedSearchService'
136+
import { minSearchLength, getTypes, search, defaultLimit, regexFilterIn, regexFilterNot, enableLiveSearch } from '../services/UnifiedSearchService'
128137
import { showError } from '@nextcloud/dialogs'
129138
130139
import ActionButton from '@nextcloud/vue/dist/Components/ActionButton'
@@ -175,9 +184,11 @@ export default {
175184
176185
query: '',
177186
focused: null,
187+
triggered: false,
178188
179189
defaultLimit,
180190
minSearchLength,
191+
enableLiveSearch,
181192
182193
open: false,
183194
}
@@ -354,6 +365,7 @@ export default {
354365
this.reached = {}
355366
this.results = {}
356367
this.focused = null
368+
this.triggered = false
357369
await this.cancelPendingRequests()
358370
},
359371
@@ -422,6 +434,7 @@ export default {
422434
423435
// Reset search if the query changed
424436
await this.resetState()
437+
this.triggered = true
425438
this.$set(this.loading, 'all', true)
426439
this.logger.debug(`Searching ${query} in`, types)
427440
@@ -481,9 +494,13 @@ export default {
481494
this.loading = {}
482495
})
483496
},
484-
onInputDebounced: debounce(function(e) {
485-
this.onInput(e)
486-
}, 500),
497+
onInputDebounced: enableLiveSearch
498+
? debounce(function(e) {
499+
this.onInput(e)
500+
}, 500)
501+
: function() {
502+
this.triggered = false
503+
},
487504
488505
/**
489506
* Load more results for the provided type
@@ -728,7 +745,7 @@ $input-padding: 6px;
728745
}
729746
}
730747
731-
&-reset {
748+
&-reset, &-submit {
732749
position: absolute;
733750
top: 0;
734751
right: 0;
@@ -746,6 +763,10 @@ $input-padding: 6px;
746763
opacity: 1;
747764
}
748765
}
766+
767+
&-submit {
768+
right: 28px;
769+
}
749770
}
750771
751772
&__filters {

dist/core-unified-search.js

Lines changed: 2 additions & 2 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

dist/core-unified-search.js.map

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

lib/private/TemplateLayout.php

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -94,7 +94,9 @@ public function __construct($renderAs, $appId = '') {
9494
}
9595

9696
$this->initialState->provideInitialState('core', 'active-app', $this->navigationManager->getActiveEntry());
97-
$this->initialState->provideInitialState('unified-search', 'limit-default', SearchQuery::LIMIT_DEFAULT);
97+
$this->initialState->provideInitialState('unified-search', 'limit-default', (int)$this->config->getAppValue('core', 'unified-search.limit-default', (string)SearchQuery::LIMIT_DEFAULT));
98+
$this->initialState->provideInitialState('unified-search', 'min-search-length', (int)$this->config->getAppValue('core', 'unified-search.min-search-length', (string)2));
99+
$this->initialState->provideInitialState('unified-search', 'live-search', $this->config->getAppValue('core', 'unified-search.live-search', 'yes') === 'yes');
98100
Util::addScript('core', 'unified-search', 'core');
99101

100102
// set logo link target

0 commit comments

Comments
 (0)