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 88<script setup lang="ts">
99import { onBeforeMount , ref } from ' vue' ;
1010import { RouterView } from ' vue-router' ;
11- import { getMaptilerToken } from ' ./composables/useFetch' ;
1211import { useRoute } from ' vue-router' ;
1312
14- import { useMaxmindDataStore } from ' ./stores/maxmindDataStore' ;
13+ import { useConfigStore } from ' @/stores/config' ;
14+ import { useMaxmindDataStore } from ' @/stores/maxmindDataStore' ;
1515
1616const route = useRoute ();
1717const maxmindDataStore = useMaxmindDataStore ();
18+ const configStore = useConfigStore ();
1819const ready = ref (false );
1920
2021onBeforeMount (async () => {
21- await getMaptilerToken ();
22+ await configStore .$reset ();
23+
2224 if (! route .query .address || route .query .address === " " ) {
2325 await maxmindDataStore .$reset ();
2426 } else {
Original file line number Diff line number Diff line change 88 import maplibregl from ' maplibre-gl' ;
99 import { storeToRefs } from ' pinia' ;
1010
11- import { useMaptilerToken } from ' @/composables/useMaptilerToken ' ;
11+ import { useConfigStore } from ' @/stores/config ' ;
1212 import { useMaxmindDataStore } from ' @/stores/maxmindDataStore' ;
1313
14+ const configStore = useConfigStore ();
15+ const { maptilerToken } = storeToRefs (configStore );
1416 const maxmindDataStore = useMaxmindDataStore ();
1517 const { data } = storeToRefs (maxmindDataStore );
1618
1719 const center = computed (() => ({ lng: data .value ! .Location .Longitude , lat: data .value ! .Location .Latitude }));
1820
1921 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 ();
2322 const map = new maplibregl .Map ({
2423 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 } ` ,
2625 center: center .value ,
2726 zoom: 10 ,
2827 });
3231 .addTo (map );
3332 };
3433
35- onMounted (() => updateMap () );
36- onUpdated (() => updateMap () );
34+ onMounted (updateMap );
35+ onUpdated (updateMap );
3736 </script >
3837
3938<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