Skip to content

Commit

Permalink
fix: cleanup of Geocoder component
Browse files Browse the repository at this point in the history
Signed-off-by: Vinayak Kulkarni <19776877+vinayakkulkarni@users.noreply.github.com>
  • Loading branch information
vinayakkulkarni committed Mar 13, 2023
1 parent 771a8d1 commit 4cab6ba
Showing 1 changed file with 7 additions and 11 deletions.
18 changes: 7 additions & 11 deletions components/map/_partials/Geocoder.vue
Original file line number Diff line number Diff line change
Expand Up @@ -29,11 +29,7 @@
</template>

<script lang="ts">
import { defineComponent, reactive } from 'vue';
import { useNuxtApp } from '#app';
import type { PropType } from 'vue';
import type { AxiosError } from 'axios';
import type { SearchResult, GeocodedFeature } from '@/@types/map';
import type { SearchResult, GeocodedFeature } from '~/@types/map';
export default defineComponent({
name: 'Geocoder',
Expand All @@ -45,7 +41,7 @@
},
},
setup(props) {
const { $axios, $config } = useNuxtApp();
const runtimeConfig = useRuntimeConfig();
const state = reactive({
search: '',
loading: false,
Expand All @@ -57,13 +53,13 @@
async function geocode() {
if (state.search && !state.loading) {
state.loading = true;
const { mapToken } = $config;
const { mapToken } = runtimeConfig;
const queryStr = encodeURIComponent(state.search);
// minLon, minLat, maxLon, maxLat
const bbox = props.bbox;
try {
const { data }: { data: { features: GeocodedFeature[] } } =
await $axios.get(
await useFetch(
`https://api.mapbox.com/geocoding/v5/mapbox.places/${queryStr}.json?access_token=${mapToken}&bbox=${bbox}`,
);
if (data && data.features) {
Expand All @@ -77,10 +73,10 @@
});
}
state.loading = false;
} catch (error: unknown) {
const { response } = error as AxiosError;
} catch (error) {
console.log('error: ', error);
state.loading = false;
alert(response!.data.message);
// alert(error.data.message);
} finally {
state.loading = false;
}
Expand Down

0 comments on commit 4cab6ba

Please sign in to comment.