Skip to content

Commit 701f49a

Browse files
feat: vary search result title based on type of search
1 parent b8ce04a commit 701f49a

File tree

3 files changed

+28
-6
lines changed

3 files changed

+28
-6
lines changed

src/App.vue

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ import SearchBox from './components/SearchBox.vue'
55
import MapView from './components/MapView.vue'
66
import SearchResults from './components/SearchResults.vue'
77
8-
const searchResults = ref({ matches: [], divisions: [] })
8+
const searchResults = ref({ matches: [], divisions: [], searchTerm: '' })
99
const isResultsExpanded = ref(false)
1010
1111
function handleSearch(results) {
@@ -17,7 +17,8 @@ function handleExpandedChange(expanded) {
1717
}
1818
1919
function handleMapSearch(results) {
20-
searchResults.value = results
20+
// For map searches, ensure we clear any previous search term
21+
searchResults.value = { ...results, searchTerm: '' }
2122
isResultsExpanded.value = true
2223
}
2324
</script>

src/components/SearchBox.vue

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,7 @@ watch(searchQuery, debounce(async (newQuery) => {
3333
await handleSearch()
3434
} else {
3535
console.log('Query too short, clearing results')
36-
emit('search', { matches: [], divisions: [] })
36+
emit('search', { matches: [], divisions: [], searchTerm: '' })
3737
}
3838
}, 300))
3939
@@ -62,7 +62,8 @@ async function handleSearch() {
6262
6363
emit('search', {
6464
matches: data,
65-
divisions: divisions
65+
divisions: divisions,
66+
searchTerm: searchQuery.value
6667
})
6768
} catch (err) {
6869
console.error('Search error:', err)

src/components/SearchResults.vue

Lines changed: 22 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ import { ref, computed, watch } from 'vue'
44
const props = defineProps({
55
results: {
66
type: Object,
7-
default: () => ({ matches: [], divisions: [] })
7+
default: () => ({ matches: [], divisions: [], searchTerm: '' })
88
}
99
})
1010
@@ -16,6 +16,26 @@ const sortedResults = computed(() => {
1616
return [...props.results.matches].sort((a, b) => a.name.localeCompare(b.name))
1717
})
1818
19+
// Compute the results title based on the type of search
20+
const resultsTitle = computed(() => {
21+
if (props.results.matches.length === 0) {
22+
return 'No Results'
23+
}
24+
25+
// If there's a search term, it's a text-based search
26+
if (props.results.searchTerm) {
27+
return `Search Results for "${props.results.searchTerm}" - ${props.results.matches.length} Results`
28+
}
29+
30+
// If there's exactly one division, it's from a map click
31+
if (props.results.divisions.length === 1) {
32+
return `Division ${props.results.divisions[0]} - ${props.results.matches.length} Results`
33+
}
34+
35+
// Default case
36+
return `${props.results.matches.length} Results`
37+
})
38+
1939
// Watch for changes in results to auto-expand/collapse
2040
watch(() => props.results.matches.length, (newCount) => {
2141
// Auto-expand if there are any results
@@ -37,7 +57,7 @@ const toggleExpand = () => {
3757
<template>
3858
<div class="search-results" :class="{ expanded: isExpanded }">
3959
<div class="results-header" @click="toggleExpand">
40-
<span class="result-count">{{ props.results.matches.length }} Results</span>
60+
<span class="result-count">{{ resultsTitle }}</span>
4161
<button class="expand-button">
4262
{{ isExpanded ? '▼' : '▲' }}
4363
</button>

0 commit comments

Comments
 (0)