Page Menu
Home
Phabricator
Search
Configure Global Search
Log In
Files
F3374889
D5852.diff
No One
Temporary
Actions
View File
Edit File
Delete File
View Transforms
Subscribe
Mute Notifications
Award Token
Flag For Later
Size
1 KB
Referenced Files
None
Subscribers
None
D5852.diff
View Options
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
@@ -9,7 +9,7 @@
threadHasPermission,
useSidebarExistsOrCanBeCreated,
} from 'lib/shared/thread-utils';
-import { isComposableMessageType } from 'lib/types/message-types';
+import { isComposableMessageType, messageTypes } from 'lib/types/message-types';
import type { ThreadInfo } from 'lib/types/thread-types';
import { threadPermissions } from 'lib/types/thread-types';
import { longAbsoluteDate } from 'lib/utils/date-utils';
@@ -409,16 +409,37 @@
}, [addReply, item.messageInfo.type, messageInfo, threadInfo]);
}
+function useMessageCopyAction(
+ item: ChatMessageInfoItem,
+): ?MessageTooltipAction {
+ const { messageInfo } = item;
+ return React.useMemo(() => {
+ if (messageInfo.type !== messageTypes.TEXT) {
+ return null;
+ }
+ const buttonContent = <CommIcon icon="copy-filled" size={18} />;
+ const onClick = async () => {
+ await navigator.clipboard.writeText(messageInfo.text);
+ };
+ return {
+ actionButtonContent: buttonContent,
+ onClick,
+ label: 'Copy',
+ };
+ }, [messageInfo]);
+}
+
function useMessageTooltipActions(
item: ChatMessageInfoItem,
threadInfo: ThreadInfo,
): $ReadOnlyArray<MessageTooltipAction> {
const sidebarAction = useMessageTooltipSidebarAction(item, threadInfo);
const replyAction = useMessageTooltipReplyAction(item, threadInfo);
- return React.useMemo(() => [replyAction, sidebarAction].filter(Boolean), [
- replyAction,
- sidebarAction,
- ]);
+ const copyAction = useMessageCopyAction(item);
+ return React.useMemo(
+ () => [replyAction, sidebarAction, copyAction].filter(Boolean),
+ [replyAction, sidebarAction, copyAction],
+ );
}
type UseMessageTooltipArgs = {
File Metadata
Details
Attached
Mime Type
text/plain
Expires
Wed, Nov 27, 5:20 PM (18 h, 36 m)
Storage Engine
blob
Storage Format
Raw Data
Storage Handle
2591148
Default Alt Text
D5852.diff (1 KB)
Attached To
Mode
D5852: Introduce message copy button on web
Attached
Detach File
Event Timeline
Log In to Comment