FIX: ensures search-menu is not briefly showing previous results (#9272)
This commit is contained in:
parent
70012f2027
commit
cff9d4726c
|
@ -1,5 +1,5 @@
|
||||||
import { get } from "@ember/object";
|
import { get } from "@ember/object";
|
||||||
import { debounce, cancel } from "@ember/runloop";
|
import { debounce } from "@ember/runloop";
|
||||||
import { popupAjaxError } from "discourse/lib/ajax-error";
|
import { popupAjaxError } from "discourse/lib/ajax-error";
|
||||||
import { searchForTerm, isValidSearchTerm } from "discourse/lib/search";
|
import { searchForTerm, isValidSearchTerm } from "discourse/lib/search";
|
||||||
import { createWidget } from "discourse/widgets/widget";
|
import { createWidget } from "discourse/widgets/widget";
|
||||||
|
@ -27,7 +27,7 @@ const SearchHelper = {
|
||||||
// for cancelling debounced search
|
// for cancelling debounced search
|
||||||
cancel() {
|
cancel() {
|
||||||
if (this._activeSearch) {
|
if (this._activeSearch) {
|
||||||
cancel(this._activeSearch);
|
this._activeSearch.abort();
|
||||||
this._activeSearch = null;
|
this._activeSearch = null;
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
|
@ -55,21 +55,24 @@ const SearchHelper = {
|
||||||
});
|
});
|
||||||
this._activeSearch
|
this._activeSearch
|
||||||
.then(content => {
|
.then(content => {
|
||||||
searchData.noResults = content.resultTypes.length === 0;
|
// we ensure the current search term is the one used
|
||||||
searchData.results = content;
|
// when starting the query
|
||||||
|
if (term === searchData.term) {
|
||||||
|
searchData.noResults = content.resultTypes.length === 0;
|
||||||
|
searchData.results = content;
|
||||||
|
|
||||||
if (searchContext && searchContext.type === "topic") {
|
if (searchContext && searchContext.type === "topic") {
|
||||||
widget.appEvents.trigger("post-stream:refresh", { force: true });
|
widget.appEvents.trigger("post-stream:refresh", { force: true });
|
||||||
searchData.topicId = searchContext.id;
|
searchData.topicId = searchContext.id;
|
||||||
} else {
|
} else {
|
||||||
searchData.topicId = null;
|
searchData.topicId = null;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
})
|
})
|
||||||
.catch(popupAjaxError)
|
.catch(popupAjaxError)
|
||||||
.finally(() => {
|
.finally(() => {
|
||||||
searchData.loading = false;
|
searchData.loading = false;
|
||||||
widget.scheduleRerender();
|
widget.scheduleRerender();
|
||||||
this._activeSearch = null;
|
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue