fix: add category and favorites filters to all recipe pages

- Move categories logic into Search component for centralization
- Add isLoggedIn prop to SeasonLayout and IconLayout components
- Fix FilterPanel CSS to properly handle hidden favorites filter
- Fix FavoritesFilter to trigger onToggle when checkbox changes
- Update Search effect to track all filter states (category, tags, icon, season, favorites)
- Hide favorites filter on favorites page while maintaining proper grid layout
- All filters now work consistently across entire site
This commit is contained in:
2026-01-10 17:19:55 +01:00
parent 7ab3482850
commit bc170abcdf
12 changed files with 44 additions and 28 deletions

View File

@@ -5,6 +5,7 @@
import Card from '$lib/components/Card.svelte';
import Search from '$lib/components/Search.svelte';
import LazyCategory from '$lib/components/LazyCategory.svelte';
import { getCategories } from '$lib/js/categories';
let { data } = $props<{ data: PageData }>();
let current_month = new Date().getMonth() + 1;
@@ -21,9 +22,7 @@
}
const isEnglish = $derived(data.lang === 'en');
const categories = $derived(isEnglish
? ["Main course", "Noodle", "Bread", "Dessert", "Soup", "Side dish", "Salad", "Cake", "Breakfast", "Sauce", "Ingredient", "Drink", "Spread", "Biscuits", "Snack"]
: ["Hauptspeise", "Nudel", "Brot", "Dessert", "Suppe", "Beilage", "Salat", "Kuchen", "Frühstück", "Sauce", "Zutat", "Getränk", "Aufstrich", "Guetzli", "Snack"]);
const categories = $derived(getCategories(data.lang));
// Pre-compute category-to-recipes Map for O(1) lookups
const recipesByCategory = $derived.by(() => {
@@ -101,7 +100,7 @@ h1{
<h1>{labels.title}</h1>
<p class=subheading>{labels.subheading}</p>
<Search lang={data.lang} recipes={data.all_brief} categories={categories} isLoggedIn={!!data.session?.user} onSearchResults={handleSearchResults}></Search>
<Search lang={data.lang} recipes={data.all_brief} isLoggedIn={!!data.session?.user} onSearchResults={handleSearchResults}></Search>
{#if seasonRecipes.length > 0}
<LazyCategory title={labels.inSeason} eager={true}>

View File

@@ -35,7 +35,7 @@
}
</style>
<h1>{label} <q>{data.category}</q>:</h1>
<Search category={data.category} lang={data.lang} recipes={data.recipes} onSearchResults={handleSearchResults}></Search>
<Search category={data.category} lang={data.lang} recipes={data.recipes} isLoggedIn={!!data.session?.user} onSearchResults={handleSearchResults}></Search>
<section>
<Recipes>
{#each rand_array(filteredRecipes) as recipe}

View File

@@ -79,7 +79,7 @@ h1{
{/if}
</p>
<Search favoritesOnly={true} lang={data.lang} recipes={data.favorites} onSearchResults={handleSearchResults}></Search>
<Search favoritesOnly={true} lang={data.lang} recipes={data.favorites} isLoggedIn={!!data.session?.user} onSearchResults={handleSearchResults}></Search>
{#if data.error}
<p class="empty-state">{labels.errorLoading} {data.error}</p>

View File

@@ -26,7 +26,7 @@
return data.season.filter(r => matchedRecipeIds.has(r._id));
});
</script>
<IconLayout icons={data.icons} active_icon={data.icon} routePrefix="/{data.recipeLang}" lang={data.lang} recipes={data.season} onSearchResults={handleSearchResults}>
<IconLayout icons={data.icons} active_icon={data.icon} routePrefix="/{data.recipeLang}" lang={data.lang} recipes={data.season} isLoggedIn={!!data.session?.user} onSearchResults={handleSearchResults}>
{#snippet recipesSlot()}
<Recipes>
{#each rand_array(filteredRecipes) as recipe}

View File

@@ -34,7 +34,7 @@
});
</script>
<SeasonLayout active_index={current_month-1} {months} routePrefix="/{data.recipeLang}" lang={data.lang} recipes={data.season} onSearchResults={handleSearchResults}>
<SeasonLayout active_index={current_month-1} {months} routePrefix="/{data.recipeLang}" lang={data.lang} recipes={data.season} isLoggedIn={!!data.session?.user} onSearchResults={handleSearchResults}>
{#snippet recipesSlot()}
<Recipes>
{#each rand_array(filteredRecipes) as recipe}

View File

@@ -35,7 +35,7 @@
}
</style>
<h1>{label} <q>{data.tag}</q>:</h1>
<Search tag={data.tag} lang={data.lang} recipes={data.recipes} onSearchResults={handleSearchResults}></Search>
<Search tag={data.tag} lang={data.lang} recipes={data.recipes} isLoggedIn={!!data.session?.user} onSearchResults={handleSearchResults}></Search>
<section>
<Recipes>
{#each rand_array(filteredRecipes) as recipe}