diff --git a/src/routes/[recipeLang=recipeLang]/category/[category]/+page.server.ts b/src/routes/[recipeLang=recipeLang]/category/[category]/+page.server.ts index 4b51fe6..f03ca0a 100644 --- a/src/routes/[recipeLang=recipeLang]/category/[category]/+page.server.ts +++ b/src/routes/[recipeLang=recipeLang]/category/[category]/+page.server.ts @@ -4,18 +4,19 @@ import { getUserFavorites, addFavoriteStatusToRecipes } from "$lib/server/favori export const load: PageServerLoad = async ({ fetch, locals, params }) => { const apiBase = `/api/${params.recipeLang}`; - const res = await fetch(`${apiBase}/items/category/${params.category}`); - const items = await res.json(); - - // Get user favorites and session - const [userFavorites, session] = await Promise.all([ + const [res, allRes, userFavorites, session] = await Promise.all([ + fetch(`${apiBase}/items/category/${params.category}`), + fetch(`${apiBase}/items/all_brief`), getUserFavorites(fetch, locals), locals.auth() ]); + const [items, allRecipes] = await Promise.all([res.json(), allRes.json()]); + return { category: params.category, recipes: addFavoriteStatusToRecipes(items, userFavorites), + allRecipes: addFavoriteStatusToRecipes(allRecipes, userFavorites), session }; }; \ No newline at end of file diff --git a/src/routes/[recipeLang=recipeLang]/category/[category]/+page.svelte b/src/routes/[recipeLang=recipeLang]/category/[category]/+page.svelte index b7095c5..dd6698b 100644 --- a/src/routes/[recipeLang=recipeLang]/category/[category]/+page.svelte +++ b/src/routes/[recipeLang=recipeLang]/category/[category]/+page.svelte @@ -3,7 +3,6 @@ import Search from '$lib/components/recipes/Search.svelte'; import CompactCard from '$lib/components/recipes/CompactCard.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; @@ -12,7 +11,18 @@ const label = $derived(isEnglish ? 'Recipes in Category' : 'Rezepte in Kategorie'); const siteTitle = $derived(isEnglish ? 'Bocken Recipes' : 'Bocken Rezepte'); - const { filtered: filteredRecipes, handleSearchResults } = createSearchFilter(() => data.recipes); + let matchedRecipeIds = $state(new Set()); + let hasActiveSearch = $state(false); + + function handleSearchResults(ids: Set, categories: Set) { + matchedRecipeIds = ids; + hasActiveSearch = ids.size < data.allRecipes.length; + } + + const displayRecipes = $derived.by(() => { + if (!hasActiveSearch) return data.recipes; + return data.allRecipes.filter((r: any) => matchedRecipeIds.has(r._id)); + });