Skip to content

Commit

Permalink
fix: Normalize derived options in Encounter Builder options filters
Browse files Browse the repository at this point in the history
  • Loading branch information
valentine195 committed May 9, 2024
1 parent 8bc3ae5 commit 27c4d92
Showing 1 changed file with 10 additions and 4 deletions.
14 changes: 10 additions & 4 deletions src/builder/stores/filter/filter.ts
Original file line number Diff line number Diff line change
Expand Up @@ -109,6 +109,10 @@ const createRangeFilter: FilterFactory<RangeFilter> = (filter) => {
};
};

function normalize(str: string): string {
if (typeof str !== "string") return str;
return str.toLowerCase();
}
const createOptionsFilter: FilterFactory<OptionsFilter> = (filter) => {
const store = writable<string[]>([]);
const { subscribe, set, update } = store;
Expand All @@ -127,9 +131,9 @@ const createOptionsFilter: FilterFactory<OptionsFilter> = (filter) => {
if (typeof value === "number") return false;
const values = get(store);
if (Array.isArray(value)) {
return value.some((v) => values.includes(v));
return value.some((v) => values.includes(normalize(v)));
}
return values.includes(value);
return values.includes(normalize(value));
},
update,
filter,
Expand Down Expand Up @@ -216,10 +220,12 @@ function getDerivedFilterOptions(
case FilterType.Options: {
if (Array.isArray(creature[field])) {
for (const value of creature[field]) {
options.get(filter).add(value);
options.get(filter).add(normalize(value));
}
} else if (typeof creature[field] === "string") {
options.get(filter).add(creature[field]);
options
.get(filter)
.add(normalize(creature[field]));
}
break;
}
Expand Down

0 comments on commit 27c4d92

Please sign in to comment.