From cf8f1c73ceeb7f20adca1609b5b08294b6dc58b4 Mon Sep 17 00:00:00 2001 From: IanM Date: Wed, 7 Feb 2024 11:07:52 +0000 Subject: [PATCH] fix: error when trying to display map if no zip or lat/lon --- js/src/forum/components/ZipCodeMap.js | 32 +++++++++++++----------- js/src/forum/extenders/extendPostMeta.js | 28 ++++++++++----------- js/src/forum/models/IPInfo.ts | 27 +++++++++++--------- resources/locale/en.yml | 1 + 4 files changed, 47 insertions(+), 41 deletions(-) diff --git a/js/src/forum/components/ZipCodeMap.js b/js/src/forum/components/ZipCodeMap.js index 8c88ef9..4204ec7 100644 --- a/js/src/forum/components/ZipCodeMap.js +++ b/js/src/forum/components/ZipCodeMap.js @@ -21,16 +21,20 @@ export default class ZipCodeMap extends Component { this.data = null; - if (this.ipInfo.zipCode()) { + if (this.ipInfo.latitude() && this.ipInfo.longitude()) { + this.searchLatLon(); + } else if (this.ipInfo.zipCode()) { this.searchZip(); } else { - this.searchLatLon(); + this.data = { unknown: true }; } } view() { if (this.loading) { return ; + } else if (this.data && this.data.unknown) { + return
{app.translator.trans('fof-geoip.forum.map_modal.not_enough_data')}
; } else if (!this.data) { return
; } @@ -38,7 +42,7 @@ export default class ZipCodeMap extends Component { return
; } - searchZip() { + searchLatLon() { if (this.loading) return; this.loading = true; @@ -46,17 +50,16 @@ export default class ZipCodeMap extends Component { return addResources().then( app .request({ - url: `https://nominatim.openstreetmap.org/search`, + url: `https://nominatim.openstreetmap.org/reverse`, method: 'GET', params: { - q: this.ipInfo.zipCode(), - countrycodes: this.ipInfo.countryCode(), - limit: 1, + lat: this.ipInfo.latitude(), + lon: this.ipInfo.longitude(), format: 'json', }, }) .then((data) => { - this.data = data[0]; + this.data = data; this.loading = false; m.redraw(); @@ -64,7 +67,7 @@ export default class ZipCodeMap extends Component { ); } - searchLatLon() { + searchZip() { if (this.loading) return; this.loading = true; @@ -72,16 +75,17 @@ export default class ZipCodeMap extends Component { return addResources().then( app .request({ - url: `https://nominatim.openstreetmap.org/reverse`, + url: `https://nominatim.openstreetmap.org/search`, method: 'GET', params: { - lat: this.ipInfo.latitude(), - lon: this.ipInfo.longitude(), + q: this.ipInfo.zipCode(), + countrycodes: this.ipInfo.countryCode(), + limit: 1, format: 'json', }, }) .then((data) => { - this.data = data; + this.data = data[0]; this.loading = false; m.redraw(); @@ -100,6 +104,6 @@ export default class ZipCodeMap extends Component { attribution: '© OpenStreetMap contributors', }).addTo(this.map); - L.marker([bounding[0], bounding[2]]).addTo(this.map).bindPopup(displayName).openPopup(); + L.marker([bounding[0], bounding[2]]).addTo(this.map).openPopup(); } } diff --git a/js/src/forum/extenders/extendPostMeta.js b/js/src/forum/extenders/extendPostMeta.js index 485b547..3775f78 100644 --- a/js/src/forum/extenders/extendPostMeta.js +++ b/js/src/forum/extenders/extendPostMeta.js @@ -46,7 +46,7 @@ export default function extendPostMeta() { const ipAddr = post.data.attributes.ipAddress; if (ipInformation && ipAddr) { - const { description, threat, image, zip, country } = getIPData(ipInformation); + const { description, threat, image } = getIPData(ipInformation); items.add( 'ipInfo', @@ -59,20 +59,18 @@ export default function extendPostMeta() { 100 ); - if (zip && country) { - items.add( - 'mapButton', - -