From fd3a8583dd5c5f18c3f91839555744fa251586a6 Mon Sep 17 00:00:00 2001 From: Robin Ward Date: Tue, 9 Aug 2016 15:11:58 -0400 Subject: [PATCH] UX: Display a message when the search term is too short on full page --- .../controllers/full-page-search.js.es6 | 30 +++++++++---------- .../discourse/templates/full-page-search.hbs | 10 +++++-- .../stylesheets/common/base/search.scss | 4 +++ config/locales/client.en.yml | 1 + 4 files changed, 27 insertions(+), 18 deletions(-) diff --git a/app/assets/javascripts/discourse/controllers/full-page-search.js.es6 b/app/assets/javascripts/discourse/controllers/full-page-search.js.es6 index b2a5aeaeca9..b33f338f6fb 100644 --- a/app/assets/javascripts/discourse/controllers/full-page-search.js.es6 +++ b/app/assets/javascripts/discourse/controllers/full-page-search.js.es6 @@ -26,6 +26,7 @@ export default Ember.Controller.extend({ searching: false, sortOrder: 0, sortOrders: SortOrders, + invalidSearch: false, @computed('model.posts') resultCount(posts) { @@ -69,11 +70,6 @@ export default Ember.Controller.extend({ return isValidSearchTerm(q); }, - @computed('searchTerm', 'searching') - searchButtonDisabled(searchTerm, searching) { - return !!(searching || !isValidSearchTerm(searchTerm)); - }, - @computed('q') noSortQ(q) { if (q) { @@ -107,7 +103,7 @@ export default Ember.Controller.extend({ @observes('sortOrder') triggerSearch() { if (this._searchOnSortChange) { - this.search(); + this._search(); } }, @@ -147,14 +143,21 @@ export default Ember.Controller.extend({ return this.currentUser && !this.site.mobileView; }, - search(){ - if (this.get("searching")) return; - this.set("searching", true); + _search() { + if (this.get("searching")) { return; } + this.set('invalidSearch', false); + const searchTerm = this.get('searchTerm'); + if (!isValidSearchTerm(searchTerm)) { + this.set('invalidSearch', true); + return; + } + + this.set("searching", true); this.set('bulkSelectEnabled', false); this.get('selected').clear(); - var args = { q: this.get("searchTerm") }; + var args = { q: searchTerm }; const sortOrder = this.get("sortOrder"); if (sortOrder && SortOrders[sortOrder].term) { @@ -203,18 +206,13 @@ export default Ember.Controller.extend({ this.get('selected').clear(); }, - refresh() { - this.search(); - }, - showSearchHelp() { // TODO: dupe code should be centralized ajax("/static/search_help.html", { dataType: 'html' }).then(model => showModal('searchHelp', { model })); }, search() { - if (this.get("searchButtonDisabled")) return; - this.search(); + this._search(); } } }); diff --git a/app/assets/javascripts/discourse/templates/full-page-search.hbs b/app/assets/javascripts/discourse/templates/full-page-search.hbs index d4409563158..5a57cfa87bc 100644 --- a/app/assets/javascripts/discourse/templates/full-page-search.hbs +++ b/app/assets/javascripts/discourse/templates/full-page-search.hbs @@ -1,6 +1,6 @@ @@ -19,6 +19,12 @@ {{/if}} +{{#if invalidSearch}} +
+ {{i18n "search.too_short"}} +
+{{/if}} + {{#if context}}