feat: enable live search on all recipe pages
All checks were successful
CI / update (push) Successful in 1m9s

Previously, live client-side search only worked on the main /rezepte and /recipes pages. All other pages (category, tag, favorites, search results, icon, and season pages) fell back to server-side search with form submission.

Now all recipe pages support live filtering as users type, providing consistent UX across the site.
This commit is contained in:
2026-01-02 20:25:43 +01:00
parent f6258ae518
commit 903722b335
10 changed files with 177 additions and 25 deletions

View File

@@ -9,6 +9,24 @@
const isEnglish = $derived(data.lang === 'en');
const label = $derived(isEnglish ? 'Recipes in Category' : 'Rezepte in Kategorie');
// Search state
let matchedRecipeIds = $state(new Set());
let hasActiveSearch = $state(false);
// Handle search results from Search component
function handleSearchResults(ids, categories) {
matchedRecipeIds = ids;
hasActiveSearch = ids.size < data.recipes.length;
}
// Filter recipes based on search
const filteredRecipes = $derived.by(() => {
if (!hasActiveSearch) {
return data.recipes;
}
return data.recipes.filter(r => matchedRecipeIds.has(r._id));
});
</script>
<style>
h1 {
@@ -17,10 +35,10 @@
}
</style>
<h1>{label} <q>{data.category}</q>:</h1>
<Search category={data.category} lang={data.lang}></Search>
<Search category={data.category} lang={data.lang} recipes={data.recipes} onSearchResults={handleSearchResults}></Search>
<section>
<Recipes>
{#each rand_array(data.recipes) as recipe}
{#each rand_array(filteredRecipes) as recipe}
<Card {recipe} {current_month} isFavorite={recipe.isFavorite} showFavoriteIndicator={!!data.session?.user} routePrefix="/{data.recipeLang}"></Card>
{/each}
</Recipes>