Skip to content

Commit

Permalink
Added copy link feature
Browse files Browse the repository at this point in the history
  • Loading branch information
devanshkansagra committed Dec 22, 2024
1 parent 47c8a9e commit d5c356d
Show file tree
Hide file tree
Showing 4 changed files with 45 additions and 0 deletions.
7 changes: 7 additions & 0 deletions packages/layout_editor/src/views/Message/MessageToolbox.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -155,6 +155,13 @@ export const MessageToolbox = ({ variantStyles = {}, ...props }) => {
iconName: 'copy',
visible: true,
},
link: {
label: 'Copy link',
id: 'copyLink',
onClick: () => {},
iconName: 'link',
visible: true,
},
delete: {
label: 'Delete',
id: 'delete',
Expand Down
6 changes: 6 additions & 0 deletions packages/layout_editor/src/views/ThemeLab/LayoutSetting.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -364,6 +364,12 @@ const LayoutSetting = () => {
},
iconName: 'copy',
},
link: {
label: 'Copy link',
id: 'copyLink',
onClick: () => addMessageSurfaceItem('link'),
iconName: 'link',
},
delete: {
label: 'Delete',
id: 'delete',
Expand Down
23 changes: 23 additions & 0 deletions packages/react/src/views/Message/Message.js
Original file line number Diff line number Diff line change
Expand Up @@ -135,6 +135,28 @@ const Message = ({
});
};

const getMessageLink = async (id) => {
const host = await RCInstance.getHost();
const res = await RCInstance.channelInfo();
return `${host}/channel/${res.room.name}/?msg=${id}`;
};

const handleCopyMessageLink = async (msg) => {
try {
const messageLink = await getMessageLink(msg._id);
await navigator.clipboard.writeText(messageLink);
dispatchToastMessage({
type: 'success',
message: 'Message link copied successfully',
});
} catch (err) {
dispatchToastMessage({
type: 'error',
message: 'Error in copying message link',
});
}
};

const handleDeleteMessage = async (msg) => {
const res = await RCInstance.deleteMessage(msg._id);

Expand Down Expand Up @@ -233,6 +255,7 @@ const Message = ({
pinRoles={pinRoles}
editMessageRoles={editMessageRoles}
handleCopyMessage={handleCopyMessage}
handleCopyMessageLink={handleCopyMessageLink}
handleOpenThread={handleOpenThread}
handleDeleteMessage={handleDeleteMessage}
handleStarMessage={handleStarMessage}
Expand Down
9 changes: 9 additions & 0 deletions packages/react/src/views/Message/MessageToolbox.js
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@ export const MessageToolbox = ({
handleDeleteMessage,
handlerReportMessage,
handleCopyMessage,
handleCopyMessageLink,
handleEditMessage,
handleQuoteMessage,
isEditing = false,
Expand All @@ -41,6 +42,7 @@ export const MessageToolbox = ({
'quote',
'star',
'copy',
'link',
'pin',
'edit',
'delete',
Expand Down Expand Up @@ -139,6 +141,13 @@ export const MessageToolbox = ({
iconName: 'copy',
visible: true,
},
link: {
label: 'Copy link',
id: 'copyLink',
onClick: () => handleCopyMessageLink(message),
iconName: 'link',
visible: true,
},
delete: {
label: 'Delete',
id: 'delete',
Expand Down

0 comments on commit d5c356d

Please sign in to comment.