Skip to content

Commit

Permalink
make use of new search function in other components
Browse files Browse the repository at this point in the history
  • Loading branch information
atomicptr committed Dec 10, 2024
1 parent 6e6798d commit fb8981e
Show file tree
Hide file tree
Showing 2 changed files with 4 additions and 3 deletions.
4 changes: 2 additions & 2 deletions src/lib/build/filters.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ import type {
Weapon,
WeaponType,
} from "$lib/data/phalanx-types";
import { searchInTranslatableStrings } from "$lib/utils/search";
import { translatableString } from "$lib/utils/translatable-string";

export interface GenericItem {
Expand All @@ -24,8 +25,7 @@ export type FilterFunc = (item: FilterItem) => boolean;
export const applyAll = (items: FilterItem[], funcs: FilterFunc[]) =>
items.filter((item) => funcs.every((f) => f(item)));

export const filterName = (search: string) => (item: FilterItem) =>
translatableString(item.name).toLowerCase().indexOf(search.toLowerCase()) > -1;
export const filterName = (search: string) => (item: FilterItem) => searchInTranslatableStrings(search, [item.name]);

export const filterWeaponType = (weaponType: WeaponType) => (item: FilterItem) => (item as Weapon).type === weaponType;

Expand Down
3 changes: 2 additions & 1 deletion src/lib/components/FinderItemFilter.svelte
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ import CloseIcon from "./icons/CloseIcon.svelte";
import CheckCircle from "./icons/CheckCircle.svelte";
import { filterItemCompare } from "$lib/build/filters";
import type { WhitelistedItems } from "$lib/finder/finder.svelte";
import { searchInTranslatableStrings } from "$lib/utils/search";
interface Props {
heads: number[];
Expand Down Expand Up @@ -169,7 +170,7 @@ onMount(() => {
</div>

{#each armoursByType[armourType]?.toSorted(filterItemCompare) ?? [] as armour}
<div class="form-control" class:hidden={translatableString(armour.name).toLowerCase().indexOf(filtersSearch.toLowerCase()) === -1}>
<div class="form-control" class:hidden={!searchInTranslatableStrings(filtersSearch, [armour.name])}>
<label class="label cursor-pointer h-12">
<input type="checkbox" checked={isWhitelisted(armourType, armour.id)} class="checkbox" onchange={() => toggleWhitelisted(armourType, armour.id)} />
<div class="flex flex-row gap-2 grow ml-4 items-center">
Expand Down

0 comments on commit fb8981e

Please sign in to comment.