diff --git a/web/chat/reaction-message-utils.js b/web/chat/reaction-message-utils.js --- a/web/chat/reaction-message-utils.js +++ b/web/chat/reaction-message-utils.js @@ -19,7 +19,7 @@ threadID: string, reaction: string, action: 'add_reaction' | 'remove_reaction', -): (event: SyntheticEvent) => void { +): (event: SyntheticEvent) => mixed { const { pushModal } = useModalContext(); const callSendReactionMessage = useServerCall(sendReactionMessage); diff --git a/web/utils/tooltip-utils.js b/web/utils/tooltip-utils.js --- a/web/utils/tooltip-utils.js +++ b/web/utils/tooltip-utils.js @@ -5,6 +5,7 @@ import type { ChatMessageInfoItem } from 'lib/selectors/chat-selectors'; import { createMessageReply } from 'lib/shared/message-utils'; +import { useCanCreateReactionFromMessage } from 'lib/shared/reaction-utils'; import { threadHasPermission, useSidebarExistsOrCanBeCreated, @@ -19,8 +20,10 @@ tooltipLabelStyle, tooltipStyle, } from '../chat/chat-constants'; +import MessageLikeTooltipButton from '../chat/message-like-tooltip-button.react'; import MessageTooltip from '../chat/message-tooltip.react'; import type { PositionInfo } from '../chat/position-types'; +import { useOnClickReact } from '../chat/reaction-message-utils'; import { useTooltipContext } from '../chat/tooltip-provider'; import CommIcon from '../CommIcon.react'; import { InputStateContext } from '../input/input-state'; @@ -409,16 +412,56 @@ }, [addReply, item.messageInfo.type, messageInfo, threadInfo]); } +function useMessageReactAction( + item: ChatMessageInfoItem, + threadInfo: ThreadInfo, +): ?MessageTooltipAction { + const { messageInfo, reactions } = item; + + const reactionInput = '👍'; + const viewerReacted = !!reactions.get(reactionInput)?.viewerReacted; + const action = viewerReacted ? 'remove_reaction' : 'add_reaction'; + + const onClickReact = useOnClickReact( + messageInfo.id, + threadInfo.id, + reactionInput, + action, + ); + + const canCreateReactionFromMessage = useCanCreateReactionFromMessage( + threadInfo, + messageInfo, + ); + + return React.useMemo(() => { + if (!canCreateReactionFromMessage) { + return null; + } + + const buttonContent = ( + + ); + + return { + actionButtonContent: buttonContent, + onClick: onClickReact, + label: viewerReacted ? 'Unlike' : 'Like', + }; + }, [canCreateReactionFromMessage, onClickReact, viewerReacted]); +} + function useMessageTooltipActions( item: ChatMessageInfoItem, threadInfo: ThreadInfo, ): $ReadOnlyArray { const sidebarAction = useMessageTooltipSidebarAction(item, threadInfo); const replyAction = useMessageTooltipReplyAction(item, threadInfo); - return React.useMemo(() => [replyAction, sidebarAction].filter(Boolean), [ - replyAction, - sidebarAction, - ]); + const reactAction = useMessageReactAction(item, threadInfo); + return React.useMemo( + () => [replyAction, sidebarAction, reactAction].filter(Boolean), + [replyAction, sidebarAction, reactAction], + ); } type UseMessageTooltipArgs = { @@ -530,6 +573,7 @@ getMessageActionTooltipStyle, useMessageTooltipSidebarAction, useMessageTooltipReplyAction, + useMessageReactAction, useMessageTooltipActions, useMessageTooltip, };