diff --git a/src/routes/+page.svelte b/src/routes/+page.svelte index 7dd93ee..1390357 100644 --- a/src/routes/+page.svelte +++ b/src/routes/+page.svelte @@ -2,6 +2,7 @@ import { onMount } from 'svelte'; import { page } from '$app/stores'; import { CookingPot, Globe, X } from 'lucide-svelte'; + import type { Snapshot } from './$types'; import type { SearchHit } from '$lib/server/recipes/search-local'; import type { WebHit } from '$lib/server/search/searxng'; import { randomQuote } from '$lib/quotes'; @@ -18,6 +19,27 @@ let webSearching = $state(false); let webError = $state(null); let searchedFor = $state(null); + let skipNextSearch = false; + + type SearchSnapshot = { + query: string; + hits: SearchHit[]; + webHits: WebHit[]; + searchedFor: string | null; + webError: string | null; + }; + + export const snapshot: Snapshot = { + capture: () => ({ query, hits, webHits, searchedFor, webError }), + restore: (v) => { + query = v.query; + hits = v.hits; + webHits = v.webHits; + searchedFor = v.searchedFor; + webError = v.webError; + skipNextSearch = true; + } + }; async function loadRecent() { const res = await fetch('/api/recipes/search'); @@ -100,6 +122,12 @@ $effect(() => { const q = query.trim(); if (debounceTimer) clearTimeout(debounceTimer); + if (skipNextSearch) { + // Snapshot-Restore hat hits/webHits/searchedFor wiederhergestellt — + // nicht erneut fetchen. + skipNextSearch = false; + return; + } if (q.length <= 3) { hits = []; webHits = [];