diff --git a/apps/meteor/client/components/message/toolbar/MessageToolbar.tsx b/apps/meteor/client/components/message/toolbar/MessageToolbar.tsx index f846a1f9fd90..51985049d60c 100644 --- a/apps/meteor/client/components/message/toolbar/MessageToolbar.tsx +++ b/apps/meteor/client/components/message/toolbar/MessageToolbar.tsx @@ -10,6 +10,7 @@ import React, { memo, useMemo, useRef } from 'react'; import MessageActionMenu from './MessageActionMenu'; import MessageToolbarStarsActionMenu from './MessageToolbarStarsActionMenu'; +import { useJumpToMessageAction } from './useJumpToMessageAction'; import { useNewDiscussionMessageAction } from './useNewDiscussionMessageAction'; import { usePermalinkStar } from './usePermalinkStar'; import { useStarMessageAction } from './useStarMessageAction'; @@ -91,6 +92,7 @@ const MessageToolbar = ({ // TODO: move this to another place useWebDAVMessageAction(); useNewDiscussionMessageAction(); + useJumpToMessageAction(message); useStarMessageAction(message, { room, user }); useUnstarMessageAction(message, { room, user }); usePermalinkStar(message, { subscription, user }); diff --git a/apps/meteor/client/components/message/toolbar/useJumpToMessageAction.tsx b/apps/meteor/client/components/message/toolbar/useJumpToMessageAction.tsx new file mode 100644 index 000000000000..4486ab908de4 --- /dev/null +++ b/apps/meteor/client/components/message/toolbar/useJumpToMessageAction.tsx @@ -0,0 +1,25 @@ +import type { IMessage } from '@rocket.chat/core-typings'; +import { useEffect } from 'react'; + +import { MessageAction } from '../../../../app/ui-utils/client/lib/MessageAction'; +import { setMessageJumpQueryStringParameter } from '../../../lib/utils/setMessageJumpQueryStringParameter'; + +export const useJumpToMessageAction = (message: IMessage) => { + useEffect(() => { + MessageAction.addButton({ + id: 'jump-to-message', + icon: 'jump', + label: 'Jump_to_message', + context: ['mentions', 'threads', 'videoconf-threads'], + action() { + setMessageJumpQueryStringParameter(message._id); + }, + order: 100, + group: 'message', + }); + + return () => { + MessageAction.removeButton('star-message'); + }; + }, [message]); +}; diff --git a/apps/meteor/client/startup/actionButtons/index.ts b/apps/meteor/client/startup/actionButtons/index.ts index 81c8979ae2a9..f30d717f0b3a 100644 --- a/apps/meteor/client/startup/actionButtons/index.ts +++ b/apps/meteor/client/startup/actionButtons/index.ts @@ -1,4 +1,3 @@ -import './jumpToMessage'; import './jumpToPinMessage'; import './jumpToSearchMessage'; import './jumpToStarMessage'; diff --git a/apps/meteor/client/startup/actionButtons/jumpToMessage.ts b/apps/meteor/client/startup/actionButtons/jumpToMessage.ts deleted file mode 100644 index 9e8d7d5e07b9..000000000000 --- a/apps/meteor/client/startup/actionButtons/jumpToMessage.ts +++ /dev/null @@ -1,18 +0,0 @@ -import { Meteor } from 'meteor/meteor'; - -import { MessageAction } from '../../../app/ui-utils/client'; -import { setMessageJumpQueryStringParameter } from '../../lib/utils/setMessageJumpQueryStringParameter'; - -Meteor.startup(() => { - MessageAction.addButton({ - id: 'jump-to-message', - icon: 'jump', - label: 'Jump_to_message', - context: ['mentions', 'threads', 'videoconf-threads'], - action(_, { message }) { - setMessageJumpQueryStringParameter(message._id); - }, - order: 100, - group: 'message', - }); -});