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

@@ -2,32 +2,18 @@
import type { PageData } from './$types';
import Recipes from '$lib/components/Recipes.svelte';
import Search from '$lib/components/Search.svelte';
import Card from '$lib/components/Card.svelte';
import { rand_array } from '$lib/js/randomize';
import { createSearchFilter } from '$lib/js/searchFilter.svelte';
let { data } = $props<{ data: PageData }>();
let current_month = new Date().getMonth() + 1;
import Card from '$lib/components/Card.svelte'
import { rand_array } from '$lib/js/randomize';
const isEnglish = $derived(data.lang === 'en');
const label = $derived(isEnglish ? 'Recipes in Category' : 'Rezepte in Kategorie');
const siteTitle = $derived(isEnglish ? 'Bocken Recipes' : 'Bocken Rezepte');
// 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));
});
const { filtered: filteredRecipes, handleSearchResults } = createSearchFilter(() => data.recipes);
</script>
<style>
h1 {