Skip to content

Commit

Permalink
chore: map loading updated
Browse files Browse the repository at this point in the history
  • Loading branch information
stritti committed Jan 23, 2024
1 parent ee96420 commit 18fb063
Show file tree
Hide file tree
Showing 15 changed files with 97 additions and 86 deletions.
2 changes: 2 additions & 0 deletions .env
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
VITE_APP_AIRTABLE_TOKEN=keyxSG4cLVrJWeOUv
VITE_APP_GTAG_ID=G-R88JSEDEBT
Binary file modified bun.lockb
Binary file not shown.
32 changes: 16 additions & 16 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -10,11 +10,10 @@
},
"dependencies": {
"@mdi/font": "^7.4.47",
"@unhead/vue": "^1.8.9",
"@unhead/vue": "^1.8.10",
"@vue-leaflet/vue-leaflet": "^0.10.1",
"airtable": "^0.12.2",
"compressorjs": "^1.2.1",
"eslint-plugin-vuetify": "latest",
"leaflet": "^1.9.4",
"leaflet.locatecontrol": "^0.79.0",
"leaflet.markercluster": "^1.5.3",
Expand All @@ -23,34 +22,35 @@
"pinia": "^2.1.7",
"register-service-worker": "^1.7.2",
"vite-plugin-package-version": "^1.1.0",
"vue": "^3.4.7",
"vue": "^3.4.15",
"vue-leaflet-markercluster": "^0.5.1",
"vue-number-animation": "^2.0.2",
"vue-router": "^4.2.5",
"vuetify": "^3.4.10",
"vuetify": "^3.5.1",
"vuetify-sonner": "^0.3.12"
},
"devDependencies": {
"@babel/types": "^7.23.0",
"@babel/types": "^7.23.6",
"@fortawesome/fontawesome-svg-core": "^6.5.1",
"@fortawesome/free-regular-svg-icons": "^6.5.1",
"@fortawesome/free-solid-svg-icons": "^6.5.1",
"@fortawesome/vue-fontawesome": "^3.0.5",
"@types/leaflet": "^1.9.8",
"@types/markdown-it": "^13.0.7",
"@types/node": "^20.10.8",
"@vitejs/plugin-vue": "^4.5.0",
"@vue/cli-plugin-pwa": "~5.0.0",
"@types/node": "^20.11.5",
"@vitejs/plugin-vue": "^5.0.3",
"@vue/cli-plugin-pwa": "^5.0.8",
"@vue/eslint-config-typescript": "^12.0.0",
"eslint": "^8.56.0",
"eslint-plugin-vue": "^9.19.2",
"sass": "^1.69.7",
"sass-loader": "^13.3.3",
"typescript": "^5.3.0",
"unplugin-fonts": "^1.1.0",
"eslint-plugin-vue": "^9.20.1",
"eslint-plugin-vuetify": "^2.1.1",
"sass": "^1.70.0",
"sass-loader": "^14.0.0",
"typescript": "^5.3.3",
"unplugin-fonts": "^1.1.1",
"unplugin-vue-components": "^0.26.0",
"vite": "^5.0.11",
"vite-plugin-vuetify": "^2.0.0",
"vue-tsc": "^1.8.0"
"vite": "^5.0.12",
"vite-plugin-vuetify": "^2.0.1",
"vue-tsc": "^1.8.27"
}
}
32 changes: 9 additions & 23 deletions src/components/map/LocationMap.vue
Original file line number Diff line number Diff line change
Expand Up @@ -77,6 +77,7 @@ import MapNavigationCard from './MapNavigationCard.vue'
import locationService from '@/services/location.service'
import { useLocationStore } from '@/store/location.store'
import type Location from '@/types/location'
import { mapState } from 'pinia'
export default {
name: 'LocationMap',
Expand All @@ -98,7 +99,6 @@ export default {
},
data () {
return {
map: null,
geojson: null,
userLocation: undefined as { lat: number; lng: number } | undefined,
userIcon: L.icon({
Expand All @@ -109,7 +109,6 @@ export default {
currentZoom: 10,
currentCenter: {lat: 47.78707377527543, lng: 8.8828643076576 } as any,
position: null,
locations: Array<Location>(),
showPopup: false,
popupLocation: undefined as Location | undefined,
bounds: L.latLngBounds([
Expand All @@ -125,8 +124,13 @@ export default {
'&copy; <a href="http://osm.org/copyright">OpenStreetMap</a> contributors'
}
},
computed: {
...mapState(useLocationStore, {
locations: store => store.locationList
})
},
created () {
this.loadDistrictPolygons()
},
mounted () {
this.currentZoom = this.$route.query.zoom
Expand All @@ -138,9 +142,8 @@ export default {
this.currentCenter.lat = this.$route.query.clng
? Number.parseFloat(this.$route.query.clng as string)
: this.currentCenter.lat
this.loadLocations()
},
this.loadDistrictPolygons()
},
methods: {
loadDistrictPolygons () {
fetch('/landkreis-konstanz.geojson').then((response) => {
Expand All @@ -149,23 +152,6 @@ export default {
})
})
},
async loadLocations () {
const locStore = useLocationStore()
await locStore.getLocationRecords()
const locations = locStore.getLocationList
if (this.locationTypes) {
const list = Array<Location>()
this.locationTypes.forEach((type) => {
const filteredList = locations.filter((loc) => {
return loc.type === type
})
list.push(...filteredList)
})
this.locations = list
} else {
this.locations = locations
}
},
getPin (location: Location) {
return L.icon({
iconUrl: locationService.getLocationTypeImage(location),
Expand Down
8 changes: 4 additions & 4 deletions src/router/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -94,23 +94,23 @@ const router = createRouter({
} else if (savedPosition) {
return savedPosition
} else {
return new Promise((resolve, reject) => {
return new Promise((resolve) => {
setTimeout(() => {
resolve({ left: 0, top: 0 })
}, 500)
}, 5)
})
}
},
routes
})

router.beforeEach((to) => {
router.beforeEach(() => {
// ✅ This will work make sure the correct store is used for the
// current running app
useLocationStore().getLocationRecords()
useMaterialStore().getMaterialRecords()
useTargetStore().getTargetRecords()
useTipStore().getTipRecords()
useLocationStore().getLocationRecords()
})

export default router
8 changes: 0 additions & 8 deletions src/services/location.service.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
import type Location from '@/types/location'
import base from './airtable.service'
import { toast } from 'vuetify-sonner'

const BASE_NAME = 'Location'
const locationService = {
Expand Down Expand Up @@ -29,13 +28,6 @@ const locationService = {
fetchNextPage()
}, function done (err) {
if (err) {
console.error(err)
toast("Kommunikationsfehler", {
description: err.message,
cardProps: {
color: 'error',
}
})
reject(err)
}
resolve(locations)
Expand Down
8 changes: 0 additions & 8 deletions src/services/material.service.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
import MaterialRequest from '@/types/material-request'
import type Material from '@/types/material'
import base from './airtable.service'
import { toast } from 'vuetify-sonner'
import { useTargetStore } from '@/store/target.store'

const materialService = {
Expand Down Expand Up @@ -39,13 +38,6 @@ const materialService = {
},
function done (err) {
if (err) {
console.error(err)
toast("Kommunikationsfehler", {
description: err.message,
cardProps: {
color: 'error',
}
})
reject(err)
}
resolve(allRecords)
Expand Down
7 changes: 0 additions & 7 deletions src/services/partner.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -32,13 +32,6 @@ const partnerService = {
},
function done (err: Error) {
if (err) {
console.error(err)
toast("Kommunikationsfehler", {
description: err.message,
cardProps: {
color: 'error',
}
})
reject(err)
}
resolve(allRecords)
Expand Down
7 changes: 0 additions & 7 deletions src/services/target.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -36,13 +36,6 @@ const targetService = {
},
function done (err) {
if (err) {
console.error(err)
toast("Kommunikationsfehler", {
description: err.message,
cardProps: {
color: 'error',
}
})
reject(err)
}
resolve(allTargets)
Expand Down
7 changes: 0 additions & 7 deletions src/services/tip.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -36,13 +36,6 @@ const tipService = {
},
function done (err) {
if (err) {
console.error(err)
toast("Kommunikationsfehler", {
description: err.message,
cardProps: {
color: 'error',
}
})
reject(err)
}
resolve(allTips)
Expand Down
28 changes: 26 additions & 2 deletions src/store/location.store.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ import { defineStore } from "pinia"
import locationService from '@/services/location.service'
import type Location from "@/types/location"
import { useLoadingStore } from "@/store/loading.store"
import { toast } from 'vuetify-sonner'

interface State {
locationList: Array<Location>
Expand All @@ -16,17 +17,40 @@ export const useLocationStore = defineStore("location", {
}),
getters: {
getLocationList: (state: State) => state.locationList as Array<Location>,
filteredLocationList: (state: State) => (locationTypes: Array<string>) => {
if (locationTypes && locationTypes.length > 0) {
const locList = state.locationList
const list = Array<Location>()
locationTypes.forEach((type) => {
const filteredList = locList.filter((loc) => {
return loc.type === type
})
list.push(...filteredList)
})
return list
} else {
return state.locationList
}
},
getLocationListCount: (state: State) => state.locationList.length as Number
},
actions: {
getLocationRecords() {
async getLocationRecords() {
if (!this.isLoading && (!this.locationList || this.locationList.length === 0)) {
this.isLoading = true
const loading = useLoadingStore()
loading.updateShowLoadingSpinner(true)
locationService.getLocationList()
.then((result) => this.locationList = result)
.catch((error) => console.error(error))
.catch((error) => {
console.error(error)
toast("Kommunikationsfehler", {
description: error.message,
cardProps: {
color: 'error',
}
})
})
.finally(() => {
loading.updateShowLoadingSpinner(false)
this.isLoading = false
Expand Down
11 changes: 10 additions & 1 deletion src/store/material.store.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ import { defineStore } from "pinia"
import materialService from '@/services/material.service'
import type Material from "@/types/material"
import { useLoadingStore } from "@/store/loading.store"
import { toast } from 'vuetify-sonner'

interface State {
materialList: Array<Material>
Expand Down Expand Up @@ -31,7 +32,15 @@ export const useMaterialStore = defineStore("material", {
loading.updateShowLoadingSpinner(true)
materialService.getMaterialRecords()
.then((result) => this.materialList = result)
.catch((error) => console.error(error))
.catch((error) => {
console.error(error)
toast("Kommunikationsfehler", {
description: error.message,
cardProps: {
color: 'error',
}
})
})
.finally(() => {
loading.updateShowLoadingSpinner(false)
this.isLoading = false
Expand Down
11 changes: 10 additions & 1 deletion src/store/problemstoffmobil.store.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ import { defineStore } from "pinia"
import problemstoffmobilService from '@/services/problemstoffmobil.service'
import { useLoadingStore } from "./loading.store"
import type Event from "@/types/event"
import { toast } from 'vuetify-sonner'

interface State {
eventList: Array<Event>
Expand All @@ -25,7 +26,15 @@ export const useEventStore = defineStore("event", {
loading.updateShowLoadingSpinner(true)
problemstoffmobilService.getEventRecords()
.then((result) => this.eventList = result)
.catch((error) => console.error(error))
.catch((error) => {
console.error(error)
toast("Kommunikationsfehler", {
description: error.message,
cardProps: {
color: 'error',
}
})
})
.finally(() => {
loading.updateShowLoadingSpinner(false)
this.isLoading = false
Expand Down
11 changes: 10 additions & 1 deletion src/store/target.store.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ import { defineStore } from "pinia"
import targetService from '@/services/target.service'
import type Target from "@/types/target"
import { useLoadingStore } from "./loading.store"
import { toast } from 'vuetify-sonner'

interface State {
targetList: Array<Target>
Expand All @@ -25,7 +26,15 @@ export const useTargetStore = defineStore("target", {
loading.updateShowLoadingSpinner(true)
targetService.getTargetRecords()
.then((result) => this.targetList = result)
.catch((error) => console.error(error))
.catch((error) => {
console.error(error)
toast("Kommunikationsfehler", {
description: error.message,
cardProps: {
color: 'error',
}
})
})
.finally(() => {
loading.updateShowLoadingSpinner(false)
this.isLoading = false
Expand Down
Loading

0 comments on commit 18fb063

Please sign in to comment.