diff --git a/web/chat/message-action-buttons.css b/web/chat/message-action-buttons.css index aa46f0544..ec04542d5 100644 --- a/web/chat/message-action-buttons.css +++ b/web/chat/message-action-buttons.css @@ -1,54 +1,59 @@ -div.messageActionButtonsContainer { +div.messageActionButtons { display: flex; - flex-direction: row; font-size: 16px; } +div.messageActionButtonsViewer { + flex-direction: row; +} +div.messageActionButtonsNonViewer { + flex-direction: row-reverse; +} div.messageActionLinkIcon { margin: 0 3px; position: relative; } div.messageActionExtraAreaTop:before { height: 15px; width: 55px; content: ''; position: absolute; bottom: -15px; } div.messageActionExtraAreaTopRight:before { right: 0; } div.messageActionExtraAreaTopLeft:before { left: 0; } div.messageActionExtraArea:before { height: 30px; width: 20px; content: ''; position: absolute; } div.messageActionExtraAreaRight:before { left: -20px; } div.messageActionExtraAreaLeft:before { right: -20px; } div.messageActionTopRightTooltip { bottom: 100%; margin-bottom: 1px; right: 0; } div.messageActionTopLeftTooltip { bottom: 100%; margin-bottom: 1px; left: 0; } div.messageActionLeftTooltip { top: 50%; right: 100%; margin-right: 7px; } div.messageActionRightTooltip { top: 50%; left: 100%; margin-left: 7px; } diff --git a/web/chat/message-action-buttons.js b/web/chat/message-action-buttons.js index bc5b76421..ce527a680 100644 --- a/web/chat/message-action-buttons.js +++ b/web/chat/message-action-buttons.js @@ -1,217 +1,223 @@ // @flow import classNames from 'classnames'; import invariant from 'invariant'; import * as React from 'react'; import type { ChatMessageInfoItem } from 'lib/selectors/chat-selectors'; import type { ThreadInfo } from 'lib/types/thread-types'; import type { InputState } from '../input/input-state.js'; import { useOnClickThread, useOnClickPendingSidebar, } from '../selectors/nav-selectors'; import SWMansionIcon from '../SWMansionIcon.react'; import css from './message-action-buttons.css'; import MessageReplyButton from './message-reply-button.react'; import type { ItemAndContainerPositionInfo, MessagePositionInfo, OnMessagePositionWithContainerInfo, PositionInfo, } from './position-types'; import { tooltipPositions, type TooltipPosition } from './tooltip-utils'; import { TooltipMenu, type TooltipStyle, TooltipTextItem, } from './tooltip.react'; const messageActionIconExcessVerticalWhitespace = 10; const openSidebarText = 'Go to sidebar'; const createSidebarText = 'Create sidebar'; type MessageActionButtonsProps = { +threadInfo: ThreadInfo, +item: ChatMessageInfoItem, +containerPosition: PositionInfo, +availableTooltipPositions: $ReadOnlyArray, +setMouseOverMessagePosition?: ( messagePositionInfo: MessagePositionInfo, ) => void, +mouseOverMessagePosition?: OnMessagePositionWithContainerInfo, +canReply?: boolean, +inputState?: ?InputState, +sidebarExistsOrCanBeCreated?: boolean, }; function MessageActionButtons(props: MessageActionButtonsProps): React.Node { const { threadInfo, item, containerPosition, availableTooltipPositions, setMouseOverMessagePosition, mouseOverMessagePosition, canReply, inputState, sidebarExistsOrCanBeCreated, } = props; const [tooltipVisible, setTooltipVisible] = React.useState(false); const [pointingTo, setPointingTo] = React.useState(); const toggleTooltip = React.useCallback( (event: SyntheticEvent) => { setTooltipVisible(!tooltipVisible); if (tooltipVisible) { return; } const rect = event.currentTarget.getBoundingClientRect(); const { top, bottom, left, right, width, height } = rect; const iconPosition: ItemAndContainerPositionInfo = { containerPosition, itemPosition: { top: top - containerPosition.top + messageActionIconExcessVerticalWhitespace, bottom: bottom - containerPosition.top - messageActionIconExcessVerticalWhitespace, left: left - containerPosition.left, right: right - containerPosition.left, width, height: height - messageActionIconExcessVerticalWhitespace * 2, }, }; setPointingTo(iconPosition); }, [containerPosition, tooltipVisible], ); const hideTooltip = React.useCallback(() => { setTooltipVisible(false); }, []); const { threadCreatedFromMessage, messageInfo } = item; const onThreadOpen = useOnClickThread(threadCreatedFromMessage); const onPendingSidebarOpen = useOnClickPendingSidebar( messageInfo, threadInfo, ); const onSidebarButtonClick = React.useCallback( (event: SyntheticEvent) => { if (threadCreatedFromMessage) { onThreadOpen(event); } else { onPendingSidebarOpen(event); } }, [onPendingSidebarOpen, onThreadOpen, threadCreatedFromMessage], ); const onReplyButtonClick = React.useCallback(() => { invariant( setMouseOverMessagePosition, 'setMouseOverMessagePosition should be set if replyButton exists', ); setMouseOverMessagePosition({ type: 'off', item: item }); }, [item, setMouseOverMessagePosition]); const sidebarTooltipButtonText = threadCreatedFromMessage ? openSidebarText : createSidebarText; let tooltipMenu = null; if (pointingTo && tooltipVisible) { tooltipMenu = ( ); } let replyButton; if (canReply) { invariant(inputState, 'inputState must be set if replyButton exists'); invariant( mouseOverMessagePosition, 'mouseOverMessagePosition must be set if replyButton exists', ); replyButton = ( ); } let sidebarButton; if (sidebarExistsOrCanBeCreated) { sidebarButton = (
{tooltipMenu}
); } + const { isViewer } = messageInfo.creator; + const messageActionButtonsContainer = classNames({ + [css.messageActionButtons]: true, + [css.messageActionButtonsViewer]: isViewer, + [css.messageActionButtonsNonViewer]: !isViewer, + }); return ( -
+
{sidebarButton} {replyButton}
); } function getMessageActionTooltipStyle( tooltipPosition: TooltipPosition, ): TooltipStyle { let className; if (tooltipPosition === tooltipPositions.TOP_RIGHT) { className = classNames( css.messageActionTopRightTooltip, css.messageActionExtraAreaTop, css.messageActionExtraAreaTopRight, ); } else if (tooltipPosition === tooltipPositions.TOP_LEFT) { className = classNames( css.messageActionTopLeftTooltip, css.messageActionExtraAreaTop, css.messageActionExtraAreaTopLeft, ); } else if (tooltipPosition === tooltipPositions.RIGHT) { className = classNames( css.messageActionRightTooltip, css.messageActionExtraArea, css.messageActionExtraAreaRight, ); } else if (tooltipPosition === tooltipPositions.LEFT) { className = classNames( css.messageActionLeftTooltip, css.messageActionExtraArea, css.messageActionExtraAreaLeft, ); } invariant(className, `${tooltipPosition} is not valid for message tooltip`); return { className }; } export default MessageActionButtons;