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

Commit fbbb9c2

Browse files
author
Kerry
authored
Live location share - beacon tooltip in maximised view (#8572) PSF-926
* pass optional tooltip prop down through markers Signed-off-by: Kerry Archibald <[email protected]> * add beaconstatustooltip, handle overflow on beacon status label Signed-off-by: Kerry Archibald <[email protected]> * remove debug, fix mouseout Signed-off-by: Kerry Archibald <[email protected]> * tidy comments Signed-off-by: Kerry Archibald <[email protected]>
1 parent fdd5494 commit fbbb9c2

File tree

14 files changed

+271
-118
lines changed

14 files changed

+271
-118
lines changed

res/css/_components.scss

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@
66
@import "./_spacing.scss";
77
@import "./components/views/beacon/_BeaconListItem.scss";
88
@import "./components/views/beacon/_BeaconStatus.scss";
9+
@import "./components/views/beacon/_BeaconStatusTooltip.scss";
910
@import "./components/views/beacon/_BeaconViewDialog.scss";
1011
@import "./components/views/beacon/_DialogOwnBeaconStatus.scss";
1112
@import "./components/views/beacon/_DialogSidebar.scss";
@@ -143,7 +144,6 @@
143144
@import "./views/elements/_AddressSelector.scss";
144145
@import "./views/elements/_AddressTile.scss";
145146
@import "./views/elements/_CopyableText.scss";
146-
@import "./views/elements/_SearchWarning.scss";
147147
@import "./views/elements/_DesktopCapturerSourcePicker.scss";
148148
@import "./views/elements/_DialPadBackspaceButton.scss";
149149
@import "./views/elements/_DirectorySearchBox.scss";
@@ -172,6 +172,7 @@
172172
@import "./views/elements/_RoleButton.scss";
173173
@import "./views/elements/_RoomAliasField.scss";
174174
@import "./views/elements/_SSOButtons.scss";
175+
@import "./views/elements/_SearchWarning.scss";
175176
@import "./views/elements/_ServerPicker.scss";
176177
@import "./views/elements/_SettingsFlag.scss";
177178
@import "./views/elements/_Slider.scss";

res/css/components/views/beacon/_BeaconListItem.scss

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -40,6 +40,7 @@ limitations under the License.
4040

4141
.mx_BeaconListItem_info {
4242
flex: 1 1 0;
43+
width: 0;
4344
display: flex;
4445
flex-direction: column;
4546
align-items: stretch;

res/css/components/views/beacon/_BeaconStatus.scss

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -46,14 +46,15 @@ limitations under the License.
4646
}
4747

4848
.mx_BeaconStatus_description {
49-
flex: 1;
49+
flex: 1 1 0;
5050
display: flex;
5151
flex-direction: column;
5252
line-height: $font-14px;
5353

5454
padding-right: $spacing-8;
5555

56-
// TODO handle text-overflow
56+
white-space: nowrap;
57+
overflow: hidden;
5758
}
5859

5960
.mx_BeaconStatus_expiryTime {
@@ -62,4 +63,6 @@ limitations under the License.
6263

6364
.mx_BeaconStatus_label {
6465
margin-bottom: 2px;
66+
overflow: hidden;
67+
text-overflow: ellipsis;
6568
}
Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,37 @@
1+
/*
2+
Copyright 2022 The Matrix.org Foundation C.I.C.
3+
4+
Licensed under the Apache License, Version 2.0 (the "License");
5+
you may not use this file except in compliance with the License.
6+
You may obtain a copy of the License at
7+
8+
http://www.apache.org/licenses/LICENSE-2.0
9+
10+
Unless required by applicable law or agreed to in writing, software
11+
distributed under the License is distributed on an "AS IS" BASIS,
12+
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13+
See the License for the specific language governing permissions and
14+
limitations under the License.
15+
*/
16+
17+
.mx_BeaconStatusTooltip {
18+
position: absolute;
19+
top: 42px;
20+
max-width: 150px;
21+
height: 38px;
22+
box-sizing: content-box;
23+
padding-top: $spacing-8;
24+
25+
// override copyable text style to make compact
26+
.mx_CopyableText_copyButton {
27+
margin-left: 0 !important;
28+
}
29+
}
30+
31+
.mx_BeaconStatusTooltip_inner {
32+
position: relative;
33+
height: 100%;
34+
border-radius: 4px;
35+
background: $menu-bg-color;
36+
box-shadow: 4px 4px 12px 0 $menu-box-shadow-color;
37+
}

src/components/views/beacon/BeaconMarker.tsx

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ See the License for the specific language governing permissions and
1414
limitations under the License.
1515
*/
1616

17-
import React, { useContext } from 'react';
17+
import React, { ReactNode, useContext } from 'react';
1818
import maplibregl from 'maplibre-gl';
1919
import {
2020
Beacon,
@@ -29,12 +29,13 @@ import SmartMarker from '../location/SmartMarker';
2929
interface Props {
3030
map: maplibregl.Map;
3131
beacon: Beacon;
32+
tooltip?: ReactNode;
3233
}
3334

3435
/**
3536
* Updates a map SmartMarker with latest location from given beacon
3637
*/
37-
const BeaconMarker: React.FC<Props> = ({ map, beacon }) => {
38+
const BeaconMarker: React.FC<Props> = ({ map, beacon, tooltip }) => {
3839
const latestLocationState = useEventEmitterState(
3940
beacon,
4041
BeaconEvent.LocationUpdate,
@@ -58,6 +59,7 @@ const BeaconMarker: React.FC<Props> = ({ map, beacon }) => {
5859
id={beacon.identifier}
5960
geoUri={geoUri}
6061
roomMember={markerRoomMember}
62+
tooltip={tooltip}
6163
useMemberColor
6264
/>;
6365
};
Lines changed: 61 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,61 @@
1+
/*
2+
Copyright 2022 The Matrix.org Foundation C.I.C.
3+
4+
Licensed under the Apache License, Version 2.0 (the "License");
5+
you may not use this file except in compliance with the License.
6+
You may obtain a copy of the License at
7+
8+
http://www.apache.org/licenses/LICENSE-2.0
9+
10+
Unless required by applicable law or agreed to in writing, software
11+
distributed under the License is distributed on an "AS IS" BASIS,
12+
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13+
See the License for the specific language governing permissions and
14+
limitations under the License.
15+
*/
16+
17+
import React, { useContext } from 'react';
18+
import { Beacon } from 'matrix-js-sdk/src/matrix';
19+
import { LocationAssetType } from 'matrix-js-sdk/src/@types/location';
20+
21+
import MatrixClientContext from '../../../contexts/MatrixClientContext';
22+
import CopyableText from '../elements/CopyableText';
23+
import BeaconStatus from './BeaconStatus';
24+
import { BeaconDisplayStatus } from './displayStatus';
25+
26+
interface Props {
27+
beacon: Beacon;
28+
}
29+
30+
const useBeaconName = (beacon: Beacon): string => {
31+
const matrixClient = useContext(MatrixClientContext);
32+
33+
if (beacon.beaconInfo.assetType !== LocationAssetType.Self) {
34+
return beacon.beaconInfo.description;
35+
}
36+
const room = matrixClient.getRoom(beacon.roomId);
37+
const member = room?.getMember(beacon.beaconInfoOwner);
38+
39+
return member?.rawDisplayName || beacon.beaconInfoOwner;
40+
};
41+
42+
const BeaconStatusTooltip: React.FC<Props> = ({ beacon }) => {
43+
const label = useBeaconName(beacon);
44+
45+
return <div className='mx_BeaconStatusTooltip'>
46+
<BeaconStatus
47+
beacon={beacon}
48+
label={label}
49+
displayStatus={BeaconDisplayStatus.Active}
50+
displayLiveTimeRemaining
51+
className='mx_BeaconStatusTooltip_inner'
52+
>
53+
<CopyableText
54+
border={false}
55+
getTextToCopy={() => beacon.latestLocationState?.uri}
56+
/>
57+
</BeaconStatus>
58+
</div>;
59+
};
60+
61+
export default BeaconStatusTooltip;

src/components/views/beacon/BeaconViewDialog.tsx

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,7 @@ import { _t } from '../../../languageHandler';
3737
import AccessibleButton from '../elements/AccessibleButton';
3838
import DialogSidebar from './DialogSidebar';
3939
import DialogOwnBeaconStatus from './DialogOwnBeaconStatus';
40+
import BeaconStatusTooltip from './BeaconStatusTooltip';
4041

4142
interface IProps extends IDialogProps {
4243
roomId: Room['roomId'];
@@ -103,6 +104,7 @@ const BeaconViewDialog: React.FC<IProps> = ({
103104
key={beacon.identifier}
104105
map={map}
105106
beacon={beacon}
107+
tooltip={<BeaconStatusTooltip beacon={beacon} />}
106108
/>) }
107109
<ZoomButtons map={map} />
108110
</>

src/components/views/location/Marker.tsx

Lines changed: 44 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ See the License for the specific language governing permissions and
1414
limitations under the License.
1515
*/
1616

17-
import React from 'react';
17+
import React, { ReactNode, useState } from 'react';
1818
import classNames from 'classnames';
1919
import { RoomMember } from 'matrix-js-sdk/src/matrix';
2020

@@ -28,12 +28,39 @@ interface Props {
2828
roomMember?: RoomMember;
2929
// use member text color as background
3030
useMemberColor?: boolean;
31+
tooltip?: ReactNode;
3132
}
3233

34+
/**
35+
* Wrap with tooltip handlers when
36+
* tooltip is truthy
37+
*/
38+
const OptionalTooltip: React.FC<{
39+
tooltip?: ReactNode; children: ReactNode;
40+
}> = ({ tooltip, children }) => {
41+
const [isVisible, setIsVisible] = useState(false);
42+
if (!tooltip) {
43+
return <>{ children }</>;
44+
}
45+
46+
const show = () => setIsVisible(true);
47+
const hide = () => setIsVisible(false);
48+
const toggleVisibility = (e: React.MouseEvent<HTMLDivElement, MouseEvent>) => {
49+
// stop map from zooming in on click
50+
e.stopPropagation();
51+
setIsVisible(!isVisible);
52+
};
53+
54+
return <div onMouseEnter={show} onClick={toggleVisibility} onMouseLeave={hide}>
55+
{ children }
56+
{ isVisible && tooltip }
57+
</div>;
58+
};
59+
3360
/**
3461
* Generic location marker
3562
*/
36-
const Marker = React.forwardRef<HTMLDivElement, Props>(({ id, roomMember, useMemberColor }, ref) => {
63+
const Marker = React.forwardRef<HTMLDivElement, Props>(({ id, roomMember, useMemberColor, tooltip }, ref) => {
3764
const memberColorClass = useMemberColor && roomMember ? getUserNameColorClass(roomMember.userId) : '';
3865
return <div
3966
ref={ref}
@@ -42,17 +69,21 @@ const Marker = React.forwardRef<HTMLDivElement, Props>(({ id, roomMember, useMem
4269
"mx_Marker_defaultColor": !memberColorClass,
4370
})}
4471
>
45-
<div className="mx_Marker_border">
46-
{ roomMember ?
47-
<MemberAvatar
48-
member={roomMember}
49-
width={36}
50-
height={36}
51-
viewUserOnClick={false}
52-
/>
53-
: <LocationIcon className="mx_Marker_icon" />
54-
}
55-
</div>
72+
<OptionalTooltip tooltip={tooltip}>
73+
<div className="mx_Marker_border">
74+
{ roomMember ?
75+
<MemberAvatar
76+
member={roomMember}
77+
width={36}
78+
height={36}
79+
viewUserOnClick={false}
80+
// no mxid on hover when marker has tooltip
81+
hideTitle={!!tooltip}
82+
/>
83+
: <LocationIcon className="mx_Marker_icon" />
84+
}
85+
</div>
86+
</OptionalTooltip>
5687
</div>;
5788
});
5889

src/components/views/location/SmartMarker.tsx

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ See the License for the specific language governing permissions and
1414
limitations under the License.
1515
*/
1616

17-
import React, { useCallback, useEffect, useState } from 'react';
17+
import React, { ReactNode, useCallback, useEffect, useState } from 'react';
1818
import maplibregl from 'maplibre-gl';
1919
import { RoomMember } from 'matrix-js-sdk/src/matrix';
2020

@@ -64,12 +64,13 @@ interface SmartMarkerProps {
6464
roomMember?: RoomMember;
6565
// use member text color as background
6666
useMemberColor?: boolean;
67+
tooltip?: ReactNode;
6768
}
6869

6970
/**
7071
* Generic location marker
7172
*/
72-
const SmartMarker: React.FC<SmartMarkerProps> = ({ id, map, geoUri, roomMember, useMemberColor }) => {
73+
const SmartMarker: React.FC<SmartMarkerProps> = ({ id, map, geoUri, roomMember, useMemberColor, tooltip }) => {
7374
const { onElementRef } = useMapMarker(map, geoUri);
7475

7576
return (
@@ -84,6 +85,7 @@ const SmartMarker: React.FC<SmartMarkerProps> = ({ id, map, geoUri, roomMember,
8485
id={id}
8586
roomMember={roomMember}
8687
useMemberColor={useMemberColor}
88+
tooltip={tooltip}
8789
/>
8890
</span>
8991
);

0 commit comments

Comments
 (0)