FIX: the empty state message was appearing in wrong moments on the user bookmarks stage (#14127)

FIX: the empty state message was appearing in wrong moments on the user bookmarks stage (#14127)

Steps to reproduce:

  1. Go to activity/bookmarks
  2. Search for something that isn’t in your bookmarks, so you get no results
  3. Navigate away and then click “Bookmarked” on the sidebar or open the user menu and click the View All Bookmarks button on the bottom of the bookmarks tab, and you get the message “You haven’t bookmarked anything yet”.

This commit fixes the problem. We have a controller with a query parameter q that contains a search query. And we also have a property searchTerm that is bound to the search box on the page and mirrors the value in q. We were using a value from searchTerm when querying the server, but ember controllers are singletons so the searchTerm value persisted between page visits and leaded to this bug.

To make things work properly, we should be using the value from q everywhere except two places when we copy a value from q to searchTerm and vice versa.

diff --git a/app/assets/javascripts/discourse/app/controllers/user-activity-bookmarks.js b/app/assets/javascripts/discourse/app/controllers/user-activity-bookmarks.js
index 8df706e..c80cfc0 100644
--- a/app/assets/javascripts/discourse/app/controllers/user-activity-bookmarks.js
+++ b/app/assets/javascripts/discourse/app/controllers/user-activity-bookmarks.js
@@ -25,14 +25,11 @@ export default Controller.extend({
       content: [],
       loading: true,
       permissionDenied: false,
+      searchTerm: this.q,
     });
 
-    if (this.q && !this.searchTerm) {
-      this.set("searchTerm", this.q);
-    }
-
     return this.model
-      .loadItems({ q: this.searchTerm })
+      .loadItems({ q: this.q })
       .then((response) => this._processLoadResponse(response))
       .catch(() => this._bookmarksListDenied())
       .finally(() => {
@@ -85,7 +82,7 @@ export default Controller.extend({
     this.set("loadingMore", true);
 
     return this.model
-      .loadMore({ q: this.searchTerm })
+      .loadMore({ q: this.q })
       .then((response) => this._processLoadResponse(response))
       .catch(() => this._bookmarksListDenied())
       .finally(() => this.set("loadingMore", false));

GitHub sha: 4d5f5a67c112ec4451641c816e0ade7e4120bd47

This commit appears in #14127 which was approved by jjaffeux. It was merged by AndrewPrigorshnev.