Skip to content

Commit

Permalink
More feedback in geolocation
Browse files Browse the repository at this point in the history
Default to IP if user denied geolocation services
Added circle spinner while loading data
  • Loading branch information
Albermonte committed Aug 31, 2023
1 parent 005c314 commit dcb62c7
Showing 1 changed file with 18 additions and 3 deletions.
21 changes: 18 additions & 3 deletions src/components/elements/Controls.vue
Original file line number Diff line number Diff line change
@@ -1,15 +1,28 @@
<script setup lang="ts">
import { ref } from 'vue'
import IconCircleSpinner from '../icons/icon-circle-spinner.vue'
import Button from '@/components/atoms/Button.vue'
import GeolocationIcon from '@/components/icons/icon-geolocation.vue'
import MinusIcon from '@/components/icons/icon-minus.vue'
import PlusIcon from '@/components/icons/icon-plus.vue'
import { useGeoIp } from '@/composables/useGeoLocation'
import { useMap } from '@/stores/map'
const { browserPositionIsSupported, geolocateUserViaBrowser, geolocatingUserBrowser } = useGeoIp()
const isGeolocationLoading = ref(false)
const { browserPositionIsSupported, ipPosition, ipPositionError, geolocateIp, geolocateUserViaBrowser, geolocatingUserBrowser, errorBrowser } = useGeoIp()
async function setBrowserPosition() {
isGeolocationLoading.value = true
const browserPosition = await geolocateUserViaBrowser()
if (errorBrowser.value) {
alert(`${errorBrowser.value.message}. Moving to closest location`)

This comment has been minimized.

Copy link
@onmax

onmax Aug 31, 2023

Member

Can we remove the alert? I don't think is neccesary tbh @Albermonte

This comment has been minimized.

Copy link
@Albermonte

Albermonte Aug 31, 2023

Author Member

I think we should give more feedback to the user, at least letting him know that their location services are not enabled because he may want to enable them and try again. It doesn't need to be an alert, that's temporary

await geolocateIp()
if (!ipPositionError.value && ipPosition.value)
useMap().setPosition(ipPosition.value)
isGeolocationLoading.value = false
return
}
isGeolocationLoading.value = false

This comment has been minimized.

Copy link
@onmax

onmax Aug 31, 2023

Member

It would be nice to have at least 800ms of loading spinner. If the function runs in 40ms, the user will see a quick flash, which is not a nice thing to see. Wdty?

This comment has been minimized.

Copy link
@Albermonte

Albermonte Aug 31, 2023

Author Member

So delaying everything even the setPosition?

useMap().setPosition(browserPosition)
}
</script>
Expand All @@ -19,10 +32,12 @@ async function setBrowserPosition() {
<Button
v-if="browserPositionIsSupported"
:disabled="geolocatingUserBrowser" style="width: 34px; height: 34px" bg-color="white" size="sm" :aria-label="$t('Show your location')"
:title="$t('Show your location')" @click="setBrowserPosition"
:title="$t('Show your location')"
@click="setBrowserPosition"
>
<template #icon>
<GeolocationIcon />
<GeolocationIcon v-if="!isGeolocationLoading" />
<IconCircleSpinner v-else class="w-4 h-4 text-space" />
</template>
</Button>

Expand Down

0 comments on commit dcb62c7

Please sign in to comment.