From 32c01806d6755e8402740b9828269845330153f0 Mon Sep 17 00:00:00 2001 From: Matvei Andrienko Date: Thu, 18 Jan 2024 16:37:46 +0100 Subject: [PATCH] fix: get rid of positioning wrapper for message actions box (#2246) MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit ### 🎯 Goal In #2241 we've added a new positioning wrapper for `MessageActionsBox`. That was not the greatest idea, since adding new wrappers can break custom CSS for the users. Having a wrapper is not necessary in this case anyway. This PR implements the same positioning as #2241, but without additional wrappers. --- .../MessageActions/MessageActions.tsx | 26 +- .../MessageActions/MessageActionsBox.tsx | 238 +++++++++--------- .../__tests__/MessageActions.test.js | 41 +-- 3 files changed, 136 insertions(+), 169 deletions(-) diff --git a/src/components/MessageActions/MessageActions.tsx b/src/components/MessageActions/MessageActions.tsx index 53e583a57d..252b9f2427 100644 --- a/src/components/MessageActions/MessageActions.tsx +++ b/src/components/MessageActions/MessageActions.tsx @@ -134,24 +134,20 @@ export const MessageActions = < inline={inline} setActionsBoxOpen={setActionsBoxOpen} > -
- -
+ /> - )} - {messageActions.indexOf(MESSAGE_ACTIONS.pin) > -1 && !message.parent_id && ( - - )} - {messageActions.indexOf(MESSAGE_ACTIONS.flag) > -1 && ( - - )} - {messageActions.indexOf(MESSAGE_ACTIONS.mute) > -1 && ( - - )} - {messageActions.indexOf(MESSAGE_ACTIONS.edit) > -1 && ( - - )} - {messageActions.indexOf(MESSAGE_ACTIONS.delete) > -1 && ( - - )} +} & ComponentProps<'div'>; + +const UnMemoizedMessageActionsBox = React.forwardRef( + ( + props: MessageActionsBoxProps, + ref: React.ForwardedRef, + ) => { + const { + getMessageActions, + handleDelete, + handleEdit, + handleFlag, + handleMute, + handlePin, + isUserMuted, + // eslint-disable-next-line @typescript-eslint/no-unused-vars + mine, + open = false, + ...restDivProps + } = props; + + const { + CustomMessageActionsList = DefaultCustomMessageActionsList, + } = useComponentContext('MessageActionsBox'); + const { setQuotedMessage } = useChannelActionContext('MessageActionsBox'); + const { customMessageActions, message } = useMessageContext( + 'MessageActionsBox', + ); + + const { t } = useTranslationContext('MessageActionsBox'); + + const messageActions = getMessageActions(); + + const handleQuote = () => { + setQuotedMessage(message); + + const elements = message.parent_id + ? document.querySelectorAll('.str-chat__thread .str-chat__textarea__textarea') + : document.getElementsByClassName('str-chat__textarea__textarea'); + const textarea = elements.item(0); + + if (textarea instanceof HTMLTextAreaElement) { + textarea.focus(); + } + }; + + const rootClassName = clsx('str-chat__message-actions-box', { + 'str-chat__message-actions-box--open': open, + }); + const buttonClassName = + 'str-chat__message-actions-list-item str-chat__message-actions-list-item-button'; + + return ( +
+
+ + {messageActions.indexOf(MESSAGE_ACTIONS.quote) > -1 && ( + + )} + {messageActions.indexOf(MESSAGE_ACTIONS.pin) > -1 && !message.parent_id && ( + + )} + {messageActions.indexOf(MESSAGE_ACTIONS.flag) > -1 && ( + + )} + {messageActions.indexOf(MESSAGE_ACTIONS.mute) > -1 && ( + + )} + {messageActions.indexOf(MESSAGE_ACTIONS.edit) > -1 && ( + + )} + {messageActions.indexOf(MESSAGE_ACTIONS.delete) > -1 && ( + + )} +
- - ); -}; + ); + }, +); /** * A popup box that displays the available actions on a message, such as edit, delete, pin, etc. diff --git a/src/components/MessageActions/__tests__/MessageActions.test.js b/src/components/MessageActions/__tests__/MessageActions.test.js index 59fc85afdc..8c137a9e3a 100644 --- a/src/components/MessageActions/__tests__/MessageActions.test.js +++ b/src/components/MessageActions/__tests__/MessageActions.test.js @@ -72,18 +72,7 @@ describe(' component', () => { data-testid="message-actions" onClick={[Function]} > -
-
-
+