Check that char.list has any filters before applying hidden block.

This commit is contained in:
Cohee 2024-04-28 21:33:37 +03:00
parent 73cf58826f
commit 87219f897e
2 changed files with 31 additions and 1 deletions

View File

@ -1363,7 +1363,7 @@ async function printCharacters(fullRefresh = false) {
}
const hidden = (characters.length + groups.length) - displayCount;
if (hidden > 0) {
if (hidden > 0 && entitiesFilter.hasAnyFilter()) {
$(listId).append(getHiddenBlock(hidden));
}

View File

@ -64,6 +64,36 @@ export class FilterHelper {
this.onDataChanged = onDataChanged;
}
/**
* Checks if the filter data has any values.
* @returns {boolean} Whether the filter data has any values
*/
hasAnyFilter() {
/**
* Checks if the object has any values.
* @param {object} obj The object to check for values
* @returns {boolean} Whether the object has any values
*/
function checkRecursive(obj) {
if (typeof obj === 'string' && obj.length > 0 && obj !== 'UNDEFINED') {
return true;
} else if (typeof obj === 'boolean' && obj) {
return true;
} else if (Array.isArray(obj) && obj.length > 0) {
return true;
} else if (typeof obj === 'object' && obj !== null && Object.keys(obj.length > 0)) {
for (const key in obj) {
if (checkRecursive(obj[key])) {
return true;
}
}
}
return false;
}
return checkRecursive(this.filterData);
}
/**
* The filter functions.
* @type {Object.<string, Function>}