Skip to content

Commit 54e95b5

Browse files
committed
fix: address code review comments
1 parent e5022a5 commit 54e95b5

File tree

4 files changed

+15
-9
lines changed

4 files changed

+15
-9
lines changed

app/components/SearchProviderToggle.client.vue

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -74,7 +74,7 @@ useEventListener('keydown', event => {
7474
<button
7575
type="button"
7676
role="menuitem"
77-
class="w-full flex items-start gap-3 px-3 py-2.5 rounded-md text-start transition-colors hover:bg-bg-muted"
77+
class="w-full flex items-start gap-3 px-3 py-2.5 rounded-md text-start transition-colors hover:bg-bg-muted mt-1"
7878
:class="[isAlgolia ? 'bg-bg-muted' : '']"
7979
@click="
8080
() => {

app/composables/npm/useAlgoliaSearch.ts

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -158,7 +158,7 @@ export function useAlgoliaSearch() {
158158

159159
const response = results[0] as SearchResponse<AlgoliaHit> | undefined
160160
if (!response) {
161-
return { isStale: false, objects: [], total: 0, time: new Date().toISOString() }
161+
throw new Error('Algolia returned an empty response')
162162
}
163163

164164
return {
@@ -186,7 +186,10 @@ export function useAlgoliaSearch() {
186186

187187
// Algolia supports up to 1000 results per query with offset/length pagination
188188
while (offset < max) {
189-
const length = Math.min(batchSize, max - offset)
189+
// Cap at both the configured max and the server's actual total (once known)
190+
const remaining = serverTotal > 0 ? Math.min(max, serverTotal) - offset : max - offset
191+
if (remaining <= 0) break
192+
const length = Math.min(batchSize, remaining)
190193

191194
const { results } = await client.search([
192195
{

app/composables/npm/useUserPackages.ts

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -200,12 +200,15 @@ export function useUserPackages(username: MaybeRefOrGetter<string>) {
200200
return asyncData.data.value
201201
})
202202

203-
/** Whether there are more results available to load */
203+
/** Whether there are more results available to load (npm path only) */
204204
const hasMore = computed(() => {
205-
// Algolia fetches everything in one go
205+
// Non-npm providers fetch everything in one request
206206
if (searchProvider.value !== 'npm') return false
207207
if (!cache.value) return true
208-
return cache.value.objects.length < Math.min(cache.value.total, MAX_RESULTS)
208+
// npm path: more available if we haven't hit the server total or our cap
209+
const fetched = cache.value.objects.length
210+
const available = cache.value.total
211+
return fetched < available && fetched < MAX_RESULTS
209212
})
210213

211214
return {

app/pages/~[username]/index.vue

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -175,14 +175,14 @@ defineOgImageComponent('Default', {
175175
</div>
176176
</header>
177177

178-
<!-- Loading state -->
178+
<!-- Loading state (only on initial load, not when we already have data) -->
179179
<LoadingSpinner
180-
v-if="status === 'pending' && packages.length === 0"
180+
v-if="status === 'pending' && packages.length === 0 && !error"
181181
:text="$t('common.loading_packages')"
182182
/>
183183

184184
<!-- Error state -->
185-
<div v-else-if="status === 'error'" role="alert" class="py-12 text-center">
185+
<div v-else-if="error || status === 'error'" role="alert" class="py-12 text-center">
186186
<p class="text-fg-muted mb-4">
187187
{{ error?.message ?? $t('user.page.failed_to_load') }}
188188
</p>

0 commit comments

Comments
 (0)