This repository has been archived by the owner on Sep 11, 2024. It is now read-only.
-
-
Notifications
You must be signed in to change notification settings - Fork 833
Location share type UI #7924
Merged
Merged
Location share type UI #7924
Changes from 15 commits
Commits
Show all changes
20 commits
Select commit
Hold shift + click to select a range
1001a51
copyright
5871296
empty line
59ef737
functional picker
57ace01
most style
30fb04b
nice style for options
8860236
get ShareType test passing
a1ee865
add maplibre mock
f6dfc0d
lint and test
584e65e
add section to themes for location sharing cols
1ec54d2
add svg mock
13dbf09
use same mock string as imageMock
5ba2a25
newline
203873e
Merge branch 'kerryarchibald/svg-loader-mock' into psf-728/share-type…
3fda70f
lint
ba96880
Merge branch 'develop' into psf-728/share-type-switch
t3chguy 414e13f
add live location icon
646ade9
rename useEnabledShareTypes
6cd9bf1
use solid color for live border
042ac1c
Merge branch 'psf-728/share-type-switch' of https://github.com/matrix…
294a8e1
use ternary
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 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,20 @@ | ||
const EventEmitter = require("events"); | ||
const { LngLat } = require('maplibre-gl'); | ||
|
||
class MockMap extends EventEmitter { | ||
addControl = jest.fn(); | ||
removeControl = jest.fn(); | ||
} | ||
class MockGeolocateControl extends EventEmitter { | ||
|
||
} | ||
class MockMarker extends EventEmitter { | ||
setLngLat = jest.fn().mockReturnValue(this); | ||
addTo = jest.fn(); | ||
} | ||
module.exports = { | ||
Map: MockMap, | ||
GeolocateControl: MockGeolocateControl, | ||
Marker: MockMarker, | ||
LngLat, | ||
}; |
This file contains 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 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,90 @@ | ||
/* | ||
Copyright 2022 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_ShareType { | ||
flex: 1; | ||
display: flex; | ||
flex-direction: column; | ||
justify-content: flex-start; | ||
align-items: center; | ||
|
||
padding: 60px $spacing-12 $spacing-32; | ||
|
||
color: $primary-content; | ||
} | ||
|
||
.mx_ShareType_badge { | ||
height: 60px; | ||
width: 60px; | ||
margin-bottom: $spacing-20; | ||
background-color: $accent; | ||
border-radius: 50%; | ||
} | ||
|
||
.mx_ShareType_heading { | ||
padding-bottom: $spacing-32; | ||
text-align: center; | ||
} | ||
|
||
.mx_ShareType_option { | ||
@mixin ButtonResetDefault; | ||
|
||
width: 100%; | ||
display: flex; | ||
flex-direction: row; | ||
align-items: center; | ||
justify-content: flex-start; | ||
padding: $spacing-8 $spacing-20; | ||
margin-top: $spacing-12; | ||
|
||
color: $primary-content; | ||
border: 1px solid $quinary-content; | ||
border-radius: 8px; | ||
|
||
font-size: $font-15px; | ||
|
||
&:hover, &:focus { | ||
border-color: $accent; | ||
} | ||
} | ||
|
||
.mx_ShareType_option-icon { | ||
height: 40px; | ||
width: 40px; | ||
box-sizing: border-box; | ||
margin-right: $spacing-12; | ||
flex: 0 0 40px; | ||
border-width: 2px; | ||
border-style: solid; | ||
border-radius: 50%; | ||
|
||
&.Own { | ||
// color is set by user color class | ||
// generated from id | ||
border-color: currentColor; | ||
} | ||
|
||
&.Live { | ||
background-color: $location-live-color; | ||
// TODO opacity | ||
border-color: $location-live-color; | ||
} | ||
|
||
&.Pin { | ||
border-color: $accent; | ||
background-color: $accent; | ||
} | ||
} |
This file contains 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 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 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 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 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 |
---|---|---|
|
@@ -14,13 +14,15 @@ See the License for the specific language governing permissions and | |
limitations under the License. | ||
*/ | ||
|
||
import React, { SyntheticEvent, useContext } from 'react'; | ||
import React, { SyntheticEvent, useContext, useState } from 'react'; | ||
import { Room } from 'matrix-js-sdk/src/models/room'; | ||
|
||
import MatrixClientContext from '../../../contexts/MatrixClientContext'; | ||
import ContextMenu, { AboveLeftOf } from '../../structures/ContextMenu'; | ||
import LocationPicker, { ILocationPickerProps } from "./LocationPicker"; | ||
import { shareLocation } from './shareLocation'; | ||
import SettingsStore from '../../../settings/SettingsStore'; | ||
import ShareType, { LocationShareType } from './ShareType'; | ||
|
||
type Props = Omit<ILocationPickerProps, 'onChoose'> & { | ||
onFinished: (ev?: SyntheticEvent) => void; | ||
|
@@ -29,22 +31,40 @@ type Props = Omit<ILocationPickerProps, 'onChoose'> & { | |
roomId: Room["roomId"]; | ||
}; | ||
|
||
const useEnabledShareTypes = (): LocationShareType[] => { | ||
const isPinDropLocationShareEnabled = SettingsStore.getValue("feature_location_share_pin_drop"); | ||
|
||
if (isPinDropLocationShareEnabled) { | ||
return [LocationShareType.Own, LocationShareType.Pin]; | ||
} | ||
return [ | ||
LocationShareType.Own, | ||
]; | ||
}; | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This will be evaluated as a hook due to its name beginning with |
||
|
||
const LocationShareMenu: React.FC<Props> = ({ | ||
menuPosition, onFinished, sender, roomId, openMenu, | ||
}) => { | ||
const matrixClient = useContext(MatrixClientContext); | ||
const enabledShareTypes = useEnabledShareTypes(); | ||
|
||
const [shareType, setShareType] = useState<LocationShareType>( | ||
enabledShareTypes.length === 1 ? LocationShareType.Own : undefined, | ||
); | ||
|
||
return <ContextMenu | ||
{...menuPosition} | ||
onFinished={onFinished} | ||
managed={false} | ||
> | ||
<div className="mx_LocationShareMenu"> | ||
<LocationPicker | ||
{ !shareType && <ShareType setShareType={setShareType} enabledShareTypes={enabledShareTypes} /> } | ||
{ !!shareType && <LocationPicker | ||
sender={sender} | ||
onChoose={shareLocation(matrixClient, roomId, openMenu)} | ||
onFinished={onFinished} | ||
/> | ||
} | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. IMO would be more readable as a ternary |
||
</div> | ||
</ContextMenu>; | ||
}; | ||
|
This file contains 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,100 @@ | ||||||||
/* | ||||||||
Copyright 2022 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, { HTMLAttributes, useContext } from 'react'; | ||||||||
|
||||||||
import MatrixClientContext from '../../../contexts/MatrixClientContext'; | ||||||||
import { _t } from '../../../languageHandler'; | ||||||||
import { OwnProfileStore } from '../../../stores/OwnProfileStore'; | ||||||||
import { getUserNameColorClass } from '../../../utils/FormattingUtils'; | ||||||||
import BaseAvatar from '../avatars/BaseAvatar'; | ||||||||
import AccessibleButton from '../elements/AccessibleButton'; | ||||||||
import Heading from '../typography/Heading'; | ||||||||
|
||||||||
const UserAvatar = () => { | ||||||||
const matrixClient = useContext(MatrixClientContext); | ||||||||
const userId = matrixClient.getUserId(); | ||||||||
const displayName = OwnProfileStore.instance.displayName; | ||||||||
// 40 - 2px border | ||||||||
const avatarSize = 36; | ||||||||
const avatarUrl = OwnProfileStore.instance.getHttpAvatarUrl(avatarSize); | ||||||||
const colorClass = getUserNameColorClass(userId); | ||||||||
|
||||||||
return <div className={`mx_ShareType_option-icon ${LocationShareType.Own} ${colorClass}`}> | ||||||||
<BaseAvatar | ||||||||
idName={userId} | ||||||||
name={displayName} | ||||||||
url={avatarUrl} | ||||||||
width={avatarSize} | ||||||||
height={avatarSize} | ||||||||
resizeMethod="crop" | ||||||||
className="mx_UserMenu_userAvatar_BaseAvatar" | ||||||||
/></div>; | ||||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Suggested change
|
||||||||
}; | ||||||||
|
||||||||
const LocationPinIcon = () => <div className={`mx_ShareType_option-icon ${LocationShareType.Pin}`} />; | ||||||||
|
||||||||
// TODO this will be defined somewhere better | ||||||||
export enum LocationShareType { | ||||||||
Own = 'Own', | ||||||||
Pin = 'Pin', | ||||||||
Live = 'Live' | ||||||||
} | ||||||||
type ShareTypeOptionProps = HTMLAttributes<Element> & { label: string, shareType: LocationShareType }; | ||||||||
const ShareTypeOption: React.FC<ShareTypeOptionProps> = ({ | ||||||||
onClick, label, shareType, ...rest | ||||||||
}) => <AccessibleButton | ||||||||
element='button' | ||||||||
className='mx_ShareType_option' | ||||||||
onClick={onClick} | ||||||||
// not yet implemented | ||||||||
disabled={shareType !== LocationShareType.Own} | ||||||||
{...rest}> | ||||||||
|
||||||||
{ shareType === LocationShareType.Own && <UserAvatar /> } | ||||||||
{ shareType === LocationShareType.Pin && <LocationPinIcon /> } | ||||||||
|
||||||||
{ label } | ||||||||
</AccessibleButton>; | ||||||||
|
||||||||
interface Props { | ||||||||
setShareType: (shareType: LocationShareType) => void; | ||||||||
enabledShareTypes: LocationShareType[]; | ||||||||
} | ||||||||
const ShareType: React.FC<Props> = ({ | ||||||||
setShareType, enabledShareTypes, | ||||||||
}) => { | ||||||||
const labels = { | ||||||||
[LocationShareType.Own]: _t('My current location'), | ||||||||
[LocationShareType.Live]: _t('My live location'), | ||||||||
[LocationShareType.Pin]: _t('Drop a Pin'), | ||||||||
}; | ||||||||
return <div className='mx_ShareType'> | ||||||||
<div className='mx_ShareType_badge' /> | ||||||||
<Heading className='mx_ShareType_heading' size='h3'>{ _t("What location type do you want to share?") }</Heading> | ||||||||
{ enabledShareTypes.map((type) => | ||||||||
<ShareTypeOption | ||||||||
key={type} | ||||||||
onClick={() => setShareType(type)} | ||||||||
label={labels[type]} | ||||||||
shareType={type} | ||||||||
data-test-id={`share-location-option-${type}`} | ||||||||
/>, | ||||||||
) } | ||||||||
</div>; | ||||||||
}; | ||||||||
|
||||||||
export default ShareType; |
This file contains 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 |
---|---|---|
@@ -1,4 +1,3 @@ | ||
|
||
/* | ||
Copyright 2022 The Matrix.org Foundation C.I.C. | ||
|
||
|
This file contains 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
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.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
presumably this will be done as part of live location sharing work in the future?