FIX: make update banner always available on the categories view (#14431)

This commit is contained in:
Jean 2021-09-23 13:10:05 -04:00 committed by GitHub
parent 8115e5ef76
commit fd0e287da6
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
1 changed files with 31 additions and 31 deletions

View File

@ -43,7 +43,35 @@ const DiscoveryCategoriesRoute = DiscourseRoute.extend(OpenComposer, {
return model; 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) { _findCategoriesAndTopics(filter) {
return hash({ return hash({
wrappedCategoriesList: PreloadStore.getAndRemove("categories_list"), wrappedCategoriesList: PreloadStore.getAndRemove("categories_list"),
@ -52,51 +80,22 @@ const DiscoveryCategoriesRoute = DiscourseRoute.extend(OpenComposer, {
let { wrappedCategoriesList, topicsList } = response; let { wrappedCategoriesList, topicsList } = response;
let categoriesList = let categoriesList =
wrappedCategoriesList && wrappedCategoriesList.category_list; wrappedCategoriesList && wrappedCategoriesList.category_list;
let store = this.store;
if (categoriesList && topicsList) { if (categoriesList && topicsList) {
if (topicsList.topic_list && topicsList.topic_list.top_tags) { if (topicsList.topic_list && topicsList.topic_list.top_tags) {
Site.currentProp("top_tags", topicsList.topic_list.top_tags); Site.currentProp("top_tags", topicsList.topic_list.top_tags);
} }
let store = this.store;
return EmberObject.create({ return EmberObject.create({
categories: CategoryList.categoriesFrom( categories: CategoryList.categoriesFrom(
this.store, this.store,
wrappedCategoriesList 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), topics: TopicList.topicsFrom(this.store, topicsList),
can_create_category: categoriesList.can_create_category, can_create_category: categoriesList.can_create_category,
can_create_topic: categoriesList.can_create_topic, can_create_topic: categoriesList.can_create_topic,
loadBefore: this._loadBefore(store),
}); });
} }
// Otherwise, return the ajax result // Otherwise, return the ajax result
@ -110,6 +109,7 @@ const DiscoveryCategoriesRoute = DiscourseRoute.extend(OpenComposer, {
topics: TopicList.topicsFrom(this.store, result), topics: TopicList.topicsFrom(this.store, result),
can_create_category: result.category_list.can_create_category, can_create_category: result.category_list.can_create_category,
can_create_topic: result.category_list.can_create_topic, can_create_topic: result.category_list.can_create_topic,
loadBefore: this._loadBefore(store),
}); });
}); });
}); });