From 35e0564cfcf0f47b698e39d5045c892cc8b8b516 Mon Sep 17 00:00:00 2001 From: Thomas Citharel Date: Thu, 15 Oct 2020 16:48:11 +0200 Subject: [PATCH] Handle nothing found for reverse geocode Signed-off-by: Thomas Citharel --- .../components/Event/AddressAutoComplete.vue | 10 ++++--- .../Event/FullAddressAutoComplete.vue | 27 ++++++++++--------- 2 files changed, 21 insertions(+), 16 deletions(-) diff --git a/js/src/components/Event/AddressAutoComplete.vue b/js/src/components/Event/AddressAutoComplete.vue index feab820f8..49a93b9e7 100644 --- a/js/src/components/Event/AddressAutoComplete.vue +++ b/js/src/components/Event/AddressAutoComplete.vue @@ -175,10 +175,12 @@ export default class AddressAutoComplete extends Vue { }); this.addressData = result.data.reverseGeocode.map((address: IAddress) => new Address(address)); - const defaultAddress = new Address(this.addressData[0]); - this.selected = defaultAddress; - this.$emit("input", this.selected); - this.queryText = `${defaultAddress.poiInfos.name} ${defaultAddress.poiInfos.alternativeName}`; + if (this.addressData.length > 0) { + const defaultAddress = new Address(this.addressData[0]); + this.selected = defaultAddress; + this.$emit("input", this.selected); + this.queryText = `${defaultAddress.poiInfos.name} ${defaultAddress.poiInfos.alternativeName}`; + } } checkCurrentPosition(e: LatLng): boolean { diff --git a/js/src/components/Event/FullAddressAutoComplete.vue b/js/src/components/Event/FullAddressAutoComplete.vue index 3acd2e6ca..00acbaa4a 100644 --- a/js/src/components/Event/FullAddressAutoComplete.vue +++ b/js/src/components/Event/FullAddressAutoComplete.vue @@ -151,7 +151,7 @@ export default class FullAddressAutoComplete extends Vue { }; } - async asyncData(query: string) { + async asyncData(query: string): Promise { if (!query.length) { this.addressData = []; this.selected = new Address(); @@ -178,7 +178,7 @@ export default class FullAddressAutoComplete extends Vue { } @Watch("config") - watchConfig(config: IConfig) { + watchConfig(config: IConfig): void { if (!config.geocoding.autocomplete) { // If autocomplete is disabled, we put a larger debounce value // so that we don't request with incomplete address @@ -187,7 +187,7 @@ export default class FullAddressAutoComplete extends Vue { } @Watch("value") - updateEditing() { + updateEditing(): void { if (!(this.value && this.value.id)) return; this.selected = this.value; const address = new Address(this.selected); @@ -196,22 +196,22 @@ export default class FullAddressAutoComplete extends Vue { } } - updateSelected(option: IAddress) { + updateSelected(option: IAddress): void { if (option == null) return; this.selected = option; this.$emit("input", this.selected); } - resetPopup() { + resetPopup(): void { this.selected = new Address(); } - openNewAddressModal() { + openNewAddressModal(): void { this.resetPopup(); this.addressModalActive = true; } - async reverseGeoCode(e: LatLng, zoom: number) { + async reverseGeoCode(e: LatLng, zoom: number): Promise { // If the position has been updated through autocomplete selection, no need to geocode it! if (this.checkCurrentPosition(e)) return; const result = await this.$apollo.query({ @@ -225,13 +225,15 @@ export default class FullAddressAutoComplete extends Vue { }); this.addressData = result.data.reverseGeocode.map((address: IAddress) => new Address(address)); - const defaultAddress = new Address(this.addressData[0]); - this.selected = defaultAddress; - this.$emit("input", this.selected); - this.queryText = `${defaultAddress.poiInfos.name} ${defaultAddress.poiInfos.alternativeName}`; + if (this.addressData.length > 0) { + const defaultAddress = new Address(this.addressData[0]); + this.selected = defaultAddress; + this.$emit("input", this.selected); + this.queryText = `${defaultAddress.poiInfos.name} ${defaultAddress.poiInfos.alternativeName}`; + } } - checkCurrentPosition(e: LatLng) { + checkCurrentPosition(e: LatLng): boolean { if (!this.selected || !this.selected.geom) return false; const lat = parseFloat(this.selected.geom.split(";")[1]); const lon = parseFloat(this.selected.geom.split(";")[0]); @@ -259,6 +261,7 @@ export default class FullAddressAutoComplete extends Vue { return this.label || (this.$t("Find an address") as string); } + // eslint-disable-next-line class-methods-use-this get canShowLocateMeButton(): boolean { return window.isSecureContext; }