diff --git a/web/chat/composed-message.react.js b/web/chat/composed-message.react.js --- a/web/chat/composed-message.react.js +++ b/web/chat/composed-message.react.js @@ -14,11 +14,12 @@ import { assertComposableMessageType } from 'lib/types/message-types'; import { type ThreadInfo } from 'lib/types/thread-types'; -import { type InputState, InputStateContext } from '../input/input-state'; +import { InputStateContext } from '../input/input-state'; import css from './chat-message-list.css'; import FailedSend from './failed-send.react'; import { InlineSidebar } from './inline-sidebar.react'; import MessageTooltip from './message-tooltip.react'; +import type { MessageReplyProps } from './message-tooltip.react'; import { type OnMessagePositionWithContainerInfo, type MessagePositionInfo, @@ -52,8 +53,7 @@ ...BaseProps, // Redux state +sidebarExistsOrCanBeCreated: boolean, - // withInputState - +inputState: ?InputState, + +messageReplyProps: MessageReplyProps, }; class ComposedMessage extends React.PureComponent { static defaultProps: { +borderRadius: number } = { @@ -127,16 +127,13 @@ const availableTooltipPositions = isViewer ? availableTooltipPositionsForViewerMessage : availableTooltipPositionsForNonViewerMessage; - messageTooltip = ( ); } @@ -222,11 +219,22 @@ props.item, ); const inputState = React.useContext(InputStateContext); + const messageReplyProps = React.useMemo(() => { + if (props.canReply) { + return { + canReply: true, + inputState, + setMouseOverMessagePosition: props.setMouseOverMessagePosition, + }; + } + return { canReply: false }; + }, [inputState, props.canReply, props.setMouseOverMessagePosition]); + return ( ); }, diff --git a/web/chat/message-tooltip.react.js b/web/chat/message-tooltip.react.js --- a/web/chat/message-tooltip.react.js +++ b/web/chat/message-tooltip.react.js @@ -36,26 +36,30 @@ type TooltipType = 'sidebar' | 'reply'; +export type MessageReplyProps = + | { +canReply: false } + | { + +canReply: true, + +inputState: ?InputState, + +setMouseOverMessagePosition: ( + messagePositionInfo: MessagePositionInfo, + ) => void, + }; + type MessageTooltipProps = { +threadInfo: ThreadInfo, +item: ChatMessageInfoItem, +availableTooltipPositions: $ReadOnlyArray, - +setMouseOverMessagePosition?: ( - messagePositionInfo: MessagePositionInfo, - ) => void, + +messageReplyProps: MessageReplyProps, +mouseOverMessagePosition: OnMessagePositionWithContainerInfo, - +canReply?: boolean, - +inputState?: ?InputState, }; function MessageTooltip(props: MessageTooltipProps): React.Node { const { threadInfo, item, availableTooltipPositions, - setMouseOverMessagePosition, mouseOverMessagePosition, - canReply, - inputState, + messageReplyProps, } = props; const { containerPosition } = mouseOverMessagePosition; @@ -115,12 +119,13 @@ ); const onReplyButtonClick = React.useCallback(() => { - invariant( - setMouseOverMessagePosition, - 'setMouseOverMessagePosition should be set if replyButton exists', - ); - setMouseOverMessagePosition({ type: 'off', item: item }); - }, [item, setMouseOverMessagePosition]); + if (messageReplyProps.canReply) { + messageReplyProps.setMouseOverMessagePosition({ + type: 'off', + item: item, + }); + } + }, [item, messageReplyProps]); let tooltipText = ''; if (activeTooltip === 'reply') { @@ -146,11 +151,10 @@ } let replyButton; - if (canReply) { - invariant(inputState, 'inputState must be set if replyButton exists'); + if (messageReplyProps.canReply) { invariant( - mouseOverMessagePosition, - 'mouseOverMessagePosition must be set if replyButton exists', + messageReplyProps.inputState, + 'inputState must be set if replyButton exists', ); replyButton = (
{activeTooltip === 'reply' ? tooltipMenu : null}
diff --git a/web/chat/robotext-message.react.js b/web/chat/robotext-message.react.js --- a/web/chat/robotext-message.react.js +++ b/web/chat/robotext-message.react.js @@ -29,6 +29,7 @@ tooltipPositions.RIGHT, tooltipPositions.LEFT, ]; +const cannotReply = { canReply: false }; type BaseProps = { +item: RobotextChatMessageInfoItem, @@ -71,6 +72,7 @@ item={item} mouseOverMessagePosition={this.props.mouseOverMessagePosition} availableTooltipPositions={availableTooltipPositionsForRobotext} + messageReplyProps={cannotReply} /> ); }