MCPcopy Index your code
hub / github.com/npmx-dev/npmx.dev / updateUrlQueryImpl

Function updateUrlQueryImpl

app/composables/useGlobalSearch.ts:54–78  ·  view source on GitHub ↗
(value: string, provider: 'npm' | 'algolia')

Source from the content-addressed store, hash-verified

52
53 // Updates URL when search query changes (immediately for instantSearch or after Enter hit otherwise)
54 const updateUrlQueryImpl = (value: string, provider: 'npm' | 'algolia') => {
55 const isSameQuery = route.query.q === value && route.query.p === provider
56 // Don't navigate away from pages that use ?q for local filtering
57 if ((pagesWithLocalFilter.has(route.name as string) && place === 'content') || isSameQuery) {
58 return
59 }
60
61 if (route.name === 'search') {
62 router.replace({
63 query: {
64 ...route.query,
65 q: value || undefined,
66 p: provider === 'npm' ? 'npm' : undefined,
67 },
68 })
69 return
70 }
71 router.push({
72 name: 'search',
73 query: {
74 q: value,
75 p: provider === 'npm' ? 'npm' : undefined,
76 },
77 })
78 }
79
80 const updateUrlQuery = debounce(updateUrlQueryImpl, SEARCH_DEBOUNCE_MS)
81

Callers 2

flushUpdateUrlQueryFunction · 0.85
useGlobalSearchFunction · 0.85

Calls

no outgoing calls

Tested by

no test coverage detected