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:
Julian Lam
2025-04-08 13:31:23 -04:00
parent 695312f17f
commit a487d5f6f2
2 changed files with 13 additions and 1 deletions

View File

@@ -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,
});
}

View File

@@ -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'];