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

Commit

Permalink
Merge pull request #3152 from matrix-org/jryans/reactions-show-all
Browse files Browse the repository at this point in the history
Limit reactions row on initial display
  • Loading branch information
jryans authored Jun 28, 2019
2 parents 53d7cc6 + f9e158f commit 3342524
Show file tree
Hide file tree
Showing 3 changed files with 45 additions and 3 deletions.
14 changes: 14 additions & 0 deletions res/css/views/messages/_ReactionsRow.scss
Original file line number Diff line number Diff line change
Expand Up @@ -18,3 +18,17 @@ limitations under the License.
margin: 6px 0;
color: $primary-fg-color;
}

.mx_ReactionsRow_showAll {
text-decoration: none;
font-size: 10px;
font-weight: 600;
margin-left: 6px;
vertical-align: top;

&:hover,
&:link,
&:visited {
color: $accent-color;
}
}
33 changes: 30 additions & 3 deletions src/components/views/messages/ReactionsRow.js
Original file line number Diff line number Diff line change
Expand Up @@ -18,10 +18,14 @@ import React from 'react';
import PropTypes from 'prop-types';

import sdk from '../../../index';
import { _t } from '../../../languageHandler';
import { isContentActionable } from '../../../utils/EventUtils';
import { isSingleEmoji } from '../../../HtmlUtils';
import MatrixClientPeg from '../../../MatrixClientPeg';

// The maximum number of reactions to initially show on a message.
const MAX_ITEMS_WHEN_LIMITED = 8;

export default class ReactionsRow extends React.PureComponent {
static propTypes = {
// The event we're displaying reactions for
Expand All @@ -41,6 +45,7 @@ export default class ReactionsRow extends React.PureComponent {

this.state = {
myReactions: this.getMyReactions(),
showAll: false,
};
}

Expand Down Expand Up @@ -94,16 +99,22 @@ export default class ReactionsRow extends React.PureComponent {
return [...myReactions.values()];
}

onShowAllClick = () => {
this.setState({
showAll: true,
});
}

render() {
const { mxEvent, reactions } = this.props;
const { myReactions } = this.state;
const { myReactions, showAll } = this.state;

if (!reactions || !isContentActionable(mxEvent)) {
return null;
}

const ReactionsRowButton = sdk.getComponent('messages.ReactionsRowButton');
const items = reactions.getSortedAnnotationsByKey().map(([content, events]) => {
let items = reactions.getSortedAnnotationsByKey().map(([content, events]) => {
if (!isSingleEmoji(content)) {
return null;
}
Expand All @@ -125,10 +136,26 @@ export default class ReactionsRow extends React.PureComponent {
reactionEvents={events}
myReactionEvent={myReactionEvent}
/>;
});
}).filter(item => !!item);

// Show the first MAX_ITEMS if there are MAX_ITEMS + 1 or more items.
// The "+ 1" ensure that the "show all" reveals something that takes up
// more space than the button itself.
let showAllButton;
if ((items.length > MAX_ITEMS_WHEN_LIMITED + 1) && !showAll) {
items = items.slice(0, MAX_ITEMS_WHEN_LIMITED);
showAllButton = <a
className="mx_ReactionsRow_showAll"
href="#"
onClick={this.onShowAllClick}
>
{_t("Show all")}
</a>;
}

return <div className="mx_ReactionsRow">
{items}
{showAllButton}
</div>;
}
}
1 change: 1 addition & 0 deletions src/i18n/strings/en_EN.json
Original file line number Diff line number Diff line change
Expand Up @@ -942,6 +942,7 @@
"Party Popper": "Party Popper",
"Confused": "Confused",
"Eyes": "Eyes",
"Show all": "Show all",
"<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 removed the room avatar.": "%(senderDisplayName)s removed the room avatar.",
Expand Down

0 comments on commit 3342524

Please sign in to comment.