Skip to content

Commit aa37a01

Browse files
committed
TagEditor filter feature
1 parent 3c08b11 commit aa37a01

File tree

1 file changed

+29
-1
lines changed

1 file changed

+29
-1
lines changed

src/container/TagEditor/TagEditor.tsx

Lines changed: 29 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,12 +13,27 @@ import { TagIcon } from "../../assets/icons/TagIcon";
1313
import { useLiveQuery } from "dexie-react-hooks";
1414
import { tagService } from "../../scripts/db/TagService";
1515
import { TagConfig } from "./TagConfig/TagConfig";
16+
import { Input } from "../../common/components/shadcn/input";
17+
import { useState } from "react";
18+
import { matchSorter } from "match-sorter";
1619

1720
export const TagEditor = () => {
1821
const tags = useLiveQuery(() => {
1922
return tagService.listTags();
2023
});
2124

25+
const [filter, setFilter] = useState("");
26+
27+
const filteredTags = matchSorter(tags ?? [], filter, {
28+
keys: [
29+
"name",
30+
{
31+
key: "description",
32+
maxRanking: matchSorter.rankings.STARTS_WITH,
33+
},
34+
],
35+
});
36+
2237
return (
2338
<>
2439
<Drawer>
@@ -45,12 +60,25 @@ export const TagEditor = () => {
4560
</DrawerClose>
4661
</DrawerHeader>
4762
</div>
63+
<div className="grid grid-cols-[1fr_minmax(400px,_900px)_1fr] gap-4 p-4">
64+
<div />
65+
<div className="grid grid-cols-[300px_1fr]">
66+
<label className="flex justify-center items-center gap-2">
67+
Filter:
68+
<Input
69+
value={filter}
70+
onChange={(e) => setFilter(e.target.value)}
71+
/>
72+
</label>
73+
</div>
74+
<div />
75+
</div>
4876
<div className="grid grid-cols-[1fr_minmax(400px,_900px)_1fr] gap-4 pb-10 overflow-y-auto max-h-96">
4977
{!tags || tags.length <= 0 ? (
5078
<div>No tags yet.</div>
5179
) : (
5280
<div className="col-start-2 grid grid-cols-[200px_1fr_180px_100px_100px]">
53-
{tags.map((tag) => (
81+
{filteredTags.map((tag) => (
5482
<TagConfig
5583
key={tag.name}
5684
tag={tag}

0 commit comments

Comments
 (0)