This repository was archived by the owner on Sep 11, 2024. It is now read-only.
-
-
Notifications
You must be signed in to change notification settings - Fork 820
Simple static location sharing #7135
Merged
Merged
Changes from all 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 7970b90
fix css
ara4n 12bb69b
fix dropdown height
ara4n 1b75489
fix form
ara4n cd9ea95
use right icon
ara4n 3a779b7
hook up locationpicker
ara4n 3b0a3a2
actually send m.location events
ara4n 6ce1e86
view m.location
ara4n e7cd207
border radius on picker
ara4n fc41580
fix lint
ara4n bec7af4
Merge branch 'develop' into matthew/location-share
ara4n d6b5153
Merge branch 'develop' into matthew/location-share
ara4n ccd416d
fix css var
ara4n eebf29d
fix types
ara4n 426f7b3
only send loc if you have one
ara4n 94f1ff9
disable the streaming options until they're hooked up
ara4n 6488168
lint
ara4n 644fe03
more lint
ara4n f774e71
fix i18n
ara4n 80a15a1
show descriptions
ara4n 92ba926
incorporate review
ara4n 5531d09
use fancy optional chaining
ara4n 8fd4310
add createObjectURL mock
ara4n 097c8f7
fix i18n
ara4n 3dc7b21
Merge branch 'develop' into matthew/location-share
ara4n 982d5b7
warn if API key not set when showing maps
ara4n 6ea351e
Merge branch 'develop' into matthew/location-share
ara4n 49c590c
export LocationShareType enum correctly
ara4n f088094
hook up map failure error correctly
ara4n 58ebf2a
fix lint
ara4n e6842ba
fix type
ara4n d6b805a
fix types
ara4n File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,44 @@ | ||
/* | ||
Copyright 2021 The Matrix.org Foundation C.I.C | ||
|
||
Licensed under the Apache License, Version 2.0 (the "License"); | ||
you may not use this file except in compliance with the License. | ||
You may obtain a copy of the License at | ||
|
||
http://www.apache.org/licenses/LICENSE-2.0 | ||
|
||
Unless required by applicable law or agreed to in writing, software | ||
distributed under the License is distributed on an "AS IS" BASIS, | ||
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
See the License for the specific language governing permissions and | ||
limitations under the License. | ||
*/ | ||
|
||
.mx_LocationPicker { | ||
// placeholder sizing to be replaced once there's a proper design | ||
width: 450px; | ||
height: 500px; | ||
|
||
border-radius: 4px; | ||
|
||
display: flex; | ||
flex-direction: column; | ||
} | ||
|
||
#mx_LocationPicker_map { | ||
height: 324px; | ||
border-radius: 8px 8px 0px 0px; | ||
} | ||
|
||
.mx_LocationPicker_footer { | ||
margin: 24px; | ||
|
||
.mx_Dropdown_menu { | ||
max-height: 140px; | ||
} | ||
} | ||
|
||
.mx_LocationPicker_error { | ||
color: red; | ||
ara4n marked this conversation as resolved.
Show resolved
Hide resolved
|
||
margin: auto; | ||
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,22 @@ | ||
/* | ||
Copyright 2021 The Matrix.org Foundation C.I.C. | ||
|
||
Licensed under the Apache License, Version 2.0 (the "License"); | ||
you may not use this file except in compliance with the License. | ||
You may obtain a copy of the License at | ||
|
||
http://www.apache.org/licenses/LICENSE-2.0 | ||
|
||
Unless required by applicable law or agreed to in writing, software | ||
distributed under the License is distributed on an "AS IS" BASIS, | ||
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
See the License for the specific language governing permissions and | ||
limitations under the License. | ||
*/ | ||
|
||
.mx_MLocationBody_map { | ||
width: 450px; | ||
height: 300px; | ||
|
||
border-radius: $timeline-image-border-radius; | ||
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,200 @@ | ||
/* | ||
Copyright 2021 The Matrix.org Foundation C.I.C. | ||
|
||
Licensed under the Apache License, Version 2.0 (the "License"); | ||
you may not use this file except in compliance with the License. | ||
You may obtain a copy of the License at | ||
|
||
http://www.apache.org/licenses/LICENSE-2.0 | ||
|
||
Unless required by applicable law or agreed to in writing, software | ||
distributed under the License is distributed on an "AS IS" BASIS, | ||
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
See the License for the specific language governing permissions and | ||
limitations under the License. | ||
*/ | ||
|
||
import React from 'react'; | ||
import maplibregl from 'maplibre-gl'; | ||
|
||
import SdkConfig from '../../../SdkConfig'; | ||
import Field from "../elements/Field"; | ||
import DialogButtons from "../elements/DialogButtons"; | ||
import Dropdown from "../elements/Dropdown"; | ||
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; | ||
label: string; | ||
width?: number; | ||
onChange(type: LocationShareType): void; | ||
} | ||
|
||
const LocationShareTypeDropdown = ({ | ||
value, | ||
label, | ||
width, | ||
onChange, | ||
}: IDropdownProps) => { | ||
const options = [ | ||
// <div key={LocationShareType.Custom}>{ _t("Share custom location") }</div>, | ||
<div key={LocationShareType.OnceOff}>{ _t("Share my current location as a once off") }</div>, | ||
// <div key={LocationShareType.OneMin}>{ _t("Share my current location for one minute") }</div>, | ||
// <div key={LocationShareType.FiveMins}>{ _t("Share my current location for five minutes") }</div>, | ||
// <div key={LocationShareType.ThirtyMins}>{ _t("Share my current location for thirty minutes") }</div>, | ||
// <div key={LocationShareType.OneHour}>{ _t("Share my current location for one hour") }</div>, | ||
// <div key={LocationShareType.ThreeHours}>{ _t("Share my current location for three hours") }</div>, | ||
// <div key={LocationShareType.SixHours}>{ _t("Share my current location for six hours") }</div>, | ||
// <div key={LocationShareType.OneDay}>{ _t("Share my current location for one day") }</div>, | ||
// <div key={LocationShareType.Forever}>{ _t("Share my current location until I disable it") }</div>, | ||
]; | ||
|
||
return <Dropdown | ||
id="mx_LocationShareTypeDropdown" | ||
className="mx_LocationShareTypeDropdown" | ||
onOptionChange={(key: string)=>{ onChange(LocationShareType[LocationShareType[parseInt(key)]]); }} | ||
menuWidth={width} | ||
label={label} | ||
value={value.toString()} | ||
> | ||
{ options } | ||
</Dropdown>; | ||
}; | ||
|
||
interface IProps { | ||
onChoose(uri: string, ts: number, type: LocationShareType, description: string): boolean; | ||
onFinished(); | ||
} | ||
|
||
interface IState { | ||
description: string; | ||
type: LocationShareType; | ||
position?: GeolocationPosition; | ||
manual: boolean; | ||
error: Error; | ||
} | ||
|
||
@replaceableComponent("views.location.LocationPicker") | ||
class LocationPicker extends React.Component<IProps, IState> { | ||
private map: maplibregl.Map; | ||
private geolocate: maplibregl.GeolocateControl; | ||
|
||
constructor(props) { | ||
super(props); | ||
|
||
this.state = { | ||
description: _t("My location"), | ||
type: LocationShareType.OnceOff, | ||
position: undefined, | ||
manual: false, | ||
error: undefined, | ||
}; | ||
} | ||
|
||
componentDidMount() { | ||
const config = SdkConfig.get(); | ||
this.map = new maplibregl.Map({ | ||
container: 'mx_LocationPicker_map', | ||
style: config.map_style_url, | ||
center: [0, 0], | ||
zoom: 1, | ||
}); | ||
|
||
// Add geolocate control to the map. | ||
this.geolocate = new maplibregl.GeolocateControl({ | ||
positionOptions: { | ||
enableHighAccuracy: true, | ||
}, | ||
trackUserLocation: true, | ||
}); | ||
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(); | ||
}); | ||
|
||
this.geolocate.on('geolocate', this.onGeolocate); | ||
} | ||
|
||
componentWillUnmount() { | ||
this.geolocate.off('geolocate', this.onGeolocate); | ||
} | ||
|
||
private onGeolocate = (position) => { | ||
this.setState({ position }); | ||
}; | ||
|
||
private onDescriptionChange = (ev: React.ChangeEvent<HTMLInputElement>) => { | ||
this.setState({ description: ev.target.value }); | ||
}; | ||
|
||
private getGeoUri = (position) => { | ||
return (`geo:${ position.coords.latitude },` + | ||
position.coords.longitude + | ||
( position.coords.altitude != null ? | ||
`,${ position.coords.altitude }` : '' ) + | ||
`;u=${ position.coords.accuracy }`); | ||
}; | ||
|
||
private onOk = () => { | ||
this.props.onChoose( | ||
this.state.position ? this.getGeoUri(this.state.position) : undefined, | ||
this.state.position ? this.state.position.timestamp : undefined, | ||
this.state.type, | ||
this.state.description, | ||
); | ||
this.props.onFinished(); | ||
}; | ||
|
||
private onTypeChange= (type: LocationShareType) => { | ||
this.setState({ type }); | ||
}; | ||
|
||
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 | ||
value={this.state.type} | ||
label={_t("Type of location share")} | ||
onChange={this.onTypeChange} | ||
width={400} | ||
/> | ||
|
||
<Field | ||
label={_t('Description')} | ||
onChange={this.onDescriptionChange} | ||
value={this.state.description} | ||
width={400} | ||
className="mx_LocationPicker_description" | ||
/> | ||
|
||
<DialogButtons primaryButton={_t('Share')} | ||
onPrimaryButtonClick={this.onOk} | ||
onCancel={this.props.onFinished} | ||
disabled={!this.state.position} /> | ||
</form> | ||
</div> | ||
</div> | ||
); | ||
} | ||
} | ||
|
||
export default LocationPicker; |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,30 @@ | ||
/* | ||
Copyright 2021 The Matrix.org Foundation C.I.C. | ||
|
||
Licensed under the Apache License, Version 2.0 (the "License"); | ||
you may not use this file except in compliance with the License. | ||
You may obtain a copy of the License at | ||
|
||
http://www.apache.org/licenses/LICENSE-2.0 | ||
|
||
Unless required by applicable law or agreed to in writing, software | ||
distributed under the License is distributed on an "AS IS" BASIS, | ||
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
See the License for the specific language governing permissions and | ||
limitations under the License. | ||
*/ | ||
|
||
enum LocationShareType { | ||
Custom = -1, | ||
OnceOff = 0, | ||
OneMine = 60, | ||
FiveMins = 5 * 60, | ||
ThirtyMins = 30 * 60, | ||
OneHour = 60 * 60, | ||
ThreeHours = 3 * 60 * 60, | ||
SixHours = 6 * 60 * 60, | ||
OneDay = 24 * 60 * 60, | ||
Forever = Number.MAX_SAFE_INTEGER, | ||
} | ||
|
||
export default LocationShareType; |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.