Skip to content
23 changes: 7 additions & 16 deletions app/pages/index.vue
Original file line number Diff line number Diff line change
@@ -1,21 +1,14 @@
<script setup lang="ts">
import { debounce } from 'perfect-debounce'

const router = useRouter()
const searchQuery = ref('')
const searchInputRef = useTemplateRef('searchInputRef')
const { focused: isSearchFocused } = useFocus(searchInputRef)

const debouncedNavigate = debounce(() => {
function handleSubmit() {
router.push({
path: '/search',
query: searchQuery.value.trim() ? { q: searchQuery.value.trim() } : undefined,
name: 'search',
query: {
q: searchQuery.value.trim(),
},
})
}, 250)

function handleSearch() {
// If input is empty, navigate immediately (no need to debounce)
return searchQuery.value.trim() ? debouncedNavigate() : router.push('/search')
}

useSeoMeta({
Expand Down Expand Up @@ -49,13 +42,12 @@ defineOgImageComponent('Default')
class="w-full max-w-xl motion-safe:animate-slide-up motion-safe:animate-fill-both"
style="animation-delay: 0.2s"
>
<form method="GET" action="/search" class="relative" @submit.prevent="handleSearch">
<form method="GET" action="/search" class="relative" @submit.prevent="handleSubmit">
<label for="home-search" class="sr-only">
{{ $t('search.label') }}
</label>

<!-- Search input with glow effect on focus -->
<div class="relative group" :class="{ 'is-focused': isSearchFocused }">
<div class="relative group">
<!-- Subtle glow effect -->
<div
class="absolute -inset-px rounded-lg bg-gradient-to-r from-fg/0 via-fg/5 to-fg/0 opacity-0 transition-opacity duration-500 blur-sm group-[.is-focused]:opacity-100"
Expand All @@ -78,7 +70,6 @@ defineOgImageComponent('Default')
v-bind="noCorrect"
autofocus
class="w-full bg-bg-subtle border border-border rounded-lg ps-8 pe-24 py-4 font-mono text-base text-fg placeholder:text-fg-subtle transition-border-color duration-300 focus:border-accent focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-accent/50"
@input="handleSearch"
/>

<button
Expand Down
5 changes: 1 addition & 4 deletions test/nuxt/composables/use-colors.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -77,8 +77,6 @@ describe('useCssVariables', () => {
await nextTick()

expect(useMutationObserverMock).not.toHaveBeenCalled()
expect(lastMutationObserverInstance).not.toBeNull()
expect(lastMutationObserverInstance!.observe).toHaveBeenCalledTimes(1)

wrapper.unmount()
})
Expand All @@ -95,8 +93,7 @@ describe('useCssVariables', () => {

await nextTick()

expect(lastMutationObserverInstance).not.toBeNull()
expect(lastMutationObserverInstance!.observe).toHaveBeenCalledTimes(1)
expect(useMutationObserverMock).toHaveBeenCalledOnce()

wrapper.unmount()
})
Expand Down
Loading