Skip to content

Commit 1c7fcc9

Browse files
feat: move location loading state to results bar
1 parent 49ab54e commit 1c7fcc9

File tree

3 files changed

+21
-12
lines changed

3 files changed

+21
-12
lines changed

src/App.vue

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@ const isResultsExpanded = ref(false)
1010
const searchQuery = ref('')
1111
const isSearching = ref(false)
1212
const isDivisionLoading = ref(false)
13+
const isLocationLoading = ref(false)
1314
1415
function handleSearch(results) {
1516
searchResults.value = results
@@ -30,6 +31,10 @@ function handleMapSearch(results) {
3031
function handleDivisionLoadingChange(loading) {
3132
isDivisionLoading.value = loading
3233
}
34+
35+
function handleLocationLoadingChange(loading) {
36+
isLocationLoading.value = loading
37+
}
3338
</script>
3439

3540
<template>
@@ -45,10 +50,12 @@ function handleDivisionLoadingChange(loading) {
4550
:isResultsExpanded="isResultsExpanded"
4651
@update:searchResults="handleMapSearch"
4752
@update:loading="handleDivisionLoadingChange"
53+
@update:locationLoading="handleLocationLoadingChange"
4854
/>
4955
<SearchResults
5056
:results="searchResults"
5157
:isLoading="isSearching || isDivisionLoading"
58+
:isLocationLoading="isLocationLoading"
5259
@update:expanded="handleExpandedChange"
5360
/>
5461
</div>

src/components/MapView.vue

Lines changed: 4 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,6 @@ let userMarker = null
1313
1414
// Loading states
1515
const isLoadingMap = ref(true)
16-
const isLoadingLocation = ref(false)
1716
1817
// Initialize Supabase client
1918
const supabase = createClient(
@@ -44,7 +43,7 @@ const props = defineProps({
4443
}
4544
})
4645
47-
const emit = defineEmits(['update:searchResults', 'update:loading'])
46+
const emit = defineEmits(['update:searchResults', 'update:loading', 'update:locationLoading'])
4847
4948
// Create a custom marker element
5049
function createMarkerElement() {
@@ -185,7 +184,7 @@ async function selectDivision(division, location = null) {
185184
186185
// Function to highlight user's division
187186
async function highlightUserDivision() {
188-
isLoadingLocation.value = true;
187+
emit('update:locationLoading', true);
189188
190189
try {
191190
const location = await getUserLocation();
@@ -212,7 +211,7 @@ async function highlightUserDivision() {
212211
} catch (error) {
213212
console.error('Error getting user location:', error);
214213
} finally {
215-
isLoadingLocation.value = false;
214+
emit('update:locationLoading', false);
216215
}
217216
}
218217
@@ -328,16 +327,11 @@ onUnmounted(() => {
328327
<div class="map-container">
329328
<div ref="mapContainer" class="map"></div>
330329

331-
<!-- Loading overlays -->
330+
<!-- Loading overlay -->
332331
<div v-if="isLoadingMap" class="loading-overlay">
333332
<div class="loading-spinner"></div>
334333
<div class="loading-text">Loading map data...</div>
335334
</div>
336-
337-
<div v-if="isLoadingLocation" class="loading-overlay">
338-
<div class="loading-spinner"></div>
339-
<div class="loading-text">Getting your location...</div>
340-
</div>
341335
</div>
342336
</template>
343337

src/components/SearchResults.vue

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,10 @@ const props = defineProps({
1010
isLoading: {
1111
type: Boolean,
1212
default: false
13+
},
14+
isLocationLoading: {
15+
type: Boolean,
16+
default: false
1317
}
1418
})
1519
@@ -25,6 +29,10 @@ const hasResults = computed(() => props.results.matches.length > 0)
2529
2630
// Compute the results title based on the type of search
2731
const resultsTitle = computed(() => {
32+
if (props.isLocationLoading) {
33+
return 'Getting your location...'
34+
}
35+
2836
if (props.isLoading) {
2937
return 'Loading results...'
3038
}
@@ -61,7 +69,7 @@ watch(() => props.results.matches.length, (newCount) => {
6169
6270
const toggleExpand = () => {
6371
// Only allow toggling if there are results and not loading
64-
if (hasResults.value && !props.isLoading) {
72+
if (hasResults.value && !props.isLoading && !props.isLocationLoading) {
6573
isExpanded.value = !isExpanded.value
6674
emit('update:expanded', isExpanded.value)
6775
}
@@ -73,7 +81,7 @@ const toggleExpand = () => {
7381
<div class="results-header" @click="toggleExpand">
7482
<div class="header-content">
7583
<span class="result-count">{{ resultsTitle }}</span>
76-
<div v-if="props.isLoading" class="loading-spinner"></div>
84+
<div v-if="isLoading || isLocationLoading" class="loading-spinner"></div>
7785
<button v-else-if="hasResults" class="expand-button">
7886
{{ isExpanded ? '▼' : '▲' }}
7987
</button>

0 commit comments

Comments
 (0)