feat(geocoding): remove server side fetch
This commit is contained in:
@@ -3,6 +3,7 @@ import type { Category, CreateReportRequest } from '~/types/api'
|
||||
import type { LeafletMouseEvent, Map as LeafletMap, Marker as LeafletMarker } from 'leaflet'
|
||||
import { onMounted, onUnmounted, ref, watch } from 'vue'
|
||||
import { BARI_BOUNDS, BARI_CENTER, isWithinBariBounds } from '~/utils/bari'
|
||||
import { reverseGeocode, searchAddresses } from '~/utils/geocoding'
|
||||
|
||||
interface Props {
|
||||
isLoading?: boolean
|
||||
@@ -19,14 +20,6 @@ interface GeocodingSuggestion {
|
||||
longitude: number
|
||||
}
|
||||
|
||||
interface SearchAddressesResponse {
|
||||
suggestions: GeocodingSuggestion[]
|
||||
}
|
||||
|
||||
interface ReverseGeocodeResponse {
|
||||
address: string
|
||||
}
|
||||
|
||||
const props = withDefaults(defineProps<Props>(), {
|
||||
isLoading: false,
|
||||
categories: () => []
|
||||
@@ -123,18 +116,20 @@ const fetchAddressSuggestions = async (query: string) => {
|
||||
addressSearchError.value = ''
|
||||
|
||||
try {
|
||||
const response = await $fetch<SearchAddressesResponse>('/api/geocoding/search', {
|
||||
query: { q: query }
|
||||
})
|
||||
if (requestId !== addressSearchRequestId) {
|
||||
return
|
||||
}
|
||||
|
||||
const suggestions = await searchAddresses(query)
|
||||
|
||||
if (requestId !== addressSearchRequestId) {
|
||||
return
|
||||
}
|
||||
|
||||
addressSuggestions.value = response.suggestions
|
||||
showAddressSuggestions.value = response.suggestions.length > 0
|
||||
addressSuggestions.value = suggestions
|
||||
showAddressSuggestions.value = suggestions.length > 0
|
||||
|
||||
if (!response.suggestions.length) {
|
||||
if (!suggestions.length) {
|
||||
addressSearchError.value = 'Nessun indirizzo trovato nel Comune di Bari.'
|
||||
}
|
||||
} catch {
|
||||
@@ -157,15 +152,11 @@ const resolveAddressFromCoordinates = async (lat: number, lng: number, fallbackA
|
||||
addressSearchError.value = ''
|
||||
|
||||
try {
|
||||
const response = await $fetch<ReverseGeocodeResponse>('/api/geocoding/reverse', {
|
||||
query: { lat, lng }
|
||||
})
|
||||
|
||||
if (requestId !== reverseGeocodeRequestId) {
|
||||
return
|
||||
}
|
||||
|
||||
const resolvedAddress = response.address?.trim() || fallbackAddress.trim()
|
||||
const resolvedAddress = (await reverseGeocode(lat, lng))?.trim() || fallbackAddress.trim()
|
||||
|
||||
if (resolvedAddress) {
|
||||
setAddressValue(resolvedAddress)
|
||||
@@ -694,4 +685,3 @@ textarea {
|
||||
align-items: center;
|
||||
}
|
||||
</style>
|
||||
|
||||
|
||||
Reference in New Issue
Block a user