feat(database): add weapon discovery filters
This commit is contained in:
@@ -5,7 +5,7 @@
|
||||
import ItemIcon from './ItemIcon.svelte';
|
||||
import type { GameIconName } from '$lib/game-icons';
|
||||
|
||||
type Option = { value: string; label: string; iconUrl?: string; gameIcon?: GameIconName };
|
||||
type Option = { value: string; label: string; description?: string; searchText?: string; iconUrl?: string; gameIcon?: GameIconName };
|
||||
type Group = { key: string; label: string; kind: 'segmented' | 'searchable'; options: Option[]; selected: string[] };
|
||||
let { groups }: { groups: Group[] } = $props();
|
||||
let queries = $state<Record<string, string>>({});
|
||||
@@ -26,7 +26,10 @@
|
||||
};
|
||||
const visible = (group: Group) => {
|
||||
const query = (queries[group.key] ?? '').normalize('NFKC').trim().toLocaleLowerCase();
|
||||
return group.options.filter((option) => !query || option.label.toLocaleLowerCase().includes(query));
|
||||
return group.options.filter((option) => !query
|
||||
|| option.label.toLocaleLowerCase().includes(query)
|
||||
|| option.description?.toLocaleLowerCase().includes(query)
|
||||
|| option.searchText?.toLocaleLowerCase().includes(query));
|
||||
};
|
||||
const selectedCount = $derived(groups.reduce((total, group) => total + group.selected.length, 0));
|
||||
</script>
|
||||
@@ -44,7 +47,7 @@
|
||||
{#each visible(group) as option}
|
||||
<button type="button" class:selected={group.selected.includes(option.value)} aria-pressed={group.selected.includes(option.value)} onclick={() => change(group.key, option.value)}>
|
||||
{#if option.gameIcon}<GameIcon name={option.gameIcon} decorative/>{:else if option.iconUrl !== undefined}<ItemIcon src={option.iconUrl} alt=""/>{:else}<i aria-hidden="true"></i>{/if}
|
||||
<span>{option.label}</span>
|
||||
<span>{option.label}{#if option.description}<small><b>T1</b>{option.description}</small>{/if}</span>
|
||||
</button>
|
||||
{:else}
|
||||
<small>NO MATCHING OPTIONS</small>
|
||||
|
||||
Reference in New Issue
Block a user