File tree Expand file tree Collapse file tree 4 files changed +31
-29
lines changed Expand file tree Collapse file tree 4 files changed +31
-29
lines changed Original file line number Diff line number Diff line change 8
8
<script setup lang="ts">
9
9
import { onBeforeMount , ref } from ' vue' ;
10
10
import { RouterView } from ' vue-router' ;
11
- import { getMaptilerToken } from ' ./composables/useFetch' ;
12
11
import { useRoute } from ' vue-router' ;
13
12
14
- import { useMaxmindDataStore } from ' ./stores/maxmindDataStore' ;
13
+ import { useConfigStore } from ' @/stores/config' ;
14
+ import { useMaxmindDataStore } from ' @/stores/maxmindDataStore' ;
15
15
16
16
const route = useRoute ();
17
17
const maxmindDataStore = useMaxmindDataStore ();
18
+ const configStore = useConfigStore ();
18
19
const ready = ref (false );
19
20
20
21
onBeforeMount (async () => {
21
- await getMaptilerToken ();
22
+ await configStore .$reset ();
23
+
22
24
if (! route .query .address || route .query .address === " " ) {
23
25
await maxmindDataStore .$reset ();
24
26
} else {
Original file line number Diff line number Diff line change 8
8
import maplibregl from ' maplibre-gl' ;
9
9
import { storeToRefs } from ' pinia' ;
10
10
11
- import { useMaptilerToken } from ' @/composables/useMaptilerToken ' ;
11
+ import { useConfigStore } from ' @/stores/config ' ;
12
12
import { useMaxmindDataStore } from ' @/stores/maxmindDataStore' ;
13
13
14
+ const configStore = useConfigStore ();
15
+ const { maptilerToken } = storeToRefs (configStore );
14
16
const maxmindDataStore = useMaxmindDataStore ();
15
17
const { data } = storeToRefs (maxmindDataStore );
16
18
17
19
const center = computed (() => ({ lng: data .value ! .Location .Longitude , lat: data .value ! .Location .Latitude }));
18
20
19
21
const updateMap = async () => {
20
- // TODO: move this out? i don't like it being called on every update
21
- // currently error if we move it out of `onMounted` specifically
22
- const maptilerToken = await useMaptilerToken ();
23
22
const map = new maplibregl .Map ({
24
23
container: ' map' ,
25
- style: ` https://api.maptiler.com/maps/streets/style.json?key=${maptilerToken } ` ,
24
+ style: ` https://api.maptiler.com/maps/streets/style.json?key=${maptilerToken . value } ` ,
26
25
center: center .value ,
27
26
zoom: 10 ,
28
27
});
32
31
.addTo (map );
33
32
};
34
33
35
- onMounted (() => updateMap () );
36
- onUpdated (() => updateMap () );
34
+ onMounted (updateMap );
35
+ onUpdated (updateMap );
37
36
</script >
38
37
39
38
<style >
Load Diff This file was deleted.
Original file line number Diff line number Diff line change
1
+ import { ref } from 'vue' ;
2
+ import type { Ref } from 'vue' ;
3
+ import { defineStore } from 'pinia' ;
4
+
5
+ import { getMaptilerToken } from '@/composables/useFetch' ;
6
+
7
+ export const useConfigStore = defineStore ( 'config' , ( ) => {
8
+ const maptilerToken : Ref < string > = ref ( '' ) ;
9
+
10
+ async function $reset ( ) {
11
+ // TODO: error?
12
+ const { data, error } = await getMaptilerToken ( ) ;
13
+ maptilerToken . value = data . value ;
14
+ } ;
15
+
16
+ return {
17
+ maptilerToken,
18
+ $reset,
19
+ } ;
20
+ } ) ;
You can’t perform that action at this time.
0 commit comments