Skip to content

A platform for community discussion. Free, open, simple.

DEV: Move `noResults` to search service (#26084)

Keegan George0bc0efbd0af2
diff --git a/app/assets/javascripts/discourse/app/components/search-menu.hbs b/app/assets/javascripts/discourse/app/components/search-menu.hbs
index b13103587f0..1e88826fc58 100644
--- a/app/assets/javascripts/discourse/app/components/search-menu.hbs
+++ b/app/assets/javascripts/discourse/app/components/search-menu.hbs
@@ -54,7 +54,6 @@
{{#if @inlineResults}}
<SearchMenu::Results
@loading={{this.loading}}
- @noResults={{this.noResults}}
@invalidTerm={{this.invalidTerm}}
@suggestionKeyword={{this.suggestionKeyword}}
@suggestionResults={{this.suggestionResults}}
@@ -70,7 +69,6 @@
<MenuPanel @panelClass="search-menu-panel">
<SearchMenu::Results
@loading={{this.loading}}
- @noResults={{this.noResults}}
@invalidTerm={{this.invalidTerm}}
@suggestionKeyword={{this.suggestionKeyword}}
@suggestionResults={{this.suggestionResults}}
diff --git a/app/assets/javascripts/discourse/app/components/search-menu.js b/app/assets/javascripts/discourse/app/components/search-menu.js
index 426017ff930..9511164e9c3 100644
--- a/app/assets/javascripts/discourse/app/components/search-menu.js
+++ b/app/assets/javascripts/discourse/app/components/search-menu.js
@@ -36,7 +36,6 @@ export default class SearchMenu extends Component {
@service appEvents;
@tracked loading = false;
- @tracked noResults = false;
@tracked
inPMInboxContext = this.search.searchContext?.type === "private_messages";
@tracked typeFilter = DEFAULT_TYPE_FILTER;
@@ -215,7 +214,7 @@ export default class SearchMenu extends Component {
const matchSuggestions = this.matchesSuggestions();
if (matchSuggestions) {
- this.noResults = true;
+ this.search.noResults = true;
this.search.results = {};
this.loading = false;
this.suggestionResults = [];
@@ -253,7 +252,7 @@ export default class SearchMenu extends Component {
this.suggestionResults = result.users;
this.suggestionKeyword = "@";
} else {
- this.noResults = true;
+ this.search.noResults = true;
this.suggestionKeyword = false;
}
});
@@ -266,14 +265,14 @@ export default class SearchMenu extends Component {
this.suggestionKeyword = false;
if (!this.search.activeGlobalSearchTerm) {
- this.noResults = false;
+ this.search.noResults = false;
this.search.results = {};
this.loading = false;
this.invalidTerm = false;
} else if (
!isValidSearchTerm(this.search.activeGlobalSearchTerm, this.siteSettings)
) {
- this.noResults = true;
+ this.search.noResults = true;
this.search.results = {};
this.loading = false;
this.invalidTerm = true;
@@ -298,7 +297,7 @@ export default class SearchMenu extends Component {
});
}
- this.noResults = results.resultTypes.length === 0;
+ this.search.noResults = results.resultTypes.length === 0;
this.search.results = results;
}
})
@@ -339,7 +338,7 @@ export default class SearchMenu extends Component {
@action
triggerSearch() {
- this.noResults = false;
+ this.search.noResults = false;
if (this.includesTopics) {
if (this.search.contextType === "topic") {
diff --git a/app/assets/javascripts/discourse/app/components/search-menu/results.js b/app/assets/javascripts/discourse/app/components/search-menu/results.js
index 4e8d131b796..3be639b32b4 100644
--- a/app/assets/javascripts/discourse/app/components/search-menu/results.js
+++ b/app/assets/javascripts/discourse/app/components/search-menu/results.js
@@ -28,7 +28,7 @@ export default class Results extends Component {
}
get noTopicResults() {
- return this.args.searchTopics && this.args.noResults;
+ return this.args.searchTopics && this.search.noResults;
}
get termTooShort() {
diff --git a/app/assets/javascripts/discourse/app/services/search.js b/app/assets/javascripts/discourse/app/services/search.js
index 758d083abc3..5a236a847ba 100644
--- a/app/assets/javascripts/discourse/app/services/search.js
+++ b/app/assets/javascripts/discourse/app/services/search.js
@@ -14,6 +14,7 @@ export default class Search extends Service {
@tracked inTopicContext = false;
@tracked visible = false;
@tracked results = {};
+ @tracked noResults = false;
// only relative for the widget search menu
searchContextEnabled = false; // checkbox to scope search