Skip to content

Commit

Permalink
Cleaner code
Browse files Browse the repository at this point in the history
  • Loading branch information
onmax committed Sep 8, 2023
1 parent 45b8cdf commit e875009
Show file tree
Hide file tree
Showing 3 changed files with 13 additions and 12 deletions.
2 changes: 1 addition & 1 deletion src/components/elements/MapMarkers.vue
Original file line number Diff line number Diff line change
Expand Up @@ -113,7 +113,7 @@ function onClusterClick(center: Point, proposedZoom: number) {
<ReuseTemplate :location="location" class="transition-shadow rounded-sm" />
</PopoverTrigger>
<PopoverPortal>
<PopoverContent side="right" :side-offset="5" class="rounded-lg shadow" @openAutoFocus.prevent>
<PopoverContent side="right" :side-offset="5" class="rounded-lg shadow" @open-auto-focus.prevent>
<Card :location="location" :progress="1" :class="location.photo ? 'max-w-xs' : 'max-w-sm'" />
<PopoverArrow class="w-4 h-2" :style="`fill: ${location.isAtm ? extractColorFromBg(location.bg[0]) : 'white'}`" />

Expand Down
21 changes: 11 additions & 10 deletions src/composables/useInitialMapPosition.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,16 +15,17 @@ export const FALLBACK_POSITION: MapPosition = { center: { lat: 9.6301892, lng: -
export async function useInitialMapPosition(p: RouteParams, query: LocationQuery) {
if (Object.keys(query).includes('uuid')) {
// We need to load the location from the uuid, but we want to keep the map position
(await import('@/stores/locations')).useLocations().getLocationByUuid(query.uuid as string /* UUID already valid. See router.ts */)
.then(async (l) => {
if (l) {
// We set the locations in the store, and then we set the selected location
(await import ('@/stores/cluster')).useCluster().singles = [l]
const sleep = (ms: number) => new Promise(resolve => setTimeout(resolve, ms))
await sleep(100) // We need to wait for the marker to be rendered in the right position to avoid CLS
;(document.querySelector(`[data-trigger-uuid="${query.uuid}"]`) as HTMLElement)?.click()
}
})
const location = await (await import('@/stores/locations')).useLocations().getLocationByUuid(query.uuid as string /* UUID already valid. See router.ts */)
if (location) {
// We set the locations in the store, and then we show the card
(await import ('@/stores/cluster')).useCluster().singles = [location]
const sleep = (ms: number) => new Promise(resolve => setTimeout(resolve, ms))
await sleep(100) // We need to wait for the marker to be rendered in the right position to avoid CLS
;(document.querySelector(`[data-trigger-uuid="${query.uuid}"]`) as HTMLElement)?.click()
}
else {
console.warn(`Location with uuid ${query.uuid} not found`)
}
}

const validFloat = (n?: string | string[]) => !!n && typeof n === 'string' && !Number.isNaN(Number(n))
Expand Down
2 changes: 1 addition & 1 deletion src/stores/cluster.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ import { computeCluster } from '@/../shared/compute-cluster'

export const useCluster = defineStore('cluster', () => {
const { setLocations, getLocations } = useLocations()
const { visitedAreas, locations } = storeToRefs(useLocations())
const { visitedAreas } = storeToRefs(useLocations())
const { filterLocations, filtersToString } = useFilters()
const { zoom, boundingBox } = storeToRefs(useMap())

Expand Down

0 comments on commit e875009

Please sign in to comment.