Skip to content

Commit bbcfb81

Browse files
committed
fix
1 parent 80e8db3 commit bbcfb81

File tree

2 files changed

+22
-38
lines changed

2 files changed

+22
-38
lines changed

app/components/Header/SearchBox.vue

Lines changed: 21 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -28,39 +28,23 @@ const searchQuery = shallowRef(normalizeSearchParam(route.query.q))
2828
// Pages that have their own local filter using ?q
2929
const pagesWithLocalFilter = new Set(['~username', 'org'])
3030
31-
// Debounced URL update for search query
3231
const updateUrlQuery = debounce((value: string) => {
33-
// Don't navigate away from pages that use ?q for local filtering
34-
if (pagesWithLocalFilter.has(route.name as string)) {
35-
return
36-
}
3732
if (route.name === 'search') {
3833
router.replace({ query: { q: value || undefined } })
39-
return
40-
}
41-
if (!value) {
42-
return
4334
}
44-
45-
router.push({
46-
name: 'search',
47-
query: {
48-
q: value,
49-
},
50-
})
5135
}, 250)
5236
53-
// Watch input and debounce URL updates
54-
watch(searchQuery, value => {
55-
updateUrlQuery(value)
37+
watch(searchQuery, (value) => {
38+
if (route.name === 'search') {
39+
updateUrlQuery(value)
40+
}
5641
})
5742
5843
// Sync input with URL when navigating (e.g., back button)
5944
watch(
6045
() => route.query.q,
61-
urlQuery => {
62-
// Don't sync from pages that use ?q for local filtering
63-
if (pagesWithLocalFilter.has(route.name as string)) {
46+
(urlQuery) => {
47+
if (pagesWithLocalFilter.has(route.name)) {
6448
return
6549
}
6650
const value = normalizeSearchParam(urlQuery)
@@ -80,15 +64,25 @@ function handleSearchFocus() {
8064
}
8165
8266
function handleSubmit() {
83-
if (pagesWithLocalFilter.has(route.name as string)) {
67+
const query = searchQuery.value.trim()
68+
if (pagesWithLocalFilter.has(route.name)) {
8469
router.push({
8570
name: 'search',
86-
query: {
87-
q: searchQuery.value,
88-
},
71+
query: { q: query },
8972
})
90-
} else {
73+
return
74+
}
75+
76+
if (route.name === 'search') {
9177
updateUrlQuery.flush()
78+
return
79+
}
80+
81+
if (query) {
82+
router.push({
83+
name: 'search',
84+
query: { q: query },
85+
})
9286
}
9387
}
9488

app/pages/index.vue

Lines changed: 1 addition & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,4 @@
11
<script setup lang="ts">
2-
import { debounce } from 'perfect-debounce'
32
import { SHOWCASED_FRAMEWORKS } from '~/utils/frameworks'
43
54
const searchQuery = shallowRef('')
@@ -11,18 +10,10 @@ async function search() {
1110
if (!query) return
1211
await navigateTo({
1312
path: '/search',
14-
query: query ? { q: query } : undefined,
13+
query: { q: query },
1514
})
16-
const newQuery = searchQuery.value.trim()
17-
if (newQuery !== query) {
18-
await search()
19-
}
2015
}
2116
22-
const handleInput = isTouchDevice()
23-
? search
24-
: debounce(search, 250, { leading: true, trailing: true })
25-
2617
useSeoMeta({
2718
title: () => $t('seo.home.title'),
2819
ogTitle: () => $t('seo.home.title'),
@@ -93,7 +84,6 @@ defineOgImageComponent('Default', {
9384
:placeholder="$t('search.placeholder')"
9485
v-bind="noCorrect"
9586
class="w-full bg-bg-subtle border border-border rounded-xl ps-8 pe-24 h-14 py-4 font-mono text-base text-fg placeholder:text-fg-subtle transition-[border-color,outline-color] duration-300 motion-reduce:transition-none hover:border-fg-subtle outline-2 outline-transparent focus:border-accent focus-visible:(outline-2 outline-accent/70)"
96-
@input="handleInput"
9787
/>
9888

9989
<ButtonBase

0 commit comments

Comments
 (0)