From fc903e7942232e6c1a548ec1e6e9983974624c2b Mon Sep 17 00:00:00 2001 From: Vincent Vanwaelscappel Date: Tue, 22 Feb 2022 16:38:38 +0100 Subject: [PATCH] wip #5120 --- resources/js/search.js | 41 +++++++++++++++-------------------------- 1 file changed, 15 insertions(+), 26 deletions(-) diff --git a/resources/js/search.js b/resources/js/search.js index 93e55d7..fc97c5f 100644 --- a/resources/js/search.js +++ b/resources/js/search.js @@ -14,9 +14,10 @@ export default () => ({ prefix: true, // Allow partial matches processTerm: (term, _fieldName) => term.length < 3 ? null : term.toLowerCase() }, - }, - querystring: '', // The search query + }, querystring: '', // The search query query: '', // The search query + results:[], + resultCount:0, medialibrary: '', // Holds URL of the media library that is passed in from the component async init() { @@ -51,31 +52,19 @@ export default () => ({ return `${result.title}`; }, - doSearch(){ - this.query=this.querystring; - }, - - get results() { - if (this.query.length < 3) { - return []; + doSearch() { + this.query = this.querystring; + this.results = []; + if (this.query.length >= 3) { + this.results = this.miniSearch.search(this.query); + if (this.results.length === 1) { + this.resultCount = '1 résultat' + } else { + this.resultCount = this.results.length + ' résultats'; + } + } else { + this.resultCount = "Veuillez taper au moins 3 caractères"; } - - return this.miniSearch.search(this.query); - }, - - get showResults() { - return false; - }, - - get resultCount() { - if (this.query.length < 3) { - return "Veuillez taper au moins 3 caractères"; - } - if (this.results.length === 1) { - return '1 résultat' - } - - return `${this.results.length} résultats`; }, }); -- 2.39.5