Skip to content
This repository has been archived by the owner on Sep 11, 2024. It is now read-only.

Commit

Permalink
Clean up error listener when location picker closes
Browse files Browse the repository at this point in the history
  • Loading branch information
robintown committed Feb 25, 2022
1 parent 3e4e7ef commit 471f533
Showing 1 changed file with 16 additions and 14 deletions.
30 changes: 16 additions & 14 deletions src/components/views/location/LocationPicker.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -111,20 +111,7 @@ class LocationPicker extends React.Component<IProps, IState> {
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('error', this.onGeolocateError);
this.geolocate.on('geolocate', this.onGeolocate);
} catch (e) {
logger.error("Failed to render map", e);
Expand All @@ -133,6 +120,7 @@ class LocationPicker extends React.Component<IProps, IState> {
}

componentWillUnmount() {
this.geolocate?.off('error', this.onGeolocateError);
this.geolocate?.off('geolocate', this.onGeolocate);
this.context.off(ClientEvent.ClientWellKnown, this.updateStyleUrl);
}
Expand All @@ -154,6 +142,20 @@ class LocationPicker extends React.Component<IProps, IState> {
);
};

private onGeolocateError = (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),
},
);
};

private onOk = () => {
const position = this.state.position;

Expand Down

0 comments on commit 471f533

Please sign in to comment.