fix: edge case in category filter

selecting a category and then clicking on all categories was breaking selection icons
isekai-main
Barış Soner Uşaklı 2 years ago
parent 160b891979
commit 5daaa5ea78

@ -70,6 +70,9 @@ define('categoryFilter', ['categorySearch', 'api', 'hooks'], function (categoryS
const icon = categoryEl.find('[component="category/select/icon"]'); const icon = categoryEl.find('[component="category/select/icon"]');
if (cid !== 'all') { if (cid !== 'all') {
if (selectedCids.includes('all')) {
selectedCids.splice(selectedCids.indexOf('all'), 1);
}
if (selectedCids.includes(cid)) { if (selectedCids.includes(cid)) {
selectedCids.splice(selectedCids.indexOf(cid), 1); selectedCids.splice(selectedCids.indexOf(cid), 1);
} else { } else {
@ -78,14 +81,19 @@ define('categoryFilter', ['categorySearch', 'api', 'hooks'], function (categoryS
selectedCids.sort(function (a, b) { selectedCids.sort(function (a, b) {
return 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 { } else {
el.find('[component="category/select/icon"]').addClass('invisible'); el.find('[component="category/select/icon"]').addClass('invisible');
selectedCids = [cid]; listEl.find('[data-cid="all"] i').removeClass('invisible');
selectedCids = ['all'];
} }
options.selectedCids = selectedCids; options.selectedCids = selectedCids;
listEl.find('[data-cid="all"] i').toggleClass('invisible', !!selectedCids.length);
icon.toggleClass('invisible');
if (options.onSelect) { if (options.onSelect) {
options.onSelect({ cid: cid, selectedCids: selectedCids.slice() }); options.onSelect({ cid: cid, selectedCids: selectedCids.slice() });
} }

@ -129,7 +129,8 @@ searchController.search = async function (req, res, next) {
), ),
}, },
categories: { 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), label: await buildSelectedCategoryLabel(searchData.selectedCids),
}, },
}; };

Loading…
Cancel
Save