Skip to content

Commit ccc8172

Browse files
committed
feat: add search input
1 parent 7d093c5 commit ccc8172

File tree

3 files changed

+39
-10
lines changed

3 files changed

+39
-10
lines changed

bun.lockb

696 Bytes
Binary file not shown.

package.json

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@
1313
"license": "MIT",
1414
"devDependencies": {
1515
"@tsconfig/svelte": "^5.0.4",
16+
"@types/lodash": "^4.17.16",
1617
"@types/node": "^22.15.3",
1718
"@typescript-eslint/eslint-plugin": "8.31.1",
1819
"@typescript-eslint/parser": "8.31.1",
@@ -26,6 +27,7 @@
2627
"typescript": "5.8.3"
2728
},
2829
"dependencies": {
30+
"lodash": "^4.17.21",
2931
"svelte": "^5.28.2"
3032
}
3133
}

src/svelte/index.svelte

Lines changed: 37 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
<script lang="ts">
2+
import { debounce } from "lodash";
23
import { Menu, type App } from "obsidian";
34
import { deleteFile } from "src/utils/delete-file";
45
import { findDuplicateUrls } from "src/utils/find-duplicate-urls";
@@ -11,7 +12,28 @@
1112
1213
const { obsidianApp }: AppProps = $props();
1314
14-
let duplicateUrls: Map<string, string[]> = $state(new Map());
15+
let duplicateUrlMap: Map<string, string[]> = $state(new Map());
16+
let searchValue = $state("");
17+
18+
let filteredDuplicateUrlMap = $derived(
19+
new Map(
20+
Array.from(duplicateUrlMap.entries()).filter(([_, files]) =>
21+
files.some((file) =>
22+
file.toLowerCase().includes(searchValue.toLowerCase()),
23+
),
24+
),
25+
),
26+
);
27+
28+
let duplicateUrlCount = $derived(
29+
Array.from(filteredDuplicateUrlMap.entries()).filter(
30+
([_, files]) => files.length > 1,
31+
).length,
32+
);
33+
34+
const handleInputChange = debounce((event: Event) => {
35+
searchValue = (event.target as HTMLInputElement).value;
36+
}, 100);
1537
1638
function handleItemClick(filePath: string) {
1739
openInNewTab(obsidianApp, filePath, true);
@@ -33,28 +55,29 @@
3355
item.setTitle("Delete file");
3456
item.onClick(async () => {
3557
await deleteFile(obsidianApp, filePath);
36-
duplicateUrls = await findDuplicateUrls(obsidianApp);
58+
duplicateUrlMap = await findDuplicateUrls(obsidianApp);
3759
});
3860
});
3961
menu.showAtMouseEvent(event);
4062
}
4163
4264
onMount(async () => {
43-
duplicateUrls = await findDuplicateUrls(obsidianApp);
65+
duplicateUrlMap = await findDuplicateUrls(obsidianApp);
4466
});
45-
46-
let duplicateUrlCount = $derived(
47-
Array.from(duplicateUrls.entries()).filter(
48-
([_, files]) => files.length > 1,
49-
).length,
50-
);
5167
</script>
5268

5369
<div>
5470
<h1>Duplicate Finder</h1>
5571
<p>Duplicate URLs: {duplicateUrlCount}</p>
72+
<input
73+
type="search"
74+
placeholder="Filter by file name..."
75+
value={searchValue}
76+
oninput={handleInputChange}
77+
/>
78+
<hr />
5679
<div class="accordion-list-container">
57-
{#each Array.from(duplicateUrls.entries()) as [url, files]}
80+
{#each Array.from(filteredDuplicateUrlMap.entries()) as [url, files]}
5881
{#if files.length > 1}
5982
<div class="accordion">
6083
<details>
@@ -88,6 +111,10 @@
88111
font-size: 2rem;
89112
}
90113
114+
hr {
115+
margin: 1.1rem 0;
116+
}
117+
91118
.accordion-item {
92119
padding: 8px 16px;
93120
border-bottom: 1px solid #e0e0e0;

0 commit comments

Comments
 (0)