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

Simple static location sharing #7135

Merged
merged 32 commits into from
Dec 6, 2021
Merged
Show file tree
Hide file tree
Changes from 6 commits
Commits
Show all changes
32 commits
Select commit Hold shift + click to select a range
c66d54b
first ugly cut at a location picker via maplibre
ara4n Nov 14, 2021
7970b90
fix css
ara4n Nov 14, 2021
12bb69b
fix dropdown height
ara4n Nov 14, 2021
1b75489
fix form
ara4n Nov 14, 2021
cd9ea95
use right icon
ara4n Nov 14, 2021
3a779b7
hook up locationpicker
ara4n Nov 15, 2021
3b0a3a2
actually send m.location events
ara4n Nov 15, 2021
6ce1e86
view m.location
ara4n Nov 15, 2021
e7cd207
border radius on picker
ara4n Nov 15, 2021
fc41580
fix lint
ara4n Nov 21, 2021
bec7af4
Merge branch 'develop' into matthew/location-share
ara4n Nov 21, 2021
d6b5153
Merge branch 'develop' into matthew/location-share
ara4n Nov 21, 2021
ccd416d
fix css var
ara4n Nov 21, 2021
eebf29d
fix types
ara4n Nov 21, 2021
426f7b3
only send loc if you have one
ara4n Nov 21, 2021
94f1ff9
disable the streaming options until they're hooked up
ara4n Nov 21, 2021
6488168
lint
ara4n Nov 21, 2021
644fe03
more lint
ara4n Nov 21, 2021
f774e71
fix i18n
ara4n Nov 21, 2021
80a15a1
show descriptions
ara4n Nov 21, 2021
92ba926
incorporate review
ara4n Nov 22, 2021
5531d09
use fancy optional chaining
ara4n Nov 22, 2021
8fd4310
add createObjectURL mock
ara4n Nov 22, 2021
097c8f7
fix i18n
ara4n Nov 22, 2021
3dc7b21
Merge branch 'develop' into matthew/location-share
ara4n Nov 28, 2021
982d5b7
warn if API key not set when showing maps
ara4n Nov 28, 2021
6ea351e
Merge branch 'develop' into matthew/location-share
ara4n Dec 4, 2021
49c590c
export LocationShareType enum correctly
ara4n Dec 5, 2021
f088094
hook up map failure error correctly
ara4n Dec 5, 2021
58ebf2a
fix lint
ara4n Dec 5, 2021
e6842ba
fix type
ara4n Dec 5, 2021
d6b805a
fix types
ara4n Dec 5, 2021
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions res/css/views/location/_LocationPicker.scss
Original file line number Diff line number Diff line change
Expand Up @@ -37,3 +37,8 @@ limitations under the License.
max-height: 140px;
}
}

.mx_LocationPicker_error {
color: red;
ara4n marked this conversation as resolved.
Show resolved Hide resolved
margin: auto;
}
16 changes: 15 additions & 1 deletion src/components/views/location/LocationPicker.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -21,10 +21,11 @@ import SdkConfig from '../../../SdkConfig';
import Field from "../elements/Field";
import DialogButtons from "../elements/DialogButtons";
import Dropdown from "../elements/Dropdown";
import { LocationShareType } from "./LocationShareType";
import LocationShareType from "./LocationShareType";

import { _t } from '../../../languageHandler';
import { replaceableComponent } from "../../../utils/replaceableComponent";
import { logger } from "matrix-js-sdk/src/logger";

interface IDropdownProps {
value: LocationShareType;
Expand Down Expand Up @@ -74,6 +75,7 @@ interface IState {
type: LocationShareType;
position?: GeolocationPosition;
manual: boolean;
error: Error;
}

@replaceableComponent("views.location.LocationPicker")
Expand All @@ -89,6 +91,7 @@ class LocationPicker extends React.Component<IProps, IState> {
type: LocationShareType.OnceOff,
position: undefined,
manual: false,
error: undefined,
};
}

Expand All @@ -110,6 +113,11 @@ class LocationPicker extends React.Component<IProps, IState> {
});
this.map.addControl(this.geolocate);

this.map.on('error', (e)=>{
logger.error("Failed to load map: check map_style_url in config.json has a valid URL and API key", e.error);
this.setState({ error: e.error });
});

this.map.on('load', ()=>{
this.geolocate.trigger();
});
Expand Down Expand Up @@ -152,9 +160,15 @@ class LocationPicker extends React.Component<IProps, IState> {
};

render() {
const error = this.state.error ?
<div className="mx_LocationPicker_error">
{ _t("Failed to load map") }
</div> : null;

return (
<div className="mx_LocationPicker">
<div id="mx_LocationPicker_map" />
{ error }
<div className="mx_LocationPicker_footer">
<form onSubmit={this.onOk}>
<LocationShareTypeDropdown
Expand Down
4 changes: 3 additions & 1 deletion src/components/views/location/LocationShareType.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ See the License for the specific language governing permissions and
limitations under the License.
*/

export enum LocationShareType {
enum LocationShareType {
Custom = -1,
OnceOff = 0,
OneMine = 60,
Expand All @@ -26,3 +26,5 @@ export enum LocationShareType {
OneDay = 24 * 60 * 60,
Forever = Number.MAX_SAFE_INTEGER,
}

export default LocationShareType;
21 changes: 11 additions & 10 deletions src/components/views/messages/MLocationBody.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -19,9 +19,11 @@ import maplibregl from 'maplibre-gl';
import SdkConfig from '../../../SdkConfig';
import { replaceableComponent } from "../../../utils/replaceableComponent";
import { IBodyProps } from "./IBodyProps";
import { logger } from "matrix-js-sdk/src/logger";
import { _t } from '../../../languageHandler';

interface IState {
fail: boolean;
error: Error;
}

@replaceableComponent("views.messages.MLocationBody")
Expand All @@ -44,7 +46,7 @@ export default class MLocationBody extends React.Component<IBodyProps, IState> {

this.coords = this.parseGeoUri(uri);
this.state = {
fail: false,
error: undefined,
};

this.description =
Expand Down Expand Up @@ -81,25 +83,24 @@ export default class MLocationBody extends React.Component<IBodyProps, IState> {
zoom: 13,
});

try {
this.map.getStyle();
} catch (e) {
this.setState({ fail: true });
}

new maplibregl.Marker()
.setLngLat([this.coords.longitude, this.coords.latitude])
.addTo(this.map);

this.map.on('error', (e)=>{
logger.error("Failed to load map: check map_style_url in config.json has a valid URL and API key", e.error);
this.setState({ error: e.error });
});
}

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

render() {
const error = this.state.fail ?
const error = this.state.error ?
<div className="mx_EventTile_tileError mx_EventTile_body">
Failed to load map - check config.json has a valid API key
{ _t("Failed to load map") }
</div> : null;

return <div className="mx_MLocationBody">
Expand Down
4 changes: 2 additions & 2 deletions src/components/views/rooms/MessageComposer.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,6 @@ import { Action } from "../../../dispatcher/actions";
import EditorModel from "../../../editor/model";
import EmojiPicker from '../emojipicker/EmojiPicker';
import LocationPicker from '../location/LocationPicker';
import MemberStatusMessageAvatar from "../avatars/MemberStatusMessageAvatar";
import UIStore, { UI_EVENTS } from '../../../stores/UIStore';
import Modal from "../../../Modal";
import { RelationType } from 'matrix-js-sdk/src/@types/event';
Expand All @@ -59,7 +58,8 @@ import ErrorDialog from "../dialogs/ErrorDialog";
import PollCreateDialog from "../elements/PollCreateDialog";
import { MsgType } from "matrix-js-sdk/src/@types/event";
import { logger } from "matrix-js-sdk/src/logger";
import { LocationShareType } from "../location/LocationShareType";
import LocationShareType from "../location/LocationShareType";
import { SettingUpdatedPayload } from "../../../dispatcher/payloads/SettingUpdatedPayload";

let instanceCount = 0;
const NARROW_MODE_BREAKPOINT = 500;
Expand Down
1 change: 1 addition & 0 deletions src/i18n/strings/en_EN.json
Original file line number Diff line number Diff line change
Expand Up @@ -2065,6 +2065,7 @@
"Declining …": "Declining …",
"%(name)s wants to verify": "%(name)s wants to verify",
"You sent a verification request": "You sent a verification request",
"Failed to load map": "Failed to load map",
"Vote not registered": "Vote not registered",
"Sorry, your vote was not registered. Please try again.": "Sorry, your vote was not registered. Please try again.",
"No votes cast": "No votes cast",
Expand Down