Skip to content

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

FIX: Top site categories are displayed in random order

Vinoth Kannanc1e62808ed37
diff --git a/app/assets/javascripts/discourse/widgets/hamburger-menu.js.es6 b/app/assets/javascripts/discourse/widgets/hamburger-menu.js.es6
index e8e2fed85c6..0c361e7c1f7 100644
--- a/app/assets/javascripts/discourse/widgets/hamburger-menu.js.es6
+++ b/app/assets/javascripts/discourse/widgets/hamburger-menu.js.es6
@@ -179,40 +179,36 @@ export default createWidget("hamburger-menu", {
listCategories() {
const maxCategoriesToDisplay = this.siteSettings
.hamburger_menu_categories_count;
- const categoriesByCount = this.site.get("categoriesByCount");
- let categories = categoriesByCount.slice();
+ let categories = this.site.get("categoriesByCount");
if (this.currentUser) {
- let unreadCategoryIds = [];
- let topCategoryIds = this.currentUser.get("top_category_ids") || [];
- let i = 0;
+ const allCategories = this.site
+ .get("categories")
+ .filter(c => c.notification_level !== NotificationLevels.MUTED);
- categoriesByCount
+ categories = allCategories
+ .filter(c => c.get("newTopics") > 0 || c.get("unreadTopics") > 0)
.sort((a, b) => {
return (
b.get("newTopics") +
b.get("unreadTopics") -
(a.get("newTopics") + a.get("unreadTopics"))
);
- })
- .forEach(c => {
- if (c.get("newTopics") > 0 || c.get("unreadTopics") > 0) {
- unreadCategoryIds.push(c.id);
- }
});
- categories = categories.filter(
- c => c.notification_level !== NotificationLevels.MUTED
- );
-
- [...unreadCategoryIds, ...topCategoryIds].uniq().forEach(id => {
- const category = categories.find(c => c.id === id);
- if (category) {
- categories = categories.filter(c => c.id !== id);
- categories.splice(i, 0, category);
- i += 1;
+ const topCategoryIds = this.currentUser.get("top_category_ids") || [];
+ topCategoryIds.forEach(id => {
+ const category = allCategories.find(c => c.id === id);
+ if (category && !categories.includes(category)) {
+ categories.push(category);
}
});
+
+ categories = categories.concat(
+ allCategories
+ .filter(c => !categories.includes(c))
+ .sort((a, b) => b.topic_count - a.topic_count)
+ );
}
const moreCount = categories.length - maxCategoriesToDisplay;