From af61b10a5925866da1b69f7ce673a4569cacb330 Mon Sep 17 00:00:00 2001 From: Thomas Richter Date: Sat, 31 Jan 2026 17:17:03 +0100 Subject: [PATCH] feat(05-03): create recent searches store and add dropdown UI - Add recentSearches persisted store with 5-item limit - Add addRecentSearch() function for deduplication - Update SearchBar with recentSearches dropdown - Show dropdown on focus when input empty - Use onmousedown to handle selection before blur - Add to recent searches on blur with >= 2 chars --- src/lib/components/SearchBar.svelte | 47 ++++++++++++++++++++++++++++- src/lib/stores/recentSearches.ts | 16 ++++++++++ 2 files changed, 62 insertions(+), 1 deletion(-) create mode 100644 src/lib/stores/recentSearches.ts diff --git a/src/lib/components/SearchBar.svelte b/src/lib/components/SearchBar.svelte index 9649ecc..9289e68 100644 --- a/src/lib/components/SearchBar.svelte +++ b/src/lib/components/SearchBar.svelte @@ -1,15 +1,21 @@
+ + {#if showRecentSearches} +
+
+ Recent searches +
+ {#each recentSearches as search} + + {/each} +
+ {/if}
diff --git a/src/lib/stores/recentSearches.ts b/src/lib/stores/recentSearches.ts new file mode 100644 index 0000000..5a22fc0 --- /dev/null +++ b/src/lib/stores/recentSearches.ts @@ -0,0 +1,16 @@ +import { persisted } from 'svelte-persisted-store'; + +const MAX_RECENT = 5; + +export const recentSearches = persisted('taskplaner-recent-searches', []); + +export function addRecentSearch(query: string): void { + if (!query || query.length < 2) return; + + recentSearches.update((searches) => { + // Remove if already exists (will re-add at front) + const filtered = searches.filter((s) => s.toLowerCase() !== query.toLowerCase()); + // Add to front, limit to MAX_RECENT + return [query, ...filtered].slice(0, MAX_RECENT); + }); +}