INSR-8688: More awaits and broader try/catch for google places API calls
This commit is contained in:
parent
a1cdf7b630
commit
52645df56c
2 changed files with 13 additions and 16 deletions
|
|
@ -13,10 +13,7 @@ import { useMainStore } from '@/store/index.js';
|
||||||
/** @ignore */
|
/** @ignore */
|
||||||
function setupMocks({
|
function setupMocks({
|
||||||
storeData,
|
storeData,
|
||||||
props,
|
props
|
||||||
isShallowMount = true,
|
|
||||||
querySelectorFunction,
|
|
||||||
geocoderResult = ['1234 Test Street']
|
|
||||||
}) {
|
}) {
|
||||||
const mountOptions = getMountOptions({
|
const mountOptions = getMountOptions({
|
||||||
router: {
|
router: {
|
||||||
|
|
|
||||||
|
|
@ -158,9 +158,9 @@ export default {
|
||||||
async beforeRouteEnter(to, from, next) {
|
async beforeRouteEnter(to, from, next) {
|
||||||
const cmsContent = await fetchCmsContentForPage(to.query.issPage);
|
const cmsContent = await fetchCmsContentForPage(to.query.issPage);
|
||||||
|
|
||||||
next((vm) => {
|
next(async (vm) => {
|
||||||
vm.setCmsContent(cmsContent);
|
vm.setCmsContent(cmsContent);
|
||||||
vm.setupAddressLookup();
|
await vm.setupAddressLookup();
|
||||||
});
|
});
|
||||||
},
|
},
|
||||||
data() {
|
data() {
|
||||||
|
|
@ -272,10 +272,10 @@ export default {
|
||||||
this.address2 = '';
|
this.address2 = '';
|
||||||
this.city = '';
|
this.city = '';
|
||||||
},
|
},
|
||||||
setupAddressLookup() {
|
async setupAddressLookup() {
|
||||||
const apiKey = applicationConfig.GOOGLE_PLACES_API_KEY;
|
const apiKey = applicationConfig.GOOGLE_PLACES_API_KEY;
|
||||||
|
|
||||||
this.$loadScript(`https://maps.googleapis.com/maps/api/js?key=${apiKey}&libraries=places&callback=Function.prototype`)
|
await this.$loadScript(`https://maps.googleapis.com/maps/api/js?key=${apiKey}&libraries=places&callback=Function.prototype`)
|
||||||
.catch(() => {
|
.catch(() => {
|
||||||
// Failed to fetch script
|
// Failed to fetch script
|
||||||
window.console.warn('Unable to load Google Places API script');
|
window.console.warn('Unable to load Google Places API script');
|
||||||
|
|
@ -283,15 +283,15 @@ export default {
|
||||||
},
|
},
|
||||||
geocodeAddress() {
|
geocodeAddress() {
|
||||||
const autoCompletePromise = new Promise((resolve, reject) => {
|
const autoCompletePromise = new Promise((resolve, reject) => {
|
||||||
// Get Autocomplete Service
|
|
||||||
const acService = new window.google.maps.places.AutocompleteService();
|
|
||||||
// Get Places Service, needs psuedo element (or a map)
|
|
||||||
const placeService = new window.google.maps.places.PlacesService(document.createElement('div'));
|
|
||||||
// Create Autocomplete Session token, multiple requests one pricing hit
|
|
||||||
const acSessionToken = new window.google.maps.places.AutocompleteSessionToken();
|
|
||||||
|
|
||||||
const addressValue = `${this.address}, ${this.city}, ${this.state} ${this.zipCode}`;
|
|
||||||
try {
|
try {
|
||||||
|
// Get Autocomplete Service
|
||||||
|
const acService = new window.google.maps.places.AutocompleteService();
|
||||||
|
// Get Places Service, needs pseudo element (or a map)
|
||||||
|
const placeService = new window.google.maps.places.PlacesService(document.createElement('div'));
|
||||||
|
// Create Autocomplete Session token, multiple requests one pricing hit
|
||||||
|
const acSessionToken = new window.google.maps.places.AutocompleteSessionToken();
|
||||||
|
|
||||||
|
const addressValue = `${this.address}, ${this.city}, ${this.state} ${this.zipCode}`;
|
||||||
acService.getPlacePredictions(
|
acService.getPlacePredictions(
|
||||||
{
|
{
|
||||||
input: addressValue,
|
input: addressValue,
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue