Skip to content

Commit

Permalink
FIX: ensures search-menu is not briefly showing previous results (#9272)
Browse files Browse the repository at this point in the history
  • Loading branch information
jjaffeux committed Mar 25, 2020
1 parent 70012f2 commit cff9d47
Showing 1 changed file with 14 additions and 11 deletions.
25 changes: 14 additions & 11 deletions app/assets/javascripts/discourse/widgets/search-menu.js
@@ -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";
Expand Down Expand Up @@ -27,7 +27,7 @@ const SearchHelper = {
// for cancelling debounced search
cancel() {
if (this._activeSearch) {
cancel(this._activeSearch);
this._activeSearch.abort();
this._activeSearch = null;
}
},
Expand Down Expand Up @@ -55,21 +55,24 @@ const SearchHelper = {
});
this._activeSearch
.then(content => {
searchData.noResults = content.resultTypes.length === 0;
searchData.results = content;

if (searchContext && searchContext.type === "topic") {
widget.appEvents.trigger("post-stream:refresh", { force: true });
searchData.topicId = searchContext.id;
} else {
searchData.topicId = null;
// 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;

if (searchContext && searchContext.type === "topic") {
widget.appEvents.trigger("post-stream:refresh", { force: true });
searchData.topicId = searchContext.id;
} else {
searchData.topicId = null;
}
}
})
.catch(popupAjaxError)
.finally(() => {
searchData.loading = false;
widget.scheduleRerender();
this._activeSearch = null;
});
}
}
Expand Down

0 comments on commit cff9d47

Please sign in to comment.