@@ -19,105 +19,38 @@ import maplibregl from 'maplibre-gl';
19
19
import { logger } from "matrix-js-sdk/src/logger" ;
20
20
21
21
import SdkConfig from '../../../SdkConfig' ;
22
- import Field from "../elements/Field" ;
23
22
import DialogButtons from "../elements/DialogButtons" ;
24
- import Dropdown from "../elements/Dropdown" ;
25
- import LocationShareType from "./LocationShareType" ;
26
23
import { _t } from '../../../languageHandler' ;
27
24
import { replaceableComponent } from "../../../utils/replaceableComponent" ;
28
25
29
- interface IDropdownProps {
30
- value : LocationShareType ;
31
- label : string ;
32
- width ?: number ;
33
- onChange ( type : LocationShareType ) : void ;
34
- }
35
-
36
- const LocationShareTypeDropdown = ( {
37
- value,
38
- label,
39
- width,
40
- onChange,
41
- } : IDropdownProps ) => {
42
- const options = [
43
- < div key = { LocationShareType . Custom } > {
44
- _t ( "Share custom location" )
45
- } </ div > ,
46
- < div key = { LocationShareType . OnceOff } > {
47
- _t ( "Share my current location as a once off" )
48
- } </ div > ,
49
- // <div key={LocationShareType.OneMin}>{
50
- // _t("Share my current location for one minute")
51
- // }</div>,
52
- // <div key={LocationShareType.FiveMins}>{
53
- // _t("Share my current location for five minutes")
54
- // }</div>,
55
- // <div key={LocationShareType.ThirtyMins}>{
56
- // _t("Share my current location for thirty minutes")
57
- // }</div>,
58
- // <div key={LocationShareType.OneHour}>{
59
- // _t("Share my current location for one hour")
60
- // }</div>,
61
- // <div key={LocationShareType.ThreeHours}>{
62
- // _t("Share my current location for three hours")
63
- // }</div>,
64
- // <div key={LocationShareType.SixHours}>{
65
- // _t("Share my current location for six hours")
66
- // }</div>,
67
- // <div key={LocationShareType.OneDay}>{
68
- // _t("Share my current location for one day")
69
- // }</div>,
70
- // <div key={LocationShareType.Forever}>{
71
- // _t("Share my current location until I disable it")
72
- // }</div>,
73
- ] ;
74
-
75
- return < Dropdown
76
- id = "mx_LocationShareTypeDropdown"
77
- className = "mx_LocationShareTypeDropdown"
78
- onOptionChange = { ( key : string ) => {
79
- onChange ( LocationShareType [ LocationShareType [ parseInt ( key ) ] ] ) ;
80
- } }
81
- menuWidth = { width }
82
- label = { label }
83
- value = { value . toString ( ) }
84
- >
85
- { options }
86
- </ Dropdown > ;
87
- } ;
88
-
89
26
interface IProps {
90
- onChoose (
91
- uri : string ,
92
- ts : number ,
93
- type : LocationShareType ,
94
- description : string ,
95
- ) : boolean ;
27
+ onChoose ( uri : string , ts : number ) : boolean ;
96
28
onFinished ( ev ?: SyntheticEvent ) : void ;
97
29
}
98
30
99
31
interface IState {
100
- description : string ;
101
- type : LocationShareType ;
102
32
position ?: GeolocationPosition ;
103
- manualPosition ?: GeolocationPosition ;
104
33
error : Error ;
105
34
}
106
35
36
+ /*
37
+ * An older version of this file allowed manually picking a location on
38
+ * the map to share, instead of sharing your current location.
39
+ * Since the current designs do not cover this case, it was removed from
40
+ * the code but you should be able to find it in the git history by
41
+ * searching for the commit that remove manualPosition from this file.
42
+ */
43
+
107
44
@replaceableComponent ( "views.location.LocationPicker" )
108
45
class LocationPicker extends React . Component < IProps , IState > {
109
46
private map : maplibregl . Map ;
110
- private marker : maplibregl . Marker ;
111
47
private geolocate : maplibregl . GeolocateControl ;
112
48
113
49
constructor ( props : IProps ) {
114
50
super ( props ) ;
115
51
116
52
this . state = {
117
- description : _t ( "My location" ) ,
118
- type : LocationShareType . OnceOff ,
119
53
position : undefined ,
120
- manualPosition : undefined ,
121
54
error : undefined ,
122
55
} ;
123
56
}
@@ -154,53 +87,13 @@ class LocationPicker extends React.Component<IProps, IState> {
154
87
this . geolocate . trigger ( ) ;
155
88
} ) ;
156
89
157
- this . map . on ( 'click' , ( e ) => {
158
- this . addMarker ( e . lngLat ) ;
159
- this . storeManualPosition ( e . lngLat ) ;
160
- this . setState ( { type : LocationShareType . Custom } ) ;
161
- } ) ;
162
-
163
90
this . geolocate . on ( 'geolocate' , this . onGeolocate ) ;
164
91
} catch ( e ) {
165
92
logger . error ( "Failed to render map" , e . error ) ;
166
93
this . setState ( { error : e . error } ) ;
167
94
}
168
95
}
169
96
170
- private addMarker ( lngLat : maplibregl . LngLat ) : void {
171
- if ( this . marker ) return ;
172
- this . marker = new maplibregl . Marker ( {
173
- draggable : true ,
174
- } )
175
- . setLngLat ( lngLat )
176
- . addTo ( this . map )
177
- . on ( 'dragend' , ( ) => {
178
- this . storeManualPosition ( this . marker . getLngLat ( ) ) ;
179
- } ) ;
180
- }
181
-
182
- private removeMarker ( ) : void {
183
- if ( ! this . marker ) return ;
184
- this . marker . remove ( ) ;
185
- this . marker = undefined ;
186
- }
187
-
188
- private storeManualPosition ( lngLat : maplibregl . LngLat ) : void {
189
- const manualPosition : GeolocationPosition = {
190
- coords : {
191
- longitude : lngLat . lng ,
192
- latitude : lngLat . lat ,
193
- altitude : undefined ,
194
- accuracy : undefined ,
195
- altitudeAccuracy : undefined ,
196
- heading : undefined ,
197
- speed : undefined ,
198
- } ,
199
- timestamp : Date . now ( ) ,
200
- } ;
201
- this . setState ( { manualPosition } ) ;
202
- }
203
-
204
97
componentWillUnmount ( ) {
205
98
this . geolocate ?. off ( 'geolocate' , this . onGeolocate ) ;
206
99
}
@@ -209,41 +102,16 @@ class LocationPicker extends React.Component<IProps, IState> {
209
102
this . setState ( { position } ) ;
210
103
} ;
211
104
212
- private onDescriptionChange = ( ev : React . ChangeEvent < HTMLInputElement > ) => {
213
- this . setState ( { description : ev . target . value } ) ;
214
- } ;
215
-
216
105
private onOk = ( ) => {
217
- const position = ( this . state . type == LocationShareType . Custom ) ?
218
- this . state . manualPosition : this . state . position ;
106
+ const position = this . state . position ;
219
107
220
108
this . props . onChoose (
221
109
position ? getGeoUri ( position ) : undefined ,
222
110
position ? position . timestamp : undefined ,
223
- this . state . type ,
224
- this . state . description ,
225
111
) ;
226
112
this . props . onFinished ( ) ;
227
113
} ;
228
114
229
- private onTypeChange = ( type : LocationShareType ) => {
230
- if ( type == LocationShareType . Custom ) {
231
- if ( ! this . state . manualPosition ) {
232
- this . setState ( { manualPosition : this . state . position } ) ;
233
- }
234
- if ( this . state . manualPosition ) {
235
- this . addMarker ( new maplibregl . LngLat (
236
- this . state . manualPosition ?. coords . longitude ,
237
- this . state . manualPosition ?. coords . latitude ,
238
- ) ) ;
239
- }
240
- } else {
241
- this . removeMarker ( ) ;
242
- }
243
-
244
- this . setState ( { type } ) ;
245
- } ;
246
-
247
115
render ( ) {
248
116
const error = this . state . error ?
249
117
< div className = "mx_LocationPicker_error" >
@@ -256,28 +124,10 @@ class LocationPicker extends React.Component<IProps, IState> {
256
124
{ error }
257
125
< div className = "mx_LocationPicker_footer" >
258
126
< form onSubmit = { this . onOk } >
259
- < LocationShareTypeDropdown
260
- value = { this . state . type }
261
- label = { _t ( "Type of location share" ) }
262
- onChange = { this . onTypeChange }
263
- width = { 400 }
264
- />
265
-
266
- < Field
267
- label = { _t ( 'Description' ) }
268
- onChange = { this . onDescriptionChange }
269
- value = { this . state . description }
270
- width = { 400 }
271
- className = "mx_LocationPicker_description"
272
- />
273
-
274
127
< DialogButtons primaryButton = { _t ( 'Share' ) }
275
128
onPrimaryButtonClick = { this . onOk }
276
129
onCancel = { this . props . onFinished }
277
- primaryDisabled = {
278
- ! this . state . position &&
279
- ! this . state . manualPosition
280
- } />
130
+ primaryDisabled = { ! this . state . position } />
281
131
</ form >
282
132
</ div >
283
133
</ div >
0 commit comments