Skip to content

Commit ab61f5a

Browse files
feat(search): show package link for invalid query length
1 parent 32e1408 commit ab61f5a

2 files changed

Lines changed: 33 additions & 1 deletion

File tree

app/pages/search.vue

Lines changed: 30 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -72,11 +72,21 @@ const {
7272
isLoadingMore,
7373
hasMore,
7474
fetchMore,
75+
error,
7576
} = useNpmSearch(query, () => ({
7677
size: requestedSize.value,
7778
incremental: true,
7879
}))
7980
81+
interface SearchError {
82+
code?: string
83+
}
84+
85+
const hasTextLengthError = computed<boolean>(() => {
86+
const errorData = error.value?.data as SearchError | undefined
87+
return errorData?.code === 'ERR_TEXT_LENGTH'
88+
})
89+
8090
// Results to display (directly from incremental search)
8191
const rawVisibleResults = computed(() => results.value)
8292
@@ -594,6 +604,25 @@ defineOgImageComponent('Default', {
594604
<h1 class="font-mono text-2xl sm:text-3xl font-medium mb-4">
595605
{{ $t('search.title') }}
596606
</h1>
607+
<div
608+
v-if="hasTextLengthError"
609+
class="mb-6 p-4 bg-bg-subtle border border-border rounded-lg flex flex-col sm:flex-row sm:items-center gap-3 sm:gap-4"
610+
>
611+
<div class="flex-1 min-w-0">
612+
<p class="font-mono text-sm text-fg">
613+
{{ $t('search.not_invalid') }}
614+
</p>
615+
<p class="text-xs text-fg-muted mt-0.5">
616+
{{ $t('search.not_invalid_description') }}
617+
</p>
618+
</div>
619+
<NuxtLink
620+
:to="{ name: 'package', params: { package: [query] } }"
621+
class="shrink-0 px-4 py-2 font-mono text-sm text-bg bg-fg rounded-md hover:text-fg-subtle focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-fg/50"
622+
>
623+
{{ $t('search.not_invalid_button_label', { name: query }) }}
624+
</NuxtLink>
625+
</div>
597626

598627
<section v-if="query">
599628
<!-- Initial loading (only after user interaction, not during view transition) -->
@@ -698,7 +727,7 @@ defineOgImageComponent('Default', {
698727
</div>
699728

700729
<!-- No results found -->
701-
<div v-else-if="status !== 'pending'" role="status" class="py-12">
730+
<div v-else-if="status !== 'pending' && !hasTextLengthError" role="status" class="py-12">
702731
<p class="text-fg-muted font-mono mb-6 text-center">
703732
{{ $t('search.no_results', { query }) }}
704733
</p>

i18n/locales/en.json

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,9 @@
3434
"want_to_claim": "Want to claim this package name?",
3535
"start_typing": "Start typing to search packages",
3636
"exact_match": "exact",
37+
"not_invalid": "Search query invalid",
38+
"not_invalid_description": "Your search query doesn't meet the requirements. View the package directly instead.",
39+
"not_invalid_button_label": "View \"{name}\"",
3740
"suggestion": {
3841
"user": "user",
3942
"org": "org",

0 commit comments

Comments
 (0)