Skip to content

Commit

Permalink
Add interfaces to filter
Browse files Browse the repository at this point in the history
  • Loading branch information
tdittr committed May 30, 2024
1 parent bafbf65 commit 0acd1e3
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 8 deletions.
4 changes: 0 additions & 4 deletions frontend/src/App.svelte
Original file line number Diff line number Diff line change
Expand Up @@ -18,8 +18,6 @@
function combine_filters(crate_length: number, selected: any): number[] {
let selected_crates = Array.from({length: crate_length}, (_, i) => i + 1);
console.log(selected);
for (const filter of selected) {
if (filter === undefined || filter.length === 0) {
continue;
Expand All @@ -29,8 +27,6 @@
selected_crates = selected_crates.filter(crate => selected_filter.includes(crate));
}
console.log(selected_crates);
return selected_crates;
}
Expand Down
15 changes: 11 additions & 4 deletions frontend/src/lib/Filter.svelte
Original file line number Diff line number Diff line change
Expand Up @@ -5,17 +5,24 @@
export let selected: number[][];
let filter: string = "";
let by_count: boolean;
$: sorted_values = by_count ? Object.entries(values).sort((a, b) => b[1].length - a[1].length) : Object.entries(values);
</script>

<fieldset>
<legend>{name}</legend>
<input type="text" bind:value={filter}/>
<div>
<input type="text" bind:value={filter} placeholder="Filter"/>
<label><input type="checkbox" bind:checked={by_count}> Sort by count</label>
</div>
<div class="list">
{#each Object.entries(values) as [key, value]}
{#each sorted_values as [key, value]}
{#if key.toLowerCase().includes(filter.toLowerCase())}
<label>
<input type="checkbox" bind:group="{selected}" value={value}>
{key}
{key} ({value.length})
</label>
{/if}
{/each}
Expand All @@ -26,7 +33,7 @@
fieldset {
border: 1px solid;
padding: 10px;
max-height: 200px; /* Adjust this value as needed */
max-height: 300px; /* Adjust this value as needed */
text-align: left;
}
Expand Down

0 comments on commit 0acd1e3

Please sign in to comment.