feat(search): Domain-Filter als Dropdown im Suchfeld
All checks were successful
Build & Publish Docker Image / build-and-push (push) Successful in 1m18s
All checks were successful
Build & Publish Docker Image / build-and-push (push) Successful in 1m18s
Links im großen Suchfeld ein Slider-Icon mit Badge („Alle" oder „2/5"), das ein Dropdown-Menü mit allen Whitelist-Domains als Checkboxen öffnet. Auswahl wird per localStorage persistiert und gilt global — Header-Such- Dropdown konsumiert den gleichen Store und sendet den domains-Parameter bei jedem Fetch mit. Leere Menge heißt „alle aktiv", damit neu vom Admin freigeschaltete Domains automatisch dabei sind. Aktive Auswahl landet als explizite Intersection mit der Whitelist serverseitig. - searchLocal nimmt jetzt optional string[] domains → `source_domain IN (…)`. - searchWeb nimmt jetzt opts.domains → site:-Filter auf die Auswahl eingeschränkt. Nicht-Whitelist-Einträge werden ignoriert. - API-Endpoints: `?domains=a.de,b.de`. - Neuer Client-Store $lib/client/search-filter.svelte.ts. - Neue Komponente $lib/components/SearchFilter.svelte (mobile-tauglich, 44px Touch-Targets, Badge auf engen Screens versteckt). Home-Seite re-runt die Suche bei Filter-Änderung automatisch (150ms debounce), ohne dass der User neu tippen muss. Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
This commit is contained in:
@@ -6,6 +6,7 @@
|
||||
import { profileStore } from '$lib/client/profile.svelte';
|
||||
import { wishlistStore } from '$lib/client/wishlist.svelte';
|
||||
import { pwaStore } from '$lib/client/pwa.svelte';
|
||||
import { searchFilterStore } from '$lib/client/search-filter.svelte';
|
||||
import ProfileSwitcher from '$lib/components/ProfileSwitcher.svelte';
|
||||
import ConfirmDialog from '$lib/components/ConfirmDialog.svelte';
|
||||
import SearchLoader from '$lib/components/SearchLoader.svelte';
|
||||
@@ -37,6 +38,11 @@
|
||||
$page.url.pathname.startsWith('/recipes/') || $page.url.pathname === '/preview'
|
||||
);
|
||||
|
||||
function filterParam(): string {
|
||||
const p = searchFilterStore.queryParam;
|
||||
return p ? `&domains=${encodeURIComponent(p)}` : '';
|
||||
}
|
||||
|
||||
$effect(() => {
|
||||
const q = navQuery.trim();
|
||||
if (debounceTimer) clearTimeout(debounceTimer);
|
||||
@@ -63,7 +69,7 @@
|
||||
debounceTimer = setTimeout(async () => {
|
||||
try {
|
||||
const res = await fetch(
|
||||
`/api/recipes/search?q=${encodeURIComponent(q)}&limit=${NAV_PAGE_SIZE}`
|
||||
`/api/recipes/search?q=${encodeURIComponent(q)}&limit=${NAV_PAGE_SIZE}${filterParam()}`
|
||||
);
|
||||
const body = await res.json();
|
||||
if (navQuery.trim() !== q) return;
|
||||
@@ -73,7 +79,7 @@
|
||||
navWebSearching = true;
|
||||
try {
|
||||
const wres = await fetch(
|
||||
`/api/recipes/search/web?q=${encodeURIComponent(q)}&pageno=1`
|
||||
`/api/recipes/search/web?q=${encodeURIComponent(q)}&pageno=1${filterParam()}`
|
||||
);
|
||||
if (navQuery.trim() !== q) return;
|
||||
if (!wres.ok) {
|
||||
@@ -104,7 +110,7 @@
|
||||
try {
|
||||
if (!navLocalExhausted) {
|
||||
const res = await fetch(
|
||||
`/api/recipes/search?q=${encodeURIComponent(q)}&limit=${NAV_PAGE_SIZE}&offset=${navHits.length}`
|
||||
`/api/recipes/search?q=${encodeURIComponent(q)}&limit=${NAV_PAGE_SIZE}&offset=${navHits.length}${filterParam()}`
|
||||
);
|
||||
const body = await res.json();
|
||||
if (navQuery.trim() !== q) return;
|
||||
@@ -118,7 +124,7 @@
|
||||
navWebSearching = navWebHits.length === 0;
|
||||
try {
|
||||
const wres = await fetch(
|
||||
`/api/recipes/search/web?q=${encodeURIComponent(q)}&pageno=${nextPage}`
|
||||
`/api/recipes/search/web?q=${encodeURIComponent(q)}&pageno=${nextPage}${filterParam()}`
|
||||
);
|
||||
if (navQuery.trim() !== q) return;
|
||||
if (!wres.ok) {
|
||||
@@ -193,6 +199,7 @@
|
||||
onMount(() => {
|
||||
profileStore.load();
|
||||
void wishlistStore.refresh();
|
||||
void searchFilterStore.load();
|
||||
void pwaStore.init();
|
||||
document.addEventListener('click', handleClickOutside);
|
||||
document.addEventListener('keydown', handleKey);
|
||||
|
||||
@@ -7,7 +7,9 @@
|
||||
import type { WebHit } from '$lib/server/search/searxng';
|
||||
import { randomQuote } from '$lib/quotes';
|
||||
import SearchLoader from '$lib/components/SearchLoader.svelte';
|
||||
import SearchFilter from '$lib/components/SearchFilter.svelte';
|
||||
import { profileStore } from '$lib/client/profile.svelte';
|
||||
import { searchFilterStore } from '$lib/client/search-filter.svelte';
|
||||
|
||||
const LOCAL_PAGE = 30;
|
||||
|
||||
@@ -26,6 +28,7 @@
|
||||
let webExhausted = $state(false);
|
||||
let loadingMore = $state(false);
|
||||
let skipNextSearch = false;
|
||||
let debounceTimer: ReturnType<typeof setTimeout> | null = null;
|
||||
|
||||
type SearchSnapshot = {
|
||||
query: string;
|
||||
@@ -85,6 +88,22 @@
|
||||
const urlQ = ($page.url.searchParams.get('q') ?? '').trim();
|
||||
if (urlQ) query = urlQ;
|
||||
void loadRecent();
|
||||
void searchFilterStore.load();
|
||||
});
|
||||
|
||||
// Bei Änderung der Domain-Auswahl: laufende Suche neu ausführen,
|
||||
// damit der User nicht manuell re-tippen muss.
|
||||
$effect(() => {
|
||||
// eslint-disable-next-line @typescript-eslint/no-unused-expressions
|
||||
searchFilterStore.active;
|
||||
const q = query.trim();
|
||||
if (!q || q.length <= 3) return;
|
||||
if (debounceTimer) clearTimeout(debounceTimer);
|
||||
searching = true;
|
||||
webHits = [];
|
||||
webSearching = false;
|
||||
webError = null;
|
||||
debounceTimer = setTimeout(() => void runSearch(q), 150);
|
||||
});
|
||||
|
||||
// Sync current query back into the URL as ?q=... via replaceState,
|
||||
@@ -110,7 +129,10 @@
|
||||
void loadFavorites(active.id);
|
||||
});
|
||||
|
||||
let debounceTimer: ReturnType<typeof setTimeout> | null = null;
|
||||
function filterParam(): string {
|
||||
const p = searchFilterStore.queryParam;
|
||||
return p ? `&domains=${encodeURIComponent(p)}` : '';
|
||||
}
|
||||
|
||||
async function runSearch(q: string) {
|
||||
localExhausted = false;
|
||||
@@ -118,7 +140,7 @@
|
||||
webExhausted = false;
|
||||
try {
|
||||
const res = await fetch(
|
||||
`/api/recipes/search?q=${encodeURIComponent(q)}&limit=${LOCAL_PAGE}`
|
||||
`/api/recipes/search?q=${encodeURIComponent(q)}&limit=${LOCAL_PAGE}${filterParam()}`
|
||||
);
|
||||
const body = await res.json();
|
||||
if (query.trim() !== q) return;
|
||||
@@ -130,7 +152,9 @@
|
||||
// damit der User nicht extra auf „+ weitere" klicken muss.
|
||||
webSearching = true;
|
||||
try {
|
||||
const wres = await fetch(`/api/recipes/search/web?q=${encodeURIComponent(q)}&pageno=1`);
|
||||
const wres = await fetch(
|
||||
`/api/recipes/search/web?q=${encodeURIComponent(q)}&pageno=1${filterParam()}`
|
||||
);
|
||||
if (query.trim() !== q) return;
|
||||
if (!wres.ok) {
|
||||
const err = await wres.json().catch(() => ({}));
|
||||
@@ -160,7 +184,7 @@
|
||||
if (!localExhausted) {
|
||||
// Noch mehr lokale Treffer holen.
|
||||
const res = await fetch(
|
||||
`/api/recipes/search?q=${encodeURIComponent(q)}&limit=${LOCAL_PAGE}&offset=${hits.length}`
|
||||
`/api/recipes/search?q=${encodeURIComponent(q)}&limit=${LOCAL_PAGE}&offset=${hits.length}${filterParam()}`
|
||||
);
|
||||
const body = await res.json();
|
||||
if (query.trim() !== q) return;
|
||||
@@ -175,7 +199,7 @@
|
||||
webSearching = webHits.length === 0;
|
||||
try {
|
||||
const wres = await fetch(
|
||||
`/api/recipes/search/web?q=${encodeURIComponent(q)}&pageno=${nextPage}`
|
||||
`/api/recipes/search/web?q=${encodeURIComponent(q)}&pageno=${nextPage}${filterParam()}`
|
||||
);
|
||||
if (query.trim() !== q) return;
|
||||
if (!wres.ok) {
|
||||
@@ -256,7 +280,8 @@
|
||||
<section class="hero">
|
||||
<h1>Kochwas</h1>
|
||||
<p class="tagline" aria-live="polite">{quote || '\u00a0'}</p>
|
||||
<form onsubmit={submit}>
|
||||
<form class="search-form" onsubmit={submit}>
|
||||
<SearchFilter />
|
||||
<input
|
||||
type="search"
|
||||
bind:value={query}
|
||||
|
||||
@@ -7,9 +7,13 @@ export const GET: RequestHandler = async ({ url }) => {
|
||||
const q = url.searchParams.get('q')?.trim() ?? '';
|
||||
const limit = Math.min(Number(url.searchParams.get('limit') ?? 30), 100);
|
||||
const offset = Math.max(0, Number(url.searchParams.get('offset') ?? 0));
|
||||
const domains = (url.searchParams.get('domains') ?? '')
|
||||
.split(',')
|
||||
.map((d) => d.trim())
|
||||
.filter(Boolean);
|
||||
const hits =
|
||||
q.length >= 1
|
||||
? searchLocal(getDb(), q, limit, offset)
|
||||
? searchLocal(getDb(), q, limit, offset, domains)
|
||||
: offset === 0
|
||||
? listRecentRecipes(getDb(), limit)
|
||||
: [];
|
||||
|
||||
@@ -7,8 +7,12 @@ export const GET: RequestHandler = async ({ url }) => {
|
||||
const q = url.searchParams.get('q')?.trim() ?? '';
|
||||
if (!q) error(400, { message: 'Missing ?q=' });
|
||||
const pageno = Math.max(1, Math.min(10, Number(url.searchParams.get('pageno') ?? 1)));
|
||||
const domains = (url.searchParams.get('domains') ?? '')
|
||||
.split(',')
|
||||
.map((d) => d.trim())
|
||||
.filter(Boolean);
|
||||
try {
|
||||
const hits = await searchWeb(getDb(), q, { pageno });
|
||||
const hits = await searchWeb(getDb(), q, { pageno, domains });
|
||||
return json({ query: q, pageno, hits });
|
||||
} catch (e) {
|
||||
error(502, { message: `Web search unavailable: ${(e as Error).message}` });
|
||||
|
||||
Reference in New Issue
Block a user