Skip to content

Commit

Permalink
Merge pull request #989 from opentripplanner/refine-desktop-location-…
Browse files Browse the repository at this point in the history
…fetch

Refine desktop location fetch
  • Loading branch information
binh-dam-ibigroup authored Aug 30, 2023
2 parents 6b3145c + 98701eb commit f40cc15
Show file tree
Hide file tree
Showing 4 changed files with 39 additions and 8 deletions.
6 changes: 6 additions & 0 deletions i18n/en-US.yml
Original file line number Diff line number Diff line change
Expand Up @@ -34,8 +34,14 @@ actions:
setPaymentError: "Error setting payment info:"
setRequestStatusError: "Error setting request status:"
location:
deniedAccessAlert: >
Access to your location is blocked.
To use your current location, enable location permissions from your
browser, and reload the page.
geolocationNotSupportedError: Geolocation not supported by your browser
unknownPositionError: Unknown error getting position
userDeniedPermission: User denied permission
map:
currentLocation: (Current Location)
user:
Expand Down
8 changes: 7 additions & 1 deletion i18n/fr.yml
Original file line number Diff line number Diff line change
Expand Up @@ -38,8 +38,14 @@ actions:
setPaymentError: "Erreur sur les coordonnées de paiement :"
setRequestStatusError: "Erreur sur l'état de la requête :"
location:
deniedAccessAlert: >
L'accès à votre position est refusé.
Pour utiliser votre emplacement actuel, permettez-en l'accès depuis votre
navigateur, et ouvrez de nouveau cette page.
geolocationNotSupportedError: La géolocalisation n'est pas prise en charge par votre navigateur.
unknownPositionError: Erreur inconnue lors de la détection de votre emplacement.
userDeniedPermission: Refusé par l'utilisateur
map:
currentLocation: (Emplacement actuel)
user:
Expand Down Expand Up @@ -178,7 +184,7 @@ components:
AdvancedOptions:
bannedRoutes: Choisissez les lignes à éviter…
bikeTolerance: Tolérance au vélo
preferredRoutes: Choisissez les lignes preferées
preferredRoutes: Choisissez les lignes préferées
walkTolerance: Tolérance à la marche
AfterSignInScreen:
mainTitle: Redirection...
Expand Down
27 changes: 24 additions & 3 deletions lib/actions/location.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
import { createAction } from 'redux-actions'
import { Dispatch } from 'redux'
import { IntlShape } from 'react-intl'
import { isMobile } from '@opentripplanner/core-utils/lib/ui'

import { setLocationToCurrent } from './map'

Expand Down Expand Up @@ -47,9 +48,29 @@ export function getCurrentPosition(
// On error
(error) => {
console.log('error getting current position', error)
// FIXME, analyze error code to produce better error message.
// See https://developer.mozilla.org/en-US/docs/Web/API/GeolocationPositionError
dispatch(receivedPositionError({ error }))
// On desktop, after user clicks "Use location" from the location fields,
// show an alert and explain if location is blocked.
// TODO: Consider moving the handling of unavailable location to the location-field component.
if (!isMobile() && error.code === 1) {
window.alert(
intl.formatMessage({
id: 'actions.location.deniedAccessAlert'
})
)
}
const newError = { ...error }
if (error.code === 1) {
// i18n for user-denied location message (error.code = 1 on secure origins).
if (
window.location.protocol === 'https:' ||
window.location.host.startsWith('localhost:')
) {
newError.message = intl.formatMessage({
id: 'actions.location.userDeniedPermission'
})
}
}
dispatch(receivedPositionError({ error: newError }))
},
// Options
{ enableHighAccuracy: true }
Expand Down
6 changes: 2 additions & 4 deletions lib/components/app/responsive-webapp.js
Original file line number Diff line number Diff line change
Expand Up @@ -153,11 +153,9 @@ class ResponsiveWebapp extends Component {
}
}

// Test location availability on load,
// so it is reported correctly by the location fields.
getCurrentPosition(intl)

if (isMobile()) {
// Test location availability on load
getCurrentPosition(intl)
// Also, watch for changes in position on mobile
navigator.geolocation.watchPosition(
// On success
Expand Down

0 comments on commit f40cc15

Please sign in to comment.