Skip to content

Commit

Permalink
reimplement reactions tooltip truncate
Browse files Browse the repository at this point in the history
Changelog: added
  • Loading branch information
antonbuks committed Sep 16, 2024
1 parent 573e1c9 commit ad901db
Showing 1 changed file with 8 additions and 6 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ type Props = {
reactions: ReactionType[];
users: string[];
};
const MAX_DISPLAY_USER = 20;

const ReactionTooltip: React.FC<Props> = (props: Props) => {
const {
Expand All @@ -27,17 +28,18 @@ const ReactionTooltip: React.FC<Props> = (props: Props) => {
users,
} = props;

const otherUsersCount = reactions.length - users.length;
const reduceUsers = users.slice(0, MAX_DISPLAY_USER);
const otherUsersCount = reactions.length - reduceUsers.length;

let names: React.ReactNode;
if (otherUsersCount > 0) {
if (users.length > 0) {
if (reduceUsers.length > 0) {
names = (
<FormattedMessage
id='reaction.usersAndOthersReacted'
defaultMessage='{users} and {otherUsers, number} other {otherUsers, plural, one {user} other {users}}'
values={{
users: users.join(', '),
users: reduceUsers.join(', '),
otherUsers: otherUsersCount,
}}
/>
Expand All @@ -59,8 +61,8 @@ const ReactionTooltip: React.FC<Props> = (props: Props) => {
id='reaction.usersReacted'
defaultMessage='{users} and {lastUser}'
values={{
users: users.slice(0, -1).join(', '),
lastUser: users[users.length - 1],
users: reduceUsers.slice(0, -1).join(', '),
lastUser: reduceUsers[reduceUsers.length - 1],
}}
/>
);
Expand All @@ -69,7 +71,7 @@ const ReactionTooltip: React.FC<Props> = (props: Props) => {
}

let reactionVerb: React.ReactNode;
if (users.length + otherUsersCount > 1) {
if (users.length > 1) {
if (currentUserReacted) {
reactionVerb = (
<FormattedMessage
Expand Down

0 comments on commit ad901db

Please sign in to comment.