Skip to content

Commit 9d6fa0a

Browse files
committed
fix: update provider detection logic
1 parent 2277c02 commit 9d6fa0a

5 files changed

Lines changed: 19 additions & 22 deletions

File tree

app/components/Header/SearchBox.vue

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -16,13 +16,11 @@ const emit = defineEmits(['blur', 'focus'])
1616
const router = useRouter()
1717
const route = useRoute()
1818
const { searchProvider } = useSearchProvider()
19-
// The actual search provider (from URL, used for API calls)
20-
const searchProviderParam = computed(() => {
19+
const searchProviderValue = computed(() => {
2120
const p = normalizeSearchParam(route.query.p)
22-
if (!p && searchProvider.value === 'npm') return 'npm'
23-
return p === 'npm' ? 'npm' : 'algolia'
21+
if (p === 'npm' || searchProvider.value === 'npm') return 'npm'
22+
return 'algolia'
2423
})
25-
const searchProviderValue = computed(() => searchProviderParam.value || searchProvider.value)
2624
2725
const isSearchFocused = shallowRef(false)
2826

app/components/SearchProviderToggle.client.vue

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,12 @@
11
<script setup lang="ts">
22
const route = useRoute()
33
const router = useRouter()
4-
const searchProviderParam = computed(() => {
4+
const { searchProvider } = useSearchProvider()
5+
const searchProviderValue = computed(() => {
56
const p = normalizeSearchParam(route.query.p)
6-
return p === 'npm' ? 'npm' : 'algolia'
7+
if (p === 'npm' || searchProvider.value === 'npm') return 'npm'
8+
return 'algolia'
79
})
8-
const { searchProvider } = useSearchProvider()
9-
const searchProviderValue = computed(() => searchProviderParam.value || searchProvider.value)
1010
1111
const isOpen = shallowRef(false)
1212
const toggleRef = useTemplateRef('toggleRef')

app/composables/npm/useOrgPackages.ts

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -11,12 +11,12 @@ import { mapWithConcurrency } from '#shared/utils/async'
1111
*/
1212
export function useOrgPackages(orgName: MaybeRefOrGetter<string>) {
1313
const route = useRoute()
14-
const searchProviderParam = computed(() => {
14+
const { searchProvider } = useSearchProvider()
15+
const searchProviderValue = computed(() => {
1516
const p = normalizeSearchParam(route.query.p)
16-
return p === 'npm' ? 'npm' : 'algolia'
17+
if (p === 'npm' || searchProvider.value === 'npm') return 'npm'
18+
return 'algolia'
1719
})
18-
const { searchProvider } = useSearchProvider()
19-
const searchProviderValue = computed(() => searchProviderParam.value || searchProvider.value)
2020
const { getPackagesByName } = useAlgoliaSearch()
2121

2222
const asyncData = useLazyAsyncData(

app/composables/npm/useUserPackages.ts

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -23,12 +23,12 @@ const MAX_RESULTS = 250
2323
*/
2424
export function useUserPackages(username: MaybeRefOrGetter<string>) {
2525
const route = useRoute()
26-
const searchProviderParam = computed(() => {
26+
const { searchProvider } = useSearchProvider()
27+
const searchProviderValue = computed(() => {
2728
const p = normalizeSearchParam(route.query.p)
28-
return p === 'npm' ? 'npm' : 'algolia'
29+
if (p === 'npm' || searchProvider.value === 'npm') return 'npm'
30+
return 'algolia'
2931
})
30-
const { searchProvider } = useSearchProvider()
31-
const searchProviderValue = computed(() => searchProviderParam.value || searchProvider.value)
3232
// this is only used in npm path, but we need to extract it when the composable runs
3333
const { $npmRegistry } = useNuxtApp()
3434
const { searchByOwner } = useAlgoliaSearch()

app/pages/search.vue

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -10,13 +10,12 @@ import { normalizeSearchParam } from '#shared/utils/url'
1010
const route = useRoute()
1111
const router = useRouter()
1212
13-
// The actual search provider (from URL, used for API calls)
14-
const searchProviderParam = computed(() => {
13+
const { searchProvider } = useSearchProvider()
14+
const searchProviderValue = computed(() => {
1515
const p = normalizeSearchParam(route.query.p)
16-
return p === 'npm' ? 'npm' : 'algolia'
16+
if (p === 'npm' || searchProvider.value === 'npm') return 'npm'
17+
return 'algolia'
1718
})
18-
const { searchProvider } = useSearchProvider()
19-
const searchProviderValue = computed(() => searchProviderParam.value || searchProvider.value)
2019
2120
// Preferences (persisted to localStorage)
2221
const {

0 commit comments

Comments
 (0)