Skip to content

Commit 6e204cf

Browse files
feat: clear search text when loading a division
1 parent 701f49a commit 6e204cf

File tree

2 files changed

+38
-8
lines changed

2 files changed

+38
-8
lines changed

src/App.vue

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@ import SearchResults from './components/SearchResults.vue'
77
88
const searchResults = ref({ matches: [], divisions: [], searchTerm: '' })
99
const isResultsExpanded = ref(false)
10+
const searchQuery = ref('')
1011
1112
function handleSearch(results) {
1213
searchResults.value = results
@@ -20,13 +21,18 @@ function handleMapSearch(results) {
2021
// For map searches, ensure we clear any previous search term
2122
searchResults.value = { ...results, searchTerm: '' }
2223
isResultsExpanded.value = true
24+
// Clear the search box without triggering a search clear
25+
searchQuery.value = ''
2326
}
2427
</script>
2528

2629
<template>
2730
<div class="app">
2831
<CountdownBar />
29-
<SearchBox @search="handleSearch" />
32+
<SearchBox
33+
v-model="searchQuery"
34+
@search="handleSearch"
35+
/>
3036
<div class="map-wrapper">
3137
<MapView
3238
:searchResults="searchResults"

src/components/SearchBox.vue

Lines changed: 31 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -2,8 +2,15 @@
22
import { ref, watch } from 'vue'
33
import { createClient } from '@supabase/supabase-js'
44
5-
const searchQuery = ref('')
6-
const emit = defineEmits(['search'])
5+
const props = defineProps({
6+
modelValue: {
7+
type: String,
8+
default: ''
9+
}
10+
})
11+
12+
const searchQuery = ref(props.modelValue)
13+
const emit = defineEmits(['search', 'update:modelValue'])
714
815
// Initialize Supabase client
916
const supabase = createClient(
@@ -25,17 +32,34 @@ function debounce(func, wait) {
2532
}
2633
}
2734
28-
// Watch for changes in search query with debounce
29-
watch(searchQuery, debounce(async (newQuery) => {
30-
console.log('Search query changed:', newQuery)
35+
// Watch for external value changes
36+
watch(() => props.modelValue, (newValue) => {
37+
if (newValue !== searchQuery.value) {
38+
searchQuery.value = newValue
39+
}
40+
})
41+
42+
// Watch for internal value changes
43+
watch(searchQuery, (newValue) => {
44+
emit('update:modelValue', newValue)
45+
})
46+
47+
// Watch for search query changes with debounce
48+
const debouncedSearch = debounce(async (query) => {
49+
console.log('Search query changed:', query)
3150
32-
if (newQuery.length >= 3) {
51+
if (query.length >= 3) {
3352
await handleSearch()
53+
} else if (query.length === 0) {
54+
// Don't clear results if the query was cleared externally
55+
console.log('Query cleared')
3456
} else {
3557
console.log('Query too short, clearing results')
3658
emit('search', { matches: [], divisions: [], searchTerm: '' })
3759
}
38-
}, 300))
60+
}, 300)
61+
62+
watch(searchQuery, debouncedSearch)
3963
4064
async function handleSearch() {
4165
if (searchQuery.value.length < 3) return

0 commit comments

Comments
 (0)