From fd0e287da6720daba60a862279ee0f24d914f89d Mon Sep 17 00:00:00 2001 From: Jean Date: Thu, 23 Sep 2021 13:10:05 -0400 Subject: [PATCH] FIX: make update banner always available on the categories view (#14431) --- .../app/routes/discovery-categories.js | 62 +++++++++---------- 1 file changed, 31 insertions(+), 31 deletions(-) diff --git a/app/assets/javascripts/discourse/app/routes/discovery-categories.js b/app/assets/javascripts/discourse/app/routes/discovery-categories.js index 92081b73c52..aeb2351552f 100644 --- a/app/assets/javascripts/discourse/app/routes/discovery-categories.js +++ b/app/assets/javascripts/discourse/app/routes/discovery-categories.js @@ -43,7 +43,35 @@ const DiscoveryCategoriesRoute = DiscourseRoute.extend(OpenComposer, { return model; }); }, + _loadBefore(store) { + return function (topic_ids, storeInSession) { + // refresh dupes + this.topics.removeObjects( + this.topics.filter((topic) => topic_ids.indexOf(topic.id) >= 0) + ); + const url = `${getURL("/")}latest.json?topic_ids=${topic_ids.join(",")}`; + + return ajax({ url, data: this.params }).then((result) => { + const topicIds = []; + + this.topics.forEach((topic) => (topicIds[topic.id] = true)); + + let i = 0; + TopicList.topicsFrom(store, result).forEach((topic) => { + if (!topicIds[topic.id]) { + topic.set("highlight", true); + this.topics.insertAt(i, topic); + i++; + } + }); + + if (storeInSession) { + Session.currentProp("topicList", this); + } + }); + }; + }, _findCategoriesAndTopics(filter) { return hash({ wrappedCategoriesList: PreloadStore.getAndRemove("categories_list"), @@ -52,51 +80,22 @@ const DiscoveryCategoriesRoute = DiscourseRoute.extend(OpenComposer, { let { wrappedCategoriesList, topicsList } = response; let categoriesList = wrappedCategoriesList && wrappedCategoriesList.category_list; + let store = this.store; if (categoriesList && topicsList) { if (topicsList.topic_list && topicsList.topic_list.top_tags) { Site.currentProp("top_tags", topicsList.topic_list.top_tags); } - let store = this.store; - return EmberObject.create({ categories: CategoryList.categoriesFrom( this.store, wrappedCategoriesList ), - loadBefore: function (topic_ids, storeInSession) { - // refresh dupes - this.topics.removeObjects( - this.topics.filter((topic) => topic_ids.indexOf(topic.id) >= 0) - ); - - const url = `${getURL("/")}latest.json?topic_ids=${topic_ids.join( - "," - )}`; - - return ajax({ url, data: this.params }).then((result) => { - const topicIds = []; - - this.topics.forEach((topic) => (topicIds[topic.id] = true)); - - let i = 0; - TopicList.topicsFrom(store, result).forEach((topic) => { - if (!topicIds[topic.id]) { - topic.set("highlight", true); - this.topics.insertAt(i, topic); - i++; - } - }); - - if (storeInSession) { - Session.currentProp("topicList", this); - } - }); - }, topics: TopicList.topicsFrom(this.store, topicsList), can_create_category: categoriesList.can_create_category, can_create_topic: categoriesList.can_create_topic, + loadBefore: this._loadBefore(store), }); } // Otherwise, return the ajax result @@ -110,6 +109,7 @@ const DiscoveryCategoriesRoute = DiscourseRoute.extend(OpenComposer, { topics: TopicList.topicsFrom(this.store, result), can_create_category: result.category_list.can_create_category, can_create_topic: result.category_list.can_create_topic, + loadBefore: this._loadBefore(store), }); }); });