mirror of
https://github.com/discourse/discourse.git
synced 2025-03-09 14:34:35 +00:00
FIX: Discard old search results if search term changes when moving posts to a different topic (#14117)
This also fixes an incorrect usage of `debounce`. Meta topic: https://meta.discourse.org/t/odd-search-behaviour-when-moving-messages-as-a-staff-member/201261?u=osama.
This commit is contained in:
parent
a230362f65
commit
19632ecfbb
@ -4,6 +4,7 @@ import discourseDebounce from "discourse-common/lib/debounce";
|
||||
import { isEmpty } from "@ember/utils";
|
||||
import { next, schedule } from "@ember/runloop";
|
||||
import { searchForTerm } from "discourse/lib/search";
|
||||
import { INPUT_DELAY } from "discourse-common/config/environment";
|
||||
|
||||
export default Component.extend({
|
||||
loading: null,
|
||||
@ -68,7 +69,7 @@ export default Component.extend({
|
||||
oldTopicTitle: this.topicTitle,
|
||||
});
|
||||
|
||||
this.search(this.topicTitle);
|
||||
this.searchDebounced(this.topicTitle);
|
||||
},
|
||||
|
||||
@discourseComputed("label")
|
||||
@ -85,10 +86,11 @@ export default Component.extend({
|
||||
this.set("loading", false);
|
||||
},
|
||||
|
||||
searchDebounced(title) {
|
||||
discourseDebounce(this, this.search, title, INPUT_DELAY);
|
||||
},
|
||||
|
||||
search(title) {
|
||||
discourseDebounce(
|
||||
this,
|
||||
function () {
|
||||
if (!this.element || this.isDestroying || this.isDestroyed) {
|
||||
return;
|
||||
}
|
||||
@ -109,12 +111,15 @@ export default Component.extend({
|
||||
}
|
||||
|
||||
searchForTerm(titleWithFilters, searchParams).then((results) => {
|
||||
// search term changed after the request was fired but before we
|
||||
// got a response, ignore results.
|
||||
if (title !== this.topicTitle) {
|
||||
return;
|
||||
}
|
||||
if (results && results.posts && results.posts.length > 0) {
|
||||
this.set(
|
||||
"topics",
|
||||
results.posts
|
||||
.mapBy("topic")
|
||||
.filter((t) => t.id !== currentTopicId)
|
||||
results.posts.mapBy("topic").filter((t) => t.id !== currentTopicId)
|
||||
);
|
||||
if (this.topics.length === 1) {
|
||||
this.send("chooseTopic", this.topics[0]);
|
||||
@ -124,10 +129,6 @@ export default Component.extend({
|
||||
}
|
||||
});
|
||||
},
|
||||
title,
|
||||
300
|
||||
);
|
||||
},
|
||||
|
||||
actions: {
|
||||
chooseTopic(topic) {
|
||||
|
Loading…
x
Reference in New Issue
Block a user