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); + }); +}