mirror of
https://github.com/discourse/discourse.git
synced 2025-09-06 10:50:21 +08:00
FIX: cancel in progress search when flipping to full search
This commit is contained in:
parent
c2fd93ffa8
commit
12b6d8a032
2 changed files with 34 additions and 5 deletions
|
@ -85,20 +85,32 @@ export default Em.Controller.extend(Presence, {
|
||||||
searchTerm: function(term, typeFilter) {
|
searchTerm: function(term, typeFilter) {
|
||||||
var self = this;
|
var self = this;
|
||||||
|
|
||||||
|
// for cancelling debounced search
|
||||||
|
if (this._cancelSearch){
|
||||||
|
this._cancelSearch = null;
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (this._search) {
|
||||||
|
this._search.abort();
|
||||||
|
}
|
||||||
|
|
||||||
var context;
|
var context;
|
||||||
if(this.get('searchContextEnabled')){
|
if(this.get('searchContextEnabled')){
|
||||||
context = this.get('searchContext');
|
context = this.get('searchContext');
|
||||||
}
|
}
|
||||||
|
|
||||||
searchForTerm(term, {
|
this._search = searchForTerm(term, {
|
||||||
typeFilter: typeFilter,
|
typeFilter: typeFilter,
|
||||||
searchContext: context,
|
searchContext: context,
|
||||||
fullSearchUrl: this.get('fullSearchUrl')
|
fullSearchUrl: this.get('fullSearchUrl')
|
||||||
}).then(function(results) {
|
});
|
||||||
|
|
||||||
|
this._search.then(function(results) {
|
||||||
self.setProperties({ noResults: !results, content: results });
|
self.setProperties({ noResults: !results, content: results });
|
||||||
|
}).finally(function() {
|
||||||
self.set('loading', false);
|
self.set('loading', false);
|
||||||
}).catch(function() {
|
self._search = null;
|
||||||
self.set('loading', false);
|
|
||||||
});
|
});
|
||||||
},
|
},
|
||||||
|
|
||||||
|
@ -113,6 +125,19 @@ export default Em.Controller.extend(Presence, {
|
||||||
|
|
||||||
actions: {
|
actions: {
|
||||||
fullSearch: function() {
|
fullSearch: function() {
|
||||||
|
const self = this;
|
||||||
|
|
||||||
|
if (this._search) {
|
||||||
|
this._search.abort();
|
||||||
|
}
|
||||||
|
|
||||||
|
// maybe we are debounced and delayed
|
||||||
|
// stop that as well
|
||||||
|
this._cancelSearch = true;
|
||||||
|
Em.run.later(function(){
|
||||||
|
self._cancelSearch = false;
|
||||||
|
}, 400);
|
||||||
|
|
||||||
var url = this.get('fullSearchUrlRelative');
|
var url = this.get('fullSearchUrlRelative');
|
||||||
if (url) {
|
if (url) {
|
||||||
Discourse.URL.routeTo(url);
|
Discourse.URL.routeTo(url);
|
||||||
|
|
|
@ -77,9 +77,13 @@ function searchForTerm(term, opts) {
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
return Discourse.ajax('/search/query', { data: data }).then(function(results){
|
var promise = Discourse.ajax('/search/query', { data: data });
|
||||||
|
|
||||||
|
promise.then(function(results){
|
||||||
return translateResults(results, opts);
|
return translateResults(results, opts);
|
||||||
});
|
});
|
||||||
|
|
||||||
|
return promise;
|
||||||
}
|
}
|
||||||
|
|
||||||
export default searchForTerm;
|
export default searchForTerm;
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue