Add a basic tooltip showing who reacted
This adds a first attempt at tooltip showing who reacted to a message. It doesn't limit senders or position the tooltip nicely, but the info is there at least. Part of https://github.com/vector-im/riot-web/issues/9722
This commit is contained in:
parent
32c68feae2
commit
3da1f73ea4
9 changed files with 180 additions and 3 deletions
|
@ -119,6 +119,7 @@
|
||||||
@import "./views/messages/_ReactionDimension.scss";
|
@import "./views/messages/_ReactionDimension.scss";
|
||||||
@import "./views/messages/_ReactionsRow.scss";
|
@import "./views/messages/_ReactionsRow.scss";
|
||||||
@import "./views/messages/_ReactionsRowButton.scss";
|
@import "./views/messages/_ReactionsRowButton.scss";
|
||||||
|
@import "./views/messages/_ReactionsRowButtonTooltip.scss";
|
||||||
@import "./views/messages/_RoomAvatarEvent.scss";
|
@import "./views/messages/_RoomAvatarEvent.scss";
|
||||||
@import "./views/messages/_SenderProfile.scss";
|
@import "./views/messages/_SenderProfile.scss";
|
||||||
@import "./views/messages/_TextualEvent.scss";
|
@import "./views/messages/_TextualEvent.scss";
|
||||||
|
|
34
res/css/views/messages/_ReactionsRowButtonTooltip.scss
Normal file
34
res/css/views/messages/_ReactionsRowButtonTooltip.scss
Normal file
|
@ -0,0 +1,34 @@
|
||||||
|
/*
|
||||||
|
Copyright 2019 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_ReactionsRowButtonTooltip {
|
||||||
|
box-shadow: none;
|
||||||
|
background-color: $reaction-row-button-tooltip-bg-color;
|
||||||
|
color: $reaction-row-button-tooltip-fg-color;
|
||||||
|
text-align: center;
|
||||||
|
font-size: 8px;
|
||||||
|
padding: 6px;
|
||||||
|
border: none;
|
||||||
|
border-radius: 3px;
|
||||||
|
|
||||||
|
.mx_Tooltip_chevron::after {
|
||||||
|
border-right-color: $reaction-row-button-tooltip-bg-color;
|
||||||
|
}
|
||||||
|
|
||||||
|
.mx_ReactionsRowButtonTooltip_reactedWith {
|
||||||
|
opacity: 0.7;
|
||||||
|
}
|
||||||
|
}
|
|
@ -156,6 +156,8 @@ $reaction-row-button-border-color: #616b7f;
|
||||||
$reaction-row-button-hover-border-color: $header-panel-text-primary-color;
|
$reaction-row-button-hover-border-color: $header-panel-text-primary-color;
|
||||||
$reaction-row-button-selected-bg-color: #1f6954;
|
$reaction-row-button-selected-bg-color: #1f6954;
|
||||||
$reaction-row-button-selected-border-color: $accent-color;
|
$reaction-row-button-selected-border-color: $accent-color;
|
||||||
|
$reaction-row-button-tooltip-bg-color: $tagpanel-bg-color;
|
||||||
|
$reaction-row-button-tooltip-fg-color: #ffffff;
|
||||||
|
|
||||||
// ***** Mixins! *****
|
// ***** Mixins! *****
|
||||||
|
|
||||||
|
|
|
@ -264,6 +264,8 @@ $reaction-row-button-border-color: #e9edf1;
|
||||||
$reaction-row-button-hover-border-color: $focus-bg-color;
|
$reaction-row-button-hover-border-color: $focus-bg-color;
|
||||||
$reaction-row-button-selected-bg-color: #e9fff9;
|
$reaction-row-button-selected-bg-color: #e9fff9;
|
||||||
$reaction-row-button-selected-border-color: $accent-color;
|
$reaction-row-button-selected-border-color: $accent-color;
|
||||||
|
$reaction-row-button-tooltip-bg-color: $tagpanel-bg-color;
|
||||||
|
$reaction-row-button-tooltip-fg-color: #ffffff;
|
||||||
|
|
||||||
// ***** Mixins! *****
|
// ***** Mixins! *****
|
||||||
|
|
||||||
|
|
|
@ -107,6 +107,17 @@ function unicodeToImage(str, addAlt) {
|
||||||
return str;
|
return str;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Returns the shortcode for an emoji character.
|
||||||
|
*
|
||||||
|
* @param {String} char The emoji character
|
||||||
|
* @return {String} The shortcode (such as :thumbup:)
|
||||||
|
*/
|
||||||
|
export function unicodeToShort(char) {
|
||||||
|
const unicode = emojione.jsEscapeMap[char];
|
||||||
|
return emojione.mapUnicodeToShort()[unicode];
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Given one or more unicode characters (represented by unicode
|
* Given one or more unicode characters (represented by unicode
|
||||||
* character number), return an image node with the corresponding
|
* character number), return an image node with the corresponding
|
||||||
|
|
|
@ -116,8 +116,8 @@ export default class ReactionsRow extends React.PureComponent {
|
||||||
return <ReactionsRowButton
|
return <ReactionsRowButton
|
||||||
key={content}
|
key={content}
|
||||||
content={content}
|
content={content}
|
||||||
count={count}
|
|
||||||
mxEvent={mxEvent}
|
mxEvent={mxEvent}
|
||||||
|
reactionEvents={events}
|
||||||
myReactionEvent={myReactionEvent}
|
myReactionEvent={myReactionEvent}
|
||||||
/>;
|
/>;
|
||||||
});
|
});
|
||||||
|
|
|
@ -19,17 +19,28 @@ import PropTypes from 'prop-types';
|
||||||
import classNames from 'classnames';
|
import classNames from 'classnames';
|
||||||
|
|
||||||
import MatrixClientPeg from '../../../MatrixClientPeg';
|
import MatrixClientPeg from '../../../MatrixClientPeg';
|
||||||
|
import sdk from '../../../index';
|
||||||
|
|
||||||
export default class ReactionsRowButton extends React.PureComponent {
|
export default class ReactionsRowButton extends React.PureComponent {
|
||||||
static propTypes = {
|
static propTypes = {
|
||||||
// The event we're displaying reactions for
|
// The event we're displaying reactions for
|
||||||
mxEvent: PropTypes.object.isRequired,
|
mxEvent: PropTypes.object.isRequired,
|
||||||
|
// The reaction content / key / emoji
|
||||||
content: PropTypes.string.isRequired,
|
content: PropTypes.string.isRequired,
|
||||||
count: PropTypes.number.isRequired,
|
// A Set of Martix reaction events for this key
|
||||||
|
reactionEvents: PropTypes.object.isRequired,
|
||||||
// A possible Matrix event if the current user has voted for this type
|
// A possible Matrix event if the current user has voted for this type
|
||||||
myReactionEvent: PropTypes.object,
|
myReactionEvent: PropTypes.object,
|
||||||
}
|
}
|
||||||
|
|
||||||
|
constructor(props) {
|
||||||
|
super(props);
|
||||||
|
|
||||||
|
this.state = {
|
||||||
|
tooltipVisible: false,
|
||||||
|
};
|
||||||
|
}
|
||||||
|
|
||||||
onClick = (ev) => {
|
onClick = (ev) => {
|
||||||
const { mxEvent, myReactionEvent, content } = this.props;
|
const { mxEvent, myReactionEvent, content } = this.props;
|
||||||
if (myReactionEvent) {
|
if (myReactionEvent) {
|
||||||
|
@ -48,18 +59,53 @@ export default class ReactionsRowButton extends React.PureComponent {
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
|
onMouseOver = () => {
|
||||||
|
this.setState({
|
||||||
|
// To avoid littering the DOM with a tooltip for every reaction,
|
||||||
|
// only render it on first use.
|
||||||
|
tooltipRendered: true,
|
||||||
|
tooltipVisible: true,
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
onMouseOut = () => {
|
||||||
|
this.setState({
|
||||||
|
tooltipVisible: false,
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
render() {
|
render() {
|
||||||
const { content, count, myReactionEvent } = this.props;
|
const ReactionsRowButtonTooltip =
|
||||||
|
sdk.getComponent('messages.ReactionsRowButtonTooltip');
|
||||||
|
const { content, reactionEvents, myReactionEvent } = this.props;
|
||||||
|
|
||||||
|
const count = reactionEvents.size;
|
||||||
|
if (!count) {
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
|
||||||
const classes = classNames({
|
const classes = classNames({
|
||||||
mx_ReactionsRowButton: true,
|
mx_ReactionsRowButton: true,
|
||||||
mx_ReactionsRowButton_selected: !!myReactionEvent,
|
mx_ReactionsRowButton_selected: !!myReactionEvent,
|
||||||
});
|
});
|
||||||
|
|
||||||
|
let tooltip;
|
||||||
|
if (this.state.tooltipRendered) {
|
||||||
|
tooltip = <ReactionsRowButtonTooltip
|
||||||
|
mxEvent={this.props.mxEvent}
|
||||||
|
content={content}
|
||||||
|
reactionEvents={reactionEvents}
|
||||||
|
visible={this.state.tooltipVisible}
|
||||||
|
/>;
|
||||||
|
}
|
||||||
|
|
||||||
return <span className={classes}
|
return <span className={classes}
|
||||||
onClick={this.onClick}
|
onClick={this.onClick}
|
||||||
|
onMouseOver={this.onMouseOver}
|
||||||
|
onMouseOut={this.onMouseOut}
|
||||||
>
|
>
|
||||||
{content} {count}
|
{content} {count}
|
||||||
|
{tooltip}
|
||||||
</span>;
|
</span>;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
80
src/components/views/messages/ReactionsRowButtonTooltip.js
Normal file
80
src/components/views/messages/ReactionsRowButtonTooltip.js
Normal file
|
@ -0,0 +1,80 @@
|
||||||
|
/*
|
||||||
|
Copyright 2019 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 PropTypes from 'prop-types';
|
||||||
|
|
||||||
|
import MatrixClientPeg from '../../../MatrixClientPeg';
|
||||||
|
import sdk from '../../../index';
|
||||||
|
import { unicodeToShort } from '../../../HtmlUtils';
|
||||||
|
import { _t } from '../../../languageHandler';
|
||||||
|
|
||||||
|
export default class ReactionsRowButtonTooltip extends React.PureComponent {
|
||||||
|
static propTypes = {
|
||||||
|
// The event we're displaying reactions for
|
||||||
|
mxEvent: PropTypes.object.isRequired,
|
||||||
|
// The reaction content / key / emoji
|
||||||
|
content: PropTypes.string.isRequired,
|
||||||
|
// A Set of Martix reaction events for this key
|
||||||
|
reactionEvents: PropTypes.object.isRequired,
|
||||||
|
visible: PropTypes.bool.isRequired,
|
||||||
|
}
|
||||||
|
|
||||||
|
render() {
|
||||||
|
const Tooltip = sdk.getComponent('elements.Tooltip');
|
||||||
|
const { content, reactionEvents, mxEvent, visible } = this.props;
|
||||||
|
|
||||||
|
const room = MatrixClientPeg.get().getRoom(mxEvent.getRoomId());
|
||||||
|
let tooltipLabel;
|
||||||
|
if (room) {
|
||||||
|
const senders = [];
|
||||||
|
for (const reactionEvent of reactionEvents) {
|
||||||
|
const { name } = room.getMember(reactionEvent.getSender());
|
||||||
|
senders.push(name);
|
||||||
|
}
|
||||||
|
const shortName = unicodeToShort(content) || content;
|
||||||
|
tooltipLabel = <div>{_t(
|
||||||
|
"<reactors/><reactedWith>reacted with %(shortName)s</reactedWith>",
|
||||||
|
{
|
||||||
|
shortName,
|
||||||
|
},
|
||||||
|
{
|
||||||
|
reactors: () => {
|
||||||
|
return <div className="mx_ReactionsRowButtonTooltip_senders">
|
||||||
|
{senders.join(", ")}
|
||||||
|
</div>;
|
||||||
|
},
|
||||||
|
reactedWith: (sub) => {
|
||||||
|
return <div className="mx_ReactionsRowButtonTooltip_reactedWith">
|
||||||
|
{sub}
|
||||||
|
</div>;
|
||||||
|
},
|
||||||
|
},
|
||||||
|
)}</div>;
|
||||||
|
}
|
||||||
|
|
||||||
|
let tooltip;
|
||||||
|
if (tooltipLabel) {
|
||||||
|
tooltip = <Tooltip
|
||||||
|
tooltipClassName="mx_ReactionsRowButtonTooltip"
|
||||||
|
visible={visible}
|
||||||
|
label={tooltipLabel}
|
||||||
|
/>;
|
||||||
|
}
|
||||||
|
|
||||||
|
return tooltip;
|
||||||
|
}
|
||||||
|
}
|
|
@ -907,6 +907,7 @@
|
||||||
"Invalid file%(extra)s": "Invalid file%(extra)s",
|
"Invalid file%(extra)s": "Invalid file%(extra)s",
|
||||||
"Error decrypting image": "Error decrypting image",
|
"Error decrypting image": "Error decrypting image",
|
||||||
"Error decrypting video": "Error decrypting video",
|
"Error decrypting video": "Error decrypting video",
|
||||||
|
"<reactors/><reactedWith>reacted with %(shortName)s</reactedWith>": "<reactors/><reactedWith>reacted with %(shortName)s</reactedWith>",
|
||||||
"%(senderDisplayName)s changed the avatar for %(roomName)s": "%(senderDisplayName)s changed the avatar for %(roomName)s",
|
"%(senderDisplayName)s changed the avatar for %(roomName)s": "%(senderDisplayName)s changed the avatar for %(roomName)s",
|
||||||
"%(senderDisplayName)s removed the room avatar.": "%(senderDisplayName)s removed the room avatar.",
|
"%(senderDisplayName)s removed the room avatar.": "%(senderDisplayName)s removed the room avatar.",
|
||||||
"%(senderDisplayName)s changed the room avatar to <img/>": "%(senderDisplayName)s changed the room avatar to <img/>",
|
"%(senderDisplayName)s changed the room avatar to <img/>": "%(senderDisplayName)s changed the room avatar to <img/>",
|
||||||
|
|
Loading…
Reference in a new issue