11<script setup lang="ts">
2- const { searchProvider, isAlgolia } = useSearchProvider ()
2+ const route = useRoute ()
3+ const router = useRouter ()
4+ const { searchProvider } = useSearchProvider ()
5+ const searchProviderValue = computed (() => {
6+ const p = normalizeSearchParam (route .query .p )
7+ if (p === ' npm' || searchProvider .value === ' npm' ) return ' npm'
8+ return ' algolia'
9+ })
310
411const isOpen = shallowRef (false )
512const toggleRef = useTemplateRef (' toggleRef' )
@@ -47,21 +54,25 @@ useEventListener('keydown', event => {
4754 type =" button"
4855 role =" menuitem"
4956 class =" w-full flex items-start gap-3 px-3 py-2.5 rounded-md text-start transition-colors hover:bg-bg-muted"
50- :class =" [!isAlgolia ? 'bg-bg-muted' : '']"
57+ :class =" [searchProviderValue !== 'algolia' ? 'bg-bg-muted' : '']"
5158 @click ="
5259 () => {
5360 searchProvider = 'npm'
61+ router.push({ query: { ...route.query, p: 'npm' } })
5462 isOpen = false
5563 }
5664 "
5765 >
5866 <span
5967 class =" i-carbon:catalog w-4 h-4 mt-0.5 shrink-0"
60- :class =" !isAlgolia ? 'text-accent' : 'text-fg-muted'"
68+ :class =" searchProviderValue !== 'algolia' ? 'text-accent' : 'text-fg-muted'"
6169 aria-hidden =" true"
6270 />
6371 <div class =" min-w-0 flex-1" >
64- <div class =" text-sm font-medium" :class =" !isAlgolia ? 'text-fg' : 'text-fg-muted'" >
72+ <div
73+ class =" text-sm font-medium"
74+ :class =" searchProviderValue !== 'algolia' ? 'text-fg' : 'text-fg-muted'"
75+ >
6576 {{ $t('settings.data_source.npm') }}
6677 </div >
6778 <p class =" text-xs text-fg-subtle mt-0.5" >
@@ -75,21 +86,25 @@ useEventListener('keydown', event => {
7586 type =" button"
7687 role =" menuitem"
7788 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"
78- :class =" [isAlgolia ? 'bg-bg-muted' : '']"
89+ :class =" [searchProviderValue === 'algolia' ? 'bg-bg-muted' : '']"
7990 @click ="
8091 () => {
8192 searchProvider = 'algolia'
93+ router.push({ query: { ...route.query, p: undefined } })
8294 isOpen = false
8395 }
8496 "
8597 >
8698 <span
8799 class =" i-carbon:search w-4 h-4 mt-0.5 shrink-0"
88- :class =" isAlgolia ? 'text-accent' : 'text-fg-muted'"
100+ :class =" searchProviderValue === 'algolia' ? 'text-accent' : 'text-fg-muted'"
89101 aria-hidden =" true"
90102 />
91103 <div class =" min-w-0 flex-1" >
92- <div class =" text-sm font-medium" :class =" isAlgolia ? 'text-fg' : 'text-fg-muted'" >
104+ <div
105+ class =" text-sm font-medium"
106+ :class =" searchProviderValue === 'algolia' ? 'text-fg' : 'text-fg-muted'"
107+ >
93108 {{ $t('settings.data_source.algolia') }}
94109 </div >
95110 <p class =" text-xs text-fg-subtle mt-0.5" >
@@ -99,7 +114,10 @@ useEventListener('keydown', event => {
99114 </button >
100115
101116 <!-- Algolia attribution -->
102- <div v-if =" isAlgolia" class =" border-t border-border mx-1 mt-1 pt-2 pb-1" >
117+ <div
118+ v-if =" searchProviderValue === 'algolia'"
119+ class =" border-t border-border mx-1 mt-1 pt-2 pb-1"
120+ >
103121 <a
104122 href =" https://www.algolia.com/developers"
105123 target =" _blank"
0 commit comments