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 1 commit
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;
}
}
30 changes: 27 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,23 @@ export default class ReactionsRow extends React.PureComponent {
reactionEvents={events}
myReactionEvent={myReactionEvent}
/>;
});
}).filter(item => !!item);

let showAllLink;
if (items.length > MAX_ITEMS_WHEN_LIMITED && !showAll) {
jryans marked this conversation as resolved.
Show resolved Hide resolved
items = items.slice(0, MAX_ITEMS_WHEN_LIMITED);
showAllLink = <a
className="mx_ReactionsRow_showAll"
href="#"
onClick={this.onShowAllClick}
>
{_t("Show all")}
</a>;
}

return <div className="mx_ReactionsRow">
{items}
{showAllLink}
jryans marked this conversation as resolved.
Show resolved Hide resolved
</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