feat(search): auto-redirect to web search when no local hits
Spares the user a click: empty local result set triggers goto('/search/web?q=...')
with replaceState so the back button returns to the previous page, not the empty
local results list.
Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
This commit is contained in:
@@ -17,6 +17,11 @@
|
|||||||
const body = await res.json();
|
const body = await res.json();
|
||||||
hits = body.hits;
|
hits = body.hits;
|
||||||
loading = false;
|
loading = false;
|
||||||
|
if (hits.length === 0) {
|
||||||
|
// Kein lokaler Treffer → automatisch im Internet weitersuchen.
|
||||||
|
// replaceState, damit die Zurück-Taste nicht zwischen leerer Liste und Web-Suche pingt.
|
||||||
|
void goto(`/search/web?q=${encodeURIComponent(q)}`, { replaceState: true });
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
$effect(() => {
|
$effect(() => {
|
||||||
@@ -47,10 +52,7 @@
|
|||||||
<p class="muted">Suche läuft …</p>
|
<p class="muted">Suche läuft …</p>
|
||||||
{:else if searched && hits.length === 0}
|
{:else if searched && hits.length === 0}
|
||||||
<section class="empty">
|
<section class="empty">
|
||||||
<p>Kein Rezept im Bestand für „{query}".</p>
|
<p>Kein lokales Rezept für „{query}" — suche jetzt im Internet …</p>
|
||||||
<a class="web-btn" href={`/search/web?q=${encodeURIComponent(query)}`}>
|
|
||||||
🌐 Im Internet suchen
|
|
||||||
</a>
|
|
||||||
</section>
|
</section>
|
||||||
{:else if hits.length > 0}
|
{:else if hits.length > 0}
|
||||||
<ul class="hits">
|
<ul class="hits">
|
||||||
@@ -185,7 +187,4 @@
|
|||||||
font-size: 1rem;
|
font-size: 1rem;
|
||||||
min-height: 48px;
|
min-height: 48px;
|
||||||
}
|
}
|
||||||
.empty .web-btn {
|
|
||||||
margin-top: 1rem;
|
|
||||||
}
|
|
||||||
</style>
|
</style>
|
||||||
|
|||||||
Reference in New Issue
Block a user