Node.js based forum software built for the modern web
feat: add new option to categorySearch module, `defaultCategories`, use to populate the category list when you don't want to poll backend for the main category list
Julian Lama487d5f6f2c5
diff --git a/public/src/client/unread.js b/public/src/client/unread.jsindex c2e8903127..5ed9eed5c8 100644--- a/public/src/client/unread.js+++ b/public/src/client/unread.js@@ -61,6 +61,17 @@ define('forum/unread', [doneRemovingTids(tids);});}++ // Generate list of default categories based on topic list+ let defaultCategories = ajaxify.data.topics.reduce((map, topic) => {+ const { category }= topic;+ let { cid } = category;+ cid = utils.isNumber(cid) ? parseInt(cid, 10) : cid;+ map.set(cid, category);+ return map;+ }, new Map());+ defaultCategories = Array.from(defaultCategories.values());+const selector = categorySelector.init($('[component="category-selector"]'), {onSelect: function (category) {selector.selectCategory(0);@@ -85,6 +96,7 @@ define('forum/unread', [icon: '',},],+ defaultCategories,});}diff --git a/public/src/modules/categorySearch.js b/public/src/modules/categorySearch.jsindex 8fa7a9f184..7840a859d7 100644--- a/public/src/modules/categorySearch.js+++ b/public/src/modules/categorySearch.js@@ -4,7 +4,7 @@ define('categorySearch', ['alerts', 'bootstrap', 'api'], function (alerts, bootsconst categorySearch = {};categorySearch.init = function (el, options) {- let categoriesList = null;+ let categoriesList = options.defaultCategories || null;options = options || {};options.privilege = options.privilege || 'topics:read';options.states = options.states || ['watching', 'tracking', 'notwatching', 'ignoring'];