Skip to content

Commit 62b7f6e

Browse files
committed
fix: max available results hint fixed og search page
1 parent 452bd47 commit 62b7f6e

1 file changed

Lines changed: 55 additions & 32 deletions

File tree

app/pages/search.vue

Lines changed: 55 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -253,14 +253,15 @@ const effectiveTotal = computed(() => {
253253
})
254254
255255
const resultsLimitAppliedText = computed<string>(() => {
256-
const totalUnlimited = visibleResults.value?.totalUnlimited ?? 0
256+
const totalUnlimited = results.value?.totalUnlimited ?? 0
257+
const total = results.value?.total ?? 0
257258
258-
if (isRelevanceSort.value && effectiveTotal.value < totalUnlimited) {
259-
const total = { total: $n(totalUnlimited) }
259+
if (isRelevanceSort.value && total < totalUnlimited) {
260+
const totalTrans = { total: $n(totalUnlimited) }
260261
261262
return searchProvider.value === 'npm'
262-
? $t('search.more_results_available_npm', total)
263-
: $t('search.more_results_available_algolia', total)
263+
? $t('search.more_results_available_npm', totalTrans)
264+
: $t('search.more_results_available_algolia', totalTrans)
264265
}
265266
// do not show hint if results limit is not reached
266267
return ''
@@ -407,22 +408,24 @@ const exactMatchType = computed<'package' | 'org' | 'user' | null>(() => {
407408
const suggestionCount = computed(() => validatedSuggestions.value.length)
408409
const totalSelectableCount = computed(() => suggestionCount.value + resultCount.value)
409410
411+
function isElementVisible(el: HTMLElement) {
412+
return el.getClientRects().length > 0
413+
}
414+
410415
/**
411416
* Get all focusable result elements in DOM order (suggestions first, then packages)
412417
*/
413418
function getFocusableElements(): HTMLElement[] {
414-
const isVisible = (el: HTMLElement) => el.getClientRects().length > 0
415-
416419
const suggestions = Array.from(document.querySelectorAll<HTMLElement>('[data-suggestion-index]'))
417-
.filter(isVisible)
420+
.filter(isElementVisible)
418421
.sort((a, b) => {
419422
const aIdx = Number.parseInt(a.dataset.suggestionIndex ?? '0', 10)
420423
const bIdx = Number.parseInt(b.dataset.suggestionIndex ?? '0', 10)
421424
return aIdx - bIdx
422425
})
423426
424427
const packages = Array.from(document.querySelectorAll<HTMLElement>('[data-result-index]'))
425-
.filter(isVisible)
428+
.filter(isElementVisible)
426429
.sort((a, b) => {
427430
const aIdx = Number.parseInt(a.dataset.resultIndex ?? '0', 10)
428431
const bIdx = Number.parseInt(b.dataset.resultIndex ?? '0', 10)
@@ -449,7 +452,7 @@ async function navigateToPackage(packageName: string) {
449452
const pendingEnterQuery = shallowRef<string | null>(null)
450453
451454
// Watch for results to navigate when Enter was pressed before results arrived
452-
watch(displayResults, results => {
455+
watch(displayResults, ([firstResult]) => {
453456
if (!pendingEnterQuery.value) return
454457
455458
// Check if input is still focused (user hasn't started navigating or clicked elsewhere)
@@ -459,7 +462,6 @@ watch(displayResults, results => {
459462
}
460463
461464
// Navigate if first result matches the query that was entered
462-
const firstResult = results[0]
463465
// eslint-disable-next-line no-console
464466
console.log('[search] watcher fired', {
465467
pending: pendingEnterQuery.value,
@@ -764,16 +766,29 @@ onBeforeUnmount(() => {
764766
/>
765767
<p
766768
v-if="viewMode === 'cards' && paginationMode === 'infinite'"
767-
class="text-fg-muted text-sm mt-4 font-mono"
769+
class="flex items-center text-fg-muted text-sm mt-4 font-mono"
768770
>
769771
<template v-if="isRelevanceSort">
770-
{{
772+
<span>{{
771773
$t(
772774
'search.found_packages',
773775
{ count: $n(visibleResults.total) },
774776
visibleResults.total,
775777
)
776-
}}
778+
}}</span>
779+
<ClientOnly>
780+
<TooltipApp
781+
v-if="resultsLimitAppliedText"
782+
position="top"
783+
:text="resultsLimitAppliedText"
784+
class="ms-1"
785+
>
786+
<span
787+
class="i-lucide:info w-3 h-3 text-fg-subtle cursor-help"
788+
aria-hidden="true"
789+
/>
790+
</TooltipApp>
791+
</ClientOnly>
777792
</template>
778793
<template v-else>
779794
{{
@@ -786,25 +801,33 @@ onBeforeUnmount(() => {
786801
</p>
787802
<p
788803
v-if="viewMode === 'table' || paginationMode === 'paginated'"
789-
class="text-fg-muted text-sm mt-4 font-mono"
804+
class="flex items-center text-fg-muted text-sm mt-4 font-mono"
790805
>
791-
{{
792-
$t(
793-
'filters.count.showing_paginated',
794-
{
795-
pageSize: Math.min(preferredPageSize, effectiveTotal),
796-
count: $n(effectiveTotal),
797-
},
798-
effectiveTotal,
799-
)
800-
}}
801-
<TooltipApp
802-
v-if="resultsLimitAppliedText"
803-
position="top"
804-
:text="resultsLimitAppliedText"
805-
>
806-
<span class="i-lucide:info w-3 h-3 text-fg-subtle cursor-help" aria-hidden="true" />
807-
</TooltipApp>
806+
<span
807+
>{{
808+
$t(
809+
'filters.count.showing_paginated',
810+
{
811+
pageSize: Math.min(preferredPageSize, effectiveTotal),
812+
count: $n(effectiveTotal),
813+
},
814+
effectiveTotal,
815+
)
816+
}}
817+
</span>
818+
<ClientOnly>
819+
<TooltipApp
820+
v-if="resultsLimitAppliedText"
821+
position="top"
822+
:text="resultsLimitAppliedText"
823+
class="ms-1"
824+
>
825+
<span
826+
class="i-lucide:info w-3 h-3 text-fg-subtle cursor-help"
827+
aria-hidden="true"
828+
/>
829+
</TooltipApp>
830+
</ClientOnly>
808831
</p>
809832
</div>
810833

0 commit comments

Comments
 (0)