Page Menu
Home
Phabricator
Search
Configure Global Search
Log In
Files
F3374660
D6057.diff
No One
Temporary
Actions
View File
Edit File
Delete File
View Transforms
Subscribe
Mute Notifications
Award Token
Flag For Later
Size
3 KB
Referenced Files
None
Subscribers
None
D6057.diff
View Options
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<HTMLElement>) => void {
+): (event: SyntheticEvent<HTMLElement>) => 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
@@ -6,6 +6,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,
@@ -20,8 +21,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';
@@ -449,6 +452,45 @@
}, [messageInfo.text, messageInfo.type, onSuccess, successful]);
}
+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 = (
+ <MessageLikeTooltipButton viewerReacted={viewerReacted} />
+ );
+
+ return {
+ actionButtonContent: buttonContent,
+ onClick: onClickReact,
+ label: viewerReacted ? 'Unlike' : 'Like',
+ };
+ }, [canCreateReactionFromMessage, onClickReact, viewerReacted]);
+}
+
function useMessageTooltipActions(
item: ChatMessageInfoItem,
threadInfo: ThreadInfo,
@@ -456,9 +498,10 @@
const sidebarAction = useMessageTooltipSidebarAction(item, threadInfo);
const replyAction = useMessageTooltipReplyAction(item, threadInfo);
const copyAction = useMessageCopyAction(item);
+ const reactAction = useMessageReactAction(item, threadInfo);
return React.useMemo(
- () => [replyAction, sidebarAction, copyAction].filter(Boolean),
- [replyAction, sidebarAction, copyAction],
+ () => [replyAction, sidebarAction, copyAction, reactAction].filter(Boolean),
+ [replyAction, sidebarAction, copyAction, reactAction],
);
}
@@ -640,6 +683,7 @@
getMessageActionTooltipStyle,
useMessageTooltipSidebarAction,
useMessageTooltipReplyAction,
+ useMessageReactAction,
useMessageTooltipActions,
useMessageTooltip,
};
File Metadata
Details
Attached
Mime Type
text/plain
Expires
Wed, Nov 27, 4:37 PM (22 h, 3 m)
Storage Engine
blob
Storage Format
Raw Data
Storage Handle
2591007
Default Alt Text
D6057.diff (3 KB)
Attached To
Mode
D6057: [web] introduce message like button to message tooltip
Attached
Detach File
Event Timeline
Log In to Comment