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

Commit

Permalink
Ensure maps show up in replies and threads, by creating unique IDs (#…
Browse files Browse the repository at this point in the history
  • Loading branch information
andybalaam committed Jan 18, 2022
1 parent e1cdbe1 commit 47cbef2
Showing 1 changed file with 11 additions and 12 deletions.
23 changes: 11 additions & 12 deletions src/components/views/messages/MLocationBody.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -38,11 +38,18 @@ interface IState {
@replaceableComponent("views.messages.MLocationBody")
export default class MLocationBody extends React.Component<IBodyProps, IState> {
private coords: GeolocationCoordinates;
private bodyId: string;
private markerId: string;

constructor(props: IBodyProps) {
super(props);

const randomString = Math.random().toString(16).slice(2, 10);
const idSuffix = `${props.mxEvent.getId()}_${randomString}`;
this.bodyId = `mx_MLocationBody_${idSuffix}`;
this.markerId = `mx_MLocationBody_marker_${idSuffix}`;
this.coords = parseGeoUri(locationEventGeoUri(this.props.mxEvent));

this.state = {
error: undefined,
};
Expand All @@ -56,20 +63,12 @@ export default class MLocationBody extends React.Component<IBodyProps, IState> {
createMap(
this.coords,
false,
this.getBodyId(),
this.getMarkerId(),
this.bodyId,
this.markerId,
(e: Error) => this.setState({ error: e }),
);
}

private getBodyId = () => {
return `mx_MLocationBody_${this.props.mxEvent.getId()}`;
};

private getMarkerId = () => {
return `mx_MLocationBody_marker_${this.props.mxEvent.getId()}`;
};

private onClick = (
event: React.MouseEvent<HTMLDivElement, MouseEvent>,
) => {
Expand All @@ -93,8 +92,8 @@ export default class MLocationBody extends React.Component<IBodyProps, IState> {
render(): React.ReactElement<HTMLDivElement> {
return <LocationBodyContent
mxEvent={this.props.mxEvent}
bodyId={this.getBodyId()}
markerId={this.getMarkerId()}
bodyId={this.bodyId}
markerId={this.markerId}
error={this.state.error}
tooltip={_t("Expand map")}
onClick={this.onClick}
Expand Down

0 comments on commit 47cbef2

Please sign in to comment.