mirror of
https://github.com/NodeBB/NodeBB.git
synced 2025-10-26 08:36:12 +01:00
fix: edge case in category filter
selecting a category and then clicking on all categories was breaking selection icons
This commit is contained in:
@@ -70,6 +70,9 @@ define('categoryFilter', ['categorySearch', 'api', 'hooks'], function (categoryS
|
||||
const icon = categoryEl.find('[component="category/select/icon"]');
|
||||
|
||||
if (cid !== 'all') {
|
||||
if (selectedCids.includes('all')) {
|
||||
selectedCids.splice(selectedCids.indexOf('all'), 1);
|
||||
}
|
||||
if (selectedCids.includes(cid)) {
|
||||
selectedCids.splice(selectedCids.indexOf(cid), 1);
|
||||
} else {
|
||||
@@ -78,14 +81,19 @@ define('categoryFilter', ['categorySearch', 'api', 'hooks'], function (categoryS
|
||||
selectedCids.sort(function (a, b) {
|
||||
return a - b;
|
||||
});
|
||||
icon.toggleClass('invisible');
|
||||
listEl.find('[data-cid="all"] i').toggleClass('invisible', !!selectedCids.length);
|
||||
if (!selectedCids.length) {
|
||||
selectedCids.push('all');
|
||||
}
|
||||
} else {
|
||||
el.find('[component="category/select/icon"]').addClass('invisible');
|
||||
selectedCids = [cid];
|
||||
listEl.find('[data-cid="all"] i').removeClass('invisible');
|
||||
selectedCids = ['all'];
|
||||
}
|
||||
|
||||
options.selectedCids = selectedCids;
|
||||
listEl.find('[data-cid="all"] i').toggleClass('invisible', !!selectedCids.length);
|
||||
icon.toggleClass('invisible');
|
||||
|
||||
if (options.onSelect) {
|
||||
options.onSelect({ cid: cid, selectedCids: selectedCids.slice() });
|
||||
}
|
||||
|
||||
@@ -129,7 +129,8 @@ searchController.search = async function (req, res, next) {
|
||||
),
|
||||
},
|
||||
categories: {
|
||||
active: !!(Array.isArray(data.categories) && data.categories.length),
|
||||
active: !!(Array.isArray(data.categories) && data.categories.length &&
|
||||
(data.categories.length > 1 || data.categories[0] !== 'all')),
|
||||
label: await buildSelectedCategoryLabel(searchData.selectedCids),
|
||||
},
|
||||
};
|
||||
|
||||
Reference in New Issue
Block a user