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

Limit reactions row on initial display #3152

Merged
merged 3 commits into from
Jun 28, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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 @@ -944,6 +944,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