Skip to content

Commit

Permalink
refactor: add early return to MessageBoxHint
Browse files Browse the repository at this point in the history
  • Loading branch information
hugocostadev committed Sep 27, 2024
1 parent e007a1e commit 658628a
Showing 1 changed file with 5 additions and 6 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -30,32 +30,31 @@ const MessageBoxHint = ({ isEditing, e2eEnabled, unencryptedMessagesAllowed, isM
!isEditing &&
!isReadOnly;

const showComposerHint = isEditing || isUnencryptedHintVisible || isReadOnly;
if (!isEditing && !isUnencryptedHintVisible && !isReadOnly) {
return null;
}

const renderHintText = (): string => {
if (isEditing) {
return t('Editing_message');
}

if (isReadOnly) {
return t('This_room_is_read_only');
}

if (isUnencryptedHintVisible) {
return t('E2EE_Composer_Unencrypted_Message');
}

return '';
};

return showComposerHint ? (
return (
<MessageComposerHint
icon={isEditing ? 'pencil' : undefined}
helperText={isEditing && !isMobile ? <Trans i18nKey='Editing_message_hint' /> : undefined}
>
{renderHintText()}
</MessageComposerHint>
) : null;
);
};

export default memo(MessageBoxHint);

0 comments on commit 658628a

Please sign in to comment.