refactor: simplify Card HTML and extract search filter composable
All checks were successful
CI / update (push) Successful in 1m23s
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:
@@ -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>
|
||||
|
||||
Reference in New Issue
Block a user