refactor: simplify Card HTML and extract search filter composable
All checks were successful
CI / update (push) Successful in 1m23s

- Remove unnecessary wrapper divs in Card component (.card_anchor, .div_div_image)
- Flatten Card HTML from 4 levels to 2 levels of nesting
- Create reusable createSearchFilter composable in $lib/js/searchFilter.svelte.ts
- Apply search filter composable to category, tag, and favorites pages
This commit is contained in:
2026-01-25 14:47:26 +01:00
parent 940f9f14a2
commit 5824993b18
5 changed files with 54 additions and 83 deletions

View File

@@ -4,6 +4,8 @@
import Recipes from '$lib/components/Recipes.svelte';
import Card from '$lib/components/Card.svelte';
import Search from '$lib/components/Search.svelte';
import { createSearchFilter } from '$lib/js/searchFilter.svelte';
let { data } = $props<{ data: PageData }>();
let current_month = new Date().getMonth() + 1;
@@ -28,23 +30,7 @@
recipesLink: isEnglish ? 'recipe' : 'Rezept'
});
// 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.favorites.length;
}
// Filter recipes based on search
const filteredFavorites = $derived.by(() => {
if (!hasActiveSearch) {
return data.favorites;
}
return data.favorites.filter(r => matchedRecipeIds.has(r._id));
});
const { filtered: filteredFavorites, handleSearchResults } = createSearchFilter(() => data.favorites);
</script>
<style>