Skip to content

Commit

Permalink
Commented out locations variable
Browse files Browse the repository at this point in the history
I suspect that locations variables is not being used anywhere, and we have replaced it for the singles in the clusters
We still have locationsMap to track which locations have been downloaded
  • Loading branch information
onmax committed Sep 5, 2023
1 parent 07c8fc2 commit 2440fba
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 26 deletions.
6 changes: 2 additions & 4 deletions src/stores/app.ts
Original file line number Diff line number Diff line change
@@ -1,18 +1,16 @@
import { defineStore, storeToRefs } from 'pinia'
import { ref } from 'vue'
import { watchOnce } from '@vueuse/core'
import { useLocations } from './locations'
import { useCluster } from './cluster'

export const useApp = defineStore('app', () => {
// We just track the first load, so we can show a loading indicator
const firstLocationsLoaded = ref(false)

const { locations } = storeToRefs(useLocations())
const { clusters } = storeToRefs(useCluster())
const { singles, clusters } = storeToRefs(useCluster())

// The moment any of these two stores are loaded, we set the firstLocationsLoaded to true
watchOnce([locations, clusters], () => firstLocationsLoaded.value = true)
watchOnce([singles, clusters], () => firstLocationsLoaded.value = true)

return {
firstLocationsLoaded,
Expand Down
43 changes: 21 additions & 22 deletions src/stores/locations.ts
Original file line number Diff line number Diff line change
@@ -1,30 +1,38 @@
import { useRouteQuery } from '@vueuse/router'
import { getLocations as getDbLocations, getLocation } from 'database'
import { defineStore, storeToRefs } from 'pinia'
import { defineStore } from 'pinia'
import { addBBoxToArea, bBoxIsWithinArea, getLocationsWithinBBox } from 'shared'
import type { BoundingBox, Location } from 'types'
import { computed, ref, shallowReactive, watch } from 'vue'
import { ref, shallowReactive, watch } from 'vue'
import { useRoute, useRouter } from 'vue-router'
import type { MultiPolygon } from '@turf/helpers'
import { useMap } from './map'
import { useFilters } from '@/stores/filters'
import { DATABASE_ARGS, parseLocation } from '@/shared'

export const useLocations = defineStore('locations', () => {
const currentBoundingBox = ref<BoundingBox>()

// Reduce redundant database fetches by reusing fetched locations by tracking the areas explored by the user
// Reduce redundant database fetches by reusing fetched locations by tracking the areas explored by the user
let visitedAreas: MultiPolygon

const locationsMap = shallowReactive(new Map<string, Location>())

const locations = computed(() => {
if (!currentBoundingBox.value)
return []
const filteredLocations = [...locationsMap.values()].filter(location => includeLocation(location))
// return getLocationsWithinBBox(filteredLocations, currentBoundingBox.value)
return filteredLocations
})
// const locations = computed(() => {
// if (!currentBoundingBox.value)
// return []
// const filteredLocations = [...locationsMap.values()].filter(location => includeLocation(location))
// // return getLocationsWithinBBox(filteredLocations, currentBoundingBox.value)
// return filteredLocations
// })

// const { selectedCurrencies, selectedCategories } = storeToRefs(useFilters())

// function includeLocation({ category, accepts, sells, lat, lng }: Location) {
// const currencies = accepts.concat(sells)
// const isFilteredByCurrencies = selectedCurrencies.value.length === 0 || currencies.some(c => selectedCurrencies.value.includes(c))
// const isFilteredByCategories = selectedCategories.value.length === 0 || selectedCategories.value.includes(category)
// return isFilteredByCurrencies && isFilteredByCategories
// }

function setLocations(locations: Location[]) {
locations.forEach(location => locationsMap.set(location.uuid, location))
Expand All @@ -34,7 +42,7 @@ export const useLocations = defineStore('locations', () => {
currentBoundingBox.value = boundingBox

if (bBoxIsWithinArea(boundingBox, visitedAreas))
return getLocationsWithinBBox(locations.value, boundingBox)
return getLocationsWithinBBox([...locationsMap.values()], boundingBox)

const newLocations = await getDbLocations(DATABASE_ARGS, boundingBox, parseLocation)
setLocations(newLocations)
Expand All @@ -54,15 +62,6 @@ export const useLocations = defineStore('locations', () => {
return location
}

const { selectedCurrencies, selectedCategories } = storeToRefs(useFilters())

function includeLocation({ category, accepts, sells, lat, lng }: Location) {
const currencies = accepts.concat(sells)
const isFilteredByCurrencies = selectedCurrencies.value.length === 0 || currencies.some(c => selectedCurrencies.value.includes(c))
const isFilteredByCategories = selectedCategories.value.length === 0 || selectedCategories.value.includes(category)
return isFilteredByCurrencies && isFilteredByCategories
}

const router = useRouter()
const route = useRoute()

Expand All @@ -88,7 +87,7 @@ export const useLocations = defineStore('locations', () => {
return {
getLocations,
getLocationByUuid,
locations,
// locations,
setLocations,

selectedUuid,
Expand Down

0 comments on commit 2440fba

Please sign in to comment.