diff --git a/src/stores/app.ts b/src/stores/app.ts index 1f836588..861528b2 100644 --- a/src/stores/app.ts +++ b/src/stores/app.ts @@ -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, diff --git a/src/stores/locations.ts b/src/stores/locations.ts index 5d5233bb..5b2fc4d5 100644 --- a/src/stores/locations.ts +++ b/src/stores/locations.ts @@ -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() - // 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()) - 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)) @@ -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) @@ -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() @@ -88,7 +87,7 @@ export const useLocations = defineStore('locations', () => { return { getLocations, getLocationByUuid, - locations, + // locations, setLocations, selectedUuid,