From 22c2aa37d75151ccea82691baad00e84f8039f8e Mon Sep 17 00:00:00 2001 From: Andy Balaam Date: Thu, 13 Jan 2022 14:38:04 +0000 Subject: [PATCH] Show an error dialog if location permission is denied (#7531) --- .../views/location/LocationPicker.tsx | 34 +++++++++++++++++++ src/i18n/strings/en_EN.json | 5 +++ 2 files changed, 39 insertions(+) diff --git a/src/components/views/location/LocationPicker.tsx b/src/components/views/location/LocationPicker.tsx index 7a7926d867..c88eb8850c 100644 --- a/src/components/views/location/LocationPicker.tsx +++ b/src/components/views/location/LocationPicker.tsx @@ -25,6 +25,8 @@ import { _t } from '../../../languageHandler'; import { replaceableComponent } from "../../../utils/replaceableComponent"; import MemberAvatar from '../avatars/MemberAvatar'; import MatrixClientContext from '../../../contexts/MatrixClientContext'; +import Modal from '../../../Modal'; +import ErrorDialog from '../dialogs/ErrorDialog'; interface IProps { sender: RoomMember; @@ -106,6 +108,20 @@ class LocationPicker extends React.Component { this.geolocate.trigger(); }); + this.geolocate.on('error', (e: GeolocationPositionError) => { + this.props.onFinished(); + logger.error("Could not fetch location", e); + Modal.createTrackedDialog( + 'Could not fetch location', + '', + ErrorDialog, + { + title: _t("Could not fetch location"), + description: positionFailureMessage(e.code), + }, + ); + }); + this.geolocate.on('geolocate', this.onGeolocate); } catch (e) { logger.error("Failed to render map", e.error); @@ -197,3 +213,21 @@ export function getGeoUri(position: GeolocationPosition): string { } export default LocationPicker; + +function positionFailureMessage(code: number): string { + switch (code) { + case 1: return _t( + "Element was denied permission to fetch your location. " + + "Please allow location access in your browser settings.", + ); + case 2: return _t( + "Failed to fetch your location. Please try again later.", + ); + case 3: return _t( + "Timed out trying to fetch your location. Please try again later.", + ); + case 4: return _t( + "Unknown error fetching location. Please try again later.", + ); + } +} diff --git a/src/i18n/strings/en_EN.json b/src/i18n/strings/en_EN.json index e175b92832..6b0be665e1 100644 --- a/src/i18n/strings/en_EN.json +++ b/src/i18n/strings/en_EN.json @@ -2137,6 +2137,11 @@ "Share location": "Share location", "We couldn’t send your location": "We couldn’t send your location", "Element could not send your location. Please try again later.": "Element could not send your location. Please try again later.", + "Could not fetch location": "Could not fetch location", + "Element was denied permission to fetch your location. Please allow location access in your browser settings.": "Element was denied permission to fetch your location. Please allow location access in your browser settings.", + "Failed to fetch your location. Please try again later.": "Failed to fetch your location. Please try again later.", + "Timed out trying to fetch your location. Please try again later.": "Timed out trying to fetch your location. Please try again later.", + "Unknown error fetching location. Please try again later.": "Unknown error fetching location. Please try again later.", "Failed to load group members": "Failed to load group members", "Filter community members": "Filter community members", "Are you sure you want to remove '%(roomName)s' from %(groupId)s?": "Are you sure you want to remove '%(roomName)s' from %(groupId)s?",