From 4d5f5a67c112ec4451641c816e0ade7e4120bd47 Mon Sep 17 00:00:00 2001 From: Andrei Prigorshnev Date: Tue, 24 Aug 2021 23:40:08 +0400 Subject: [PATCH] FIX: the empty state message was appearing in wrong moments on the user bookmarks stage (#14127) MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit 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. --- .../discourse/app/controllers/user-activity-bookmarks.js | 9 +++------ 1 file changed, 3 insertions(+), 6 deletions(-) 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 8df706ef2c8..c80cfc070ad 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));