Node.js based forum software built for the modern web
fix: edge case in category filter
Barış Soner Uşaklı5daaa5ea78ed
diff --git a/public/src/modules/categoryFilter.js b/public/src/modules/categoryFilter.jsindex 284c735448..271bf83448 100644--- a/public/src/modules/categoryFilter.js+++ b/public/src/modules/categoryFilter.js@@ -70,6 +70,9 @@ define('categoryFilter', ['categorySearch', 'api', 'hooks'], function (categorySconst 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 (categorySselectedCids.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() });}diff --git a/src/controllers/search.js b/src/controllers/search.jsindex 49fd58a6dc..a12c433edd 100644--- a/src/controllers/search.js+++ b/src/controllers/search.js@@ -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),},};