FIX: ensures search-menu is not briefly showing previous results (#9272)

This commit is contained in:
Joffrey JAFFEUX 2020-03-25 10:00:48 +01:00 committed by GitHub
parent 70012f2027
commit cff9d4726c
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
1 changed files with 13 additions and 10 deletions

View File

@ -1,5 +1,5 @@
import { get } from "@ember/object";
import { debounce, cancel } from "@ember/runloop";
import { debounce } from "@ember/runloop";
import { popupAjaxError } from "discourse/lib/ajax-error";
import { searchForTerm, isValidSearchTerm } from "discourse/lib/search";
import { createWidget } from "discourse/widgets/widget";
@ -27,7 +27,7 @@ const SearchHelper = {
// for cancelling debounced search
cancel() {
if (this._activeSearch) {
cancel(this._activeSearch);
this._activeSearch.abort();
this._activeSearch = null;
}
},
@ -55,6 +55,9 @@ const SearchHelper = {
});
this._activeSearch
.then(content => {
// we ensure the current search term is the one used
// when starting the query
if (term === searchData.term) {
searchData.noResults = content.resultTypes.length === 0;
searchData.results = content;
@ -64,12 +67,12 @@ const SearchHelper = {
} else {
searchData.topicId = null;
}
}
})
.catch(popupAjaxError)
.finally(() => {
searchData.loading = false;
widget.scheduleRerender();
this._activeSearch = null;
});
}
}