Skip to content

Commit

Permalink
fixed autocomplete, to go to the location
Browse files Browse the repository at this point in the history
  • Loading branch information
onmax committed Sep 8, 2023
1 parent 7016337 commit 49399f9
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 5 deletions.
17 changes: 13 additions & 4 deletions src/components/elements/InteractionBar.vue
Original file line number Diff line number Diff line change
Expand Up @@ -2,32 +2,41 @@
import { type Suggestion, SuggestionType } from 'types'
import { useBreakpoints } from '@vueuse/core'
import { screens } from 'tailwindcss-nimiq-theme'
import { computed } from 'vue'
import { computed, nextTick } from 'vue'
import { storeToRefs } from 'pinia'
import SearchBox from '@/components/atoms/SearchBox.vue'
import CryptoMapModal from '@/components/elements/CryptoMapModal.vue'
import { useAutocomplete } from '@/composables/useAutocomplete'
import { useMap } from '@/stores/map'
import { useLocations } from '@/stores/locations'
import { useApp } from '@/stores/app'
import { useCluster } from '@/stores/cluster'
defineEmits({
open: (value: boolean) => value,
})
const { querySearch, status, suggestions } = useAutocomplete()
function onSelect(suggestion?: Suggestion) {
const { singles } = storeToRefs(useCluster())
const sleep = (ms: number) => new Promise(resolve => setTimeout(resolve, ms))
async function onSelect(suggestion?: Suggestion) {
if (!suggestion)
return
switch (suggestion.type) {
case SuggestionType.GoogleLocation:
case SuggestionType.Region:
useMap().goToPlaceId(suggestion.id)
break
case SuggestionType.Location:
useLocations().goToLocation(suggestion.id)
if (await useLocations().goToLocation(suggestion.id)) {
while (!singles.value.some(s => s.uuid === suggestion.id))
await sleep(100) // Try to wait for the item to be added
await nextTick() // Wait for the marker to be rendered
;(document.querySelector(`[data-trigger-uuid="${suggestion.id}"]`) as HTMLElement)?.click()
}
break
}
Expand Down
4 changes: 3 additions & 1 deletion src/stores/locations.ts
Original file line number Diff line number Diff line change
Expand Up @@ -57,10 +57,12 @@ export const useLocations = defineStore('locations', () => {
})

async function goToLocation(uuid: string) {
const location = await useLocations().getLocationByUuid(uuid)
const location = await getLocationByUuid(uuid)
if (!location)
return false

selectedUuid.value = uuid

useMap().setPosition({
center: { lat: location.lat, lng: location.lng },
zoom: 19,
Expand Down

0 comments on commit 49399f9

Please sign in to comment.