diff --git a/web/tooltips/reaction-tooltip.react.js b/web/tooltips/reaction-tooltip.react.js --- a/web/tooltips/reaction-tooltip.react.js +++ b/web/tooltips/reaction-tooltip.react.js @@ -3,7 +3,6 @@ import * as React from 'react'; import { useModalContext } from 'lib/components/modal-provider.react.js'; -import { useENSNames } from 'lib/hooks/ens-cache.js'; import type { ReactionInfo } from 'lib/selectors/chat-selectors'; import css from './reaction-tooltip.css'; @@ -15,16 +14,14 @@ } from './tooltip-constants.js'; import MessageReactionsModal from '../modals/chat/message-reactions-modal.react.js'; -const useENSNamesOptions = { allAtOnce: true }; - type Props = { +reactions: ReactionInfo, - +reaction: string, + +usernames: $ReadOnlyArray, + +showSeeMoreText: boolean, }; function ReactionTooltip(props: Props): React.Node { - const { reactions, reaction } = props; - const { users } = reactions[reaction]; + const { reactions, usernames, showSeeMoreText } = props; const { pushModal, popModal } = useModalContext(); @@ -39,23 +36,24 @@ [popModal, pushModal, reactions], ); - const resolvedUsers = useENSNames(users, useENSNamesOptions); - - const usernames = React.useMemo(() => { - return resolvedUsers.map(user => ( + const usernameList = React.useMemo(() => { + return usernames.map(username => (

- {user.username} + {username}

)); - }, [resolvedUsers]); + }, [usernames]); + + const seeMoreText = React.useMemo(() => { + if (!showSeeMoreText) { + return null; + } - let seeMoreText; - if (usernames && usernames.length > 5) { - seeMoreText = ( + return (

); - } + }, [showSeeMoreText]); - return ( -

- {usernames} - {seeMoreText} -
+ const reactionTooltip = React.useMemo( + () => ( +
+ {usernameList} + {seeMoreText} +
+ ), + [onClickReactionTooltip, seeMoreText, usernameList], ); + + return reactionTooltip; } export default ReactionTooltip; diff --git a/web/tooltips/tooltip-action-utils.js b/web/tooltips/tooltip-action-utils.js --- a/web/tooltips/tooltip-action-utils.js +++ b/web/tooltips/tooltip-action-utils.js @@ -457,19 +457,30 @@ const resolvedUsers = useENSNames(users, useENSNamesOptions); + const showSeeMoreText = resolvedUsers.length > 5; + + const usernamesToShow = resolvedUsers + .map(user => user.username) + .filter(Boolean) + .slice(0, 5); + const tooltipSize = React.useMemo(() => { if (typeof document === 'undefined') { return undefinedTooltipSize; } - const usernames = resolvedUsers.map(user => user.username).filter(Boolean); - - return calculateReactionTooltipSize(usernames); - }, [resolvedUsers]); + return calculateReactionTooltipSize(usernamesToShow, showSeeMoreText); + }, [showSeeMoreText, usernamesToShow]); const createReactionTooltip = React.useCallback( - () => , - [reaction, reactions], + () => ( + + ), + [reactions, showSeeMoreText, usernamesToShow], ); const { onMouseEnter, onMouseLeave } = useTooltip({ diff --git a/web/tooltips/tooltip-utils.js b/web/tooltips/tooltip-utils.js --- a/web/tooltips/tooltip-utils.js +++ b/web/tooltips/tooltip-utils.js @@ -366,8 +366,8 @@ function calculateReactionTooltipSize( usernames: $ReadOnlyArray, + showSeeMoreText: boolean, ): TooltipSize { - const showMoreTextIsShown = usernames.length > 5; const { maxWidth, maxHeight, @@ -385,7 +385,7 @@ const seeMoreTextWidth = calculateMaxTextWidth([reactionSeeMoreLabel], 12); let textWidth = usernamesTextWidth; - if (showMoreTextIsShown) { + if (showSeeMoreText) { textWidth = Math.max(usernamesTextWidth, seeMoreTextWidth); } @@ -396,7 +396,7 @@ usernames.length * tooltipLabelStyle.height + (usernames.length - 1) * rowGap; - if (showMoreTextIsShown) { + if (showSeeMoreText) { height = maxTooltipContentHeight; }