Skip to content

Commit 2641a99

Browse files
committed
fix: address coderabbit reviews
1 parent 54e95b5 commit 2641a99

File tree

2 files changed

+10
-6
lines changed

2 files changed

+10
-6
lines changed

app/composables/npm/useUserPackages.ts

Lines changed: 9 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@ const MAX_RESULTS = 250
2323
*/
2424
export function useUserPackages(username: MaybeRefOrGetter<string>) {
2525
const { searchProvider } = useSearchProvider()
26+
// this is only used in npm path, but we need to extract it when the composable runs
2627
const { $npmRegistry } = useNuxtApp()
2728
const { searchByOwner } = useAlgoliaSearch()
2829

@@ -103,7 +104,11 @@ export function useUserPackages(username: MaybeRefOrGetter<string>) {
103104
{ default: () => emptySearchResponse },
104105
)
105106
// --- Fetch more (npm path only) ---
106-
async function fetchMore(): Promise<void> {
107+
/**
108+
* Fetch the next page of results from npm registry.
109+
* @param manageLoadingState - When false, caller manages isLoadingMore (used by loadAll to prevent flicker)
110+
*/
111+
async function fetchMore(manageLoadingState = true): Promise<void> {
107112
const user = toValue(username)
108113
const provider = searchProvider.value
109114
if (!user || provider !== 'npm') return
@@ -119,7 +124,7 @@ export function useUserPackages(username: MaybeRefOrGetter<string>) {
119124

120125
if (currentCount >= total) return
121126

122-
isLoadingMore.value = true
127+
if (manageLoadingState) isLoadingMore.value = true
123128

124129
try {
125130
const from = currentCount
@@ -155,7 +160,7 @@ export function useUserPackages(username: MaybeRefOrGetter<string>) {
155160
}
156161
}
157162
} finally {
158-
isLoadingMore.value = false
163+
if (manageLoadingState) isLoadingMore.value = false
159164
}
160165
}
161166

@@ -173,7 +178,7 @@ export function useUserPackages(username: MaybeRefOrGetter<string>) {
173178
isLoadingMore.value = true
174179
try {
175180
while (hasMore.value) {
176-
await fetchMore()
181+
await fetchMore(false)
177182
}
178183
} finally {
179184
isLoadingMore.value = false
@@ -184,7 +189,6 @@ export function useUserPackages(username: MaybeRefOrGetter<string>) {
184189
watch(searchProvider, () => {
185190
cache.value = null
186191
currentPage.value = 1
187-
asyncData.refresh()
188192
})
189193

190194
// Computed data that uses cache

app/pages/settings.vue

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -166,7 +166,7 @@ const setLocale: typeof setNuxti18nLocale = locale => {
166166
<select
167167
id="search-provider-select"
168168
:value="settings.searchProvider"
169-
class="w-full sm:w-auto min-w-48 bg-bg border border-border rounded-md px-3 py-2 text-sm text-fg focus-visible:outline-accent/70 cursor-pointer duration-200 transition-colors hover:border-fg-subtle"
169+
class="w-full sm:w-auto min-w-48 bg-bg border border-border rounded-md px-3 py-2 text-sm text-fg cursor-pointer duration-200 transition-colors hover:border-fg-subtle"
170170
@change="
171171
settings.searchProvider = ($event.target as HTMLSelectElement)
172172
.value as typeof settings.searchProvider

0 commit comments

Comments
 (0)