Skip to content

Commit

Permalink
Merge branch 'rm/361007' into 'master'
Browse files Browse the repository at this point in the history
reimplement reactions tooltip truncate

See merge request kchat/webapp!923
  • Loading branch information
antonbuks committed Sep 17, 2024
2 parents 91775c5 + ad901db commit 84f250a
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 84f250a

Please sign in to comment.