diff --git a/web/chat/robotext-message.react.js b/web/chat/robotext-message.react.js index 0c35e9529..688b6be3a 100644 --- a/web/chat/robotext-message.react.js +++ b/web/chat/robotext-message.react.js @@ -1,149 +1,135 @@ // @flow import * as React from 'react'; import { useDispatch } from 'react-redux'; import { type RobotextChatMessageInfoItem } from 'lib/selectors/chat-selectors'; import { threadInfoSelector } from 'lib/selectors/thread-selectors'; import type { Dispatch } from 'lib/types/redux-types'; import { type ThreadInfo } from 'lib/types/thread-types'; import { entityTextToReact } from 'lib/utils/entity-text'; import Markdown from '../markdown/markdown.react'; import { linkRules } from '../markdown/rules.react'; import { updateNavInfoActionType } from '../redux/action-types'; import { useSelector } from '../redux/redux-utils'; import { tooltipPositions, useMessageTooltip } from '../utils/tooltip-utils'; import InlineEngagement from './inline-engagement.react'; import css from './robotext-message.css'; const availableTooltipPositionsForRobotext = [ tooltipPositions.LEFT, tooltipPositions.LEFT_TOP, tooltipPositions.LEFT_BOTTOM, tooltipPositions.RIGHT, tooltipPositions.RIGHT_TOP, tooltipPositions.RIGHT_BOTTOM, ]; -type BaseProps = { +type Props = { +item: RobotextChatMessageInfoItem, +threadInfo: ThreadInfo, }; -type Props = { - ...BaseProps, - +onMouseLeave: ?() => mixed, - +onMouseEnter: (event: SyntheticEvent) => mixed, -}; -class RobotextMessage extends React.PureComponent { - render() { - let inlineEngagement; - if ( - this.props.item.threadCreatedFromMessage || - this.props.item.reactions.size > 0 - ) { - inlineEngagement = ( -
- -
- ); - } - - return ( -
-
- {this.linkedRobotext()} -
- {inlineEngagement} +function RobotextMessage(props: Props): React.Node { + let inlineEngagement; + const { item } = props; + const { threadCreatedFromMessage, reactions } = item; + if (threadCreatedFromMessage || reactions.size > 0) { + inlineEngagement = ( +
+
); } - linkedRobotext() { - const { item } = this.props; - const { robotext } = item; - const { threadID } = item.messageInfo; + const { messageInfo, robotext } = item; + const { threadID } = messageInfo; + const textParts = React.useMemo(() => { return entityTextToReact(robotext, threadID, { + // eslint-disable-next-line react/display-name renderText: ({ text }) => ( {text} ), + // eslint-disable-next-line react/display-name renderThread: ({ id, name }) => , + // eslint-disable-next-line react/display-name renderColor: ({ hex }) => , }); - } + }, [robotext, threadID]); + + const { threadInfo } = props; + const { onMouseEnter, onMouseLeave } = useMessageTooltip({ + item, + threadInfo, + availablePositions: availableTooltipPositionsForRobotext, + }); + + return ( +
+
+ {textParts} +
+ {inlineEngagement} +
+ ); } + type BaseInnerThreadEntityProps = { +id: string, +name: string, }; type InnerThreadEntityProps = { ...BaseInnerThreadEntityProps, +threadInfo: ThreadInfo, +dispatch: Dispatch, }; class InnerThreadEntity extends React.PureComponent { render() { return {this.props.name}; } onClickThread = (event: SyntheticEvent) => { event.preventDefault(); const id = this.props.id; this.props.dispatch({ type: updateNavInfoActionType, payload: { activeChatThreadID: id, }, }); }; } const ThreadEntity = React.memo( function ConnectedInnerThreadEntity(props: BaseInnerThreadEntityProps) { const { id } = props; const threadInfo = useSelector(state => threadInfoSelector(state)[id]); const dispatch = useDispatch(); return ( ); }, ); function ColorEntity(props: { color: string }) { const colorStyle = { color: props.color }; return {props.color}; } -const ConnectedRobotextMessage: React.ComponentType = React.memo( - function ConnectedRobotextMessage(props) { - const { item, threadInfo } = props; - - const { onMouseLeave, onMouseEnter } = useMessageTooltip({ - item, - threadInfo, - availablePositions: availableTooltipPositionsForRobotext, - }); - - return ( - - ); - }, +const MemoizedRobotextMessage: React.ComponentType = React.memo( + RobotextMessage, ); -export default ConnectedRobotextMessage; +export default MemoizedRobotextMessage;