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

Commit 4ab5968

Browse files
authored
Clean up error listener when location picker closes (#7902)
Signed-off-by: Robin Townsend <[email protected]>
1 parent ece2b85 commit 4ab5968

File tree

1 file changed

+16
-14
lines changed

1 file changed

+16
-14
lines changed

src/components/views/location/LocationPicker.tsx

Lines changed: 16 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -111,20 +111,7 @@ class LocationPicker extends React.Component<IProps, IState> {
111111
this.geolocate.trigger();
112112
});
113113

114-
this.geolocate.on('error', (e: GeolocationPositionError) => {
115-
this.props.onFinished();
116-
logger.error("Could not fetch location", e);
117-
Modal.createTrackedDialog(
118-
'Could not fetch location',
119-
'',
120-
ErrorDialog,
121-
{
122-
title: _t("Could not fetch location"),
123-
description: positionFailureMessage(e.code),
124-
},
125-
);
126-
});
127-
114+
this.geolocate.on('error', this.onGeolocateError);
128115
this.geolocate.on('geolocate', this.onGeolocate);
129116
} catch (e) {
130117
logger.error("Failed to render map", e);
@@ -133,6 +120,7 @@ class LocationPicker extends React.Component<IProps, IState> {
133120
}
134121

135122
componentWillUnmount() {
123+
this.geolocate?.off('error', this.onGeolocateError);
136124
this.geolocate?.off('geolocate', this.onGeolocate);
137125
this.context.off(ClientEvent.ClientWellKnown, this.updateStyleUrl);
138126
}
@@ -154,6 +142,20 @@ class LocationPicker extends React.Component<IProps, IState> {
154142
);
155143
};
156144

145+
private onGeolocateError = (e: GeolocationPositionError) => {
146+
this.props.onFinished();
147+
logger.error("Could not fetch location", e);
148+
Modal.createTrackedDialog(
149+
'Could not fetch location',
150+
'',
151+
ErrorDialog,
152+
{
153+
title: _t("Could not fetch location"),
154+
description: positionFailureMessage(e.code),
155+
},
156+
);
157+
};
158+
157159
private onOk = () => {
158160
const position = this.state.position;
159161

0 commit comments

Comments
 (0)