mirror of
https://github.com/NodeBB/NodeBB.git
synced 2025-10-28 01:26:16 +01:00
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
This commit is contained in:
@@ -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,
|
||||
});
|
||||
}
|
||||
|
||||
|
||||
@@ -4,7 +4,7 @@ define('categorySearch', ['alerts', 'bootstrap', 'api'], function (alerts, boots
|
||||
const 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'];
|
||||
|
||||
Reference in New Issue
Block a user