fixed the result filters problem all button sometimes not working as intended

This commit is contained in:
Jack 2021-06-01 19:35:51 +01:00
parent c51186af58
commit ffcd0c9545
2 changed files with 18 additions and 3 deletions

View file

@ -74,6 +74,7 @@ Promise.all([Misc.getLanguageList(), Misc.getFunboxList()]).then((values) => {
defaultResultFilters.funbox[funbox.name] = true;
});
// filters = defaultResultFilters;
load();
});
export function getFilters() {
@ -110,7 +111,12 @@ export function load() {
// let newTags = $.cookie("activeTags");
try {
let newResultFilters = window.localStorage.getItem("resultFilters");
if (newResultFilters != undefined && newResultFilters !== "") {
if (
newResultFilters != undefined &&
newResultFilters !== "" &&
Misc.countAllKeys(newResultFilters) >=
Misc.countAllKeys(defaultResultFilters)
) {
filters = JSON.parse(newResultFilters);
save();
} else {
@ -129,8 +135,6 @@ export function reset() {
save();
}
load();
export function updateActive() {
let aboveChartDisplay = {};
Object.keys(getFilters()).forEach((group) => {

View file

@ -726,3 +726,14 @@ export function setCharAt(str, index, chr) {
if (index > str.length - 1) return str;
return str.substring(0, index) + chr + str.substring(index + 1);
}
//https://www.reddit.com/r/learnjavascript/comments/8ohug3/how_to_recursively_count_keys_in_an_object/e03fytn/
function countAllKeys(obj) {
if (typeof obj !== "object" || obj === null) {
return 0;
}
const keys = Object.keys(obj);
let sum = keys.length;
keys.forEach((key) => (sum += countAllKeys(obj[key])));
return sum;
}