chore: useIsMessageSelectioMode hook when needed

pull/3281/head
Audric Ackermann 10 months ago
parent 42f47c15f6
commit e33f2ed734
No known key found for this signature in database

@ -1,7 +1,6 @@
import classNames from 'classnames';
import { isEqual } from 'lodash';
import { memo, SessionDataTestId, useState } from 'react';
import { useSelector } from 'react-redux';
import styled from 'styled-components';
import { useDisableDrag } from '../../hooks/useDisableDrag';
@ -11,10 +10,10 @@ import {
useConversationUsername,
useIsClosedGroup,
} from '../../hooks/useParamSelector';
import { isMessageSelectionMode } from '../../state/selectors/conversations';
import { SessionIcon } from '../icon';
import { AvatarPlaceHolder } from './AvatarPlaceHolder/AvatarPlaceHolder';
import { ClosedGroupAvatar } from './AvatarPlaceHolder/ClosedGroupAvatar';
import { useIsMessageSelectionMode } from '../../state/selectors/selectedConversation';
export enum AvatarSize {
XS = 28,
@ -127,7 +126,7 @@ const AvatarInner = (props: Props) => {
} = props;
const [imageBroken, setImageBroken] = useState(false);
const isSelectingMessages = useSelector(isMessageSelectionMode);
const isSelectingMessages = useIsMessageSelectionMode();
const isClosedGroup = useIsClosedGroup(pubkey);
const avatarPath = useAvatarPath(pubkey);

@ -9,11 +9,11 @@ import { useMessageDirection, useMessageSelected } from '../../state/selectors';
import {
getNextMessageToPlayId,
getSortedMessagesOfSelectedConversation,
isMessageSelectionMode,
} from '../../state/selectors/conversations';
import { getAudioAutoplay } from '../../state/selectors/userConfig';
import { SessionButton, SessionButtonType } from '../basic/SessionButton';
import { SessionIcon } from '../icon';
import { useIsMessageSelectionMode } from '../../state/selectors/selectedConversation';
const StyledSpeedButton = styled.div`
padding: var(--margins-xs);
@ -164,7 +164,7 @@ export const AudioPlayerWithEncryptedFile = (props: {
const autoPlaySetting = useSelector(getAudioAutoplay);
const messageProps = useSelector(getSortedMessagesOfSelectedConversation);
const nextMessageToPlayId = useSelector(getNextMessageToPlayId);
const multiSelectMode = useSelector(isMessageSelectionMode);
const multiSelectMode = useIsMessageSelectionMode();
const selected = useMessageSelected(messageId);
const direction = useMessageDirection(messageId);
const iconColor =

@ -1,17 +1,19 @@
import { useDispatch, useSelector } from 'react-redux';
import { isMessageSelectionMode } from '../../../state/selectors/conversations';
import { useDispatch } from 'react-redux';
import { openRightPanel } from '../../../state/ducks/conversations';
import { useIsOutgoingRequest } from '../../../hooks/useParamSelector';
import { useSelectedConversationKey } from '../../../state/selectors/selectedConversation';
import {
useIsMessageSelectionMode,
useSelectedConversationKey,
} from '../../../state/selectors/selectedConversation';
import { Flex } from '../../basic/Flex';
import { AvatarHeader, CallButton } from './ConversationHeaderItems';
import { SelectionOverlay } from './ConversationHeaderSelectionOverlay';
import { ConversationHeaderTitle } from './ConversationHeaderTitle';
export const ConversationHeaderWithDetails = () => {
const isSelectionMode = useSelector(isMessageSelectionMode);
const isSelectionMode = useIsMessageSelectionMode();
const selectedConvoKey = useSelectedConversationKey();
const isOutgoingRequest = useIsOutgoingRequest(selectedConvoKey);

@ -8,10 +8,7 @@ import { PropsForAttachment, toggleSelectedMessageId } from '../../../../state/d
import { LightBoxOptions, updateLightBoxOptions } from '../../../../state/ducks/modalDialog';
import { StateType } from '../../../../state/reducer';
import { useMessageSelected } from '../../../../state/selectors';
import {
getMessageAttachmentProps,
isMessageSelectionMode,
} from '../../../../state/selectors/conversations';
import { getMessageAttachmentProps } from '../../../../state/selectors/conversations';
import {
AttachmentType,
AttachmentTypeWithPath,
@ -28,6 +25,7 @@ import { MessageHighlighter } from './MessageHighlighter';
import { useIsDetailMessageView } from '../../../../contexts/isDetailViewContext';
import { MessageGenericAttachment } from './MessageGenericAttachment';
import { ContextMessageProvider } from '../../../../contexts/MessageIdContext';
import { useIsMessageSelectionMode } from '../../../../state/selectors/selectedConversation';
export type MessageAttachmentSelectorProps = Pick<
MessageRenderingProps,
@ -67,7 +65,7 @@ export const MessageAttachment = (props: Props) => {
getMessageAttachmentProps(state, messageId)
);
const multiSelectMode = useSelector(isMessageSelectionMode);
const multiSelectMode = useIsMessageSelectionMode();
const selected = useMessageSelected(messageId);
const onClickOnImageGrid = useCallback(
(attachment: AttachmentTypeWithPath | AttachmentType) => {

@ -9,10 +9,7 @@ import { toggleSelectedMessageId } from '../../../../state/ducks/conversations';
import { updateReactListModal } from '../../../../state/ducks/modalDialog';
import { StateType } from '../../../../state/reducer';
import { useHideAvatarInMsgList } from '../../../../state/selectors';
import {
getMessageContentWithStatusesSelectorProps,
isMessageSelectionMode,
} from '../../../../state/selectors/conversations';
import { getMessageContentWithStatusesSelectorProps } from '../../../../state/selectors/conversations';
import { Reactions } from '../../../../util/reactions';
import { Flex } from '../../../basic/Flex';
import { ExpirableReadableMessage } from '../message-item/ExpirableReadableMessage';
@ -21,6 +18,7 @@ import { MessageContent } from './MessageContent';
import { MessageContextMenu } from './MessageContextMenu';
import { MessageReactions } from './MessageReactions';
import { MessageStatus } from './MessageStatus';
import { useIsMessageSelectionMode } from '../../../../state/selectors/selectedConversation';
export type MessageContentWithStatusSelectorProps = { isGroup: boolean } & Pick<
MessageRenderingProps,
@ -63,7 +61,7 @@ export const MessageContentWithStatuses = (props: Props) => {
const dispatch = useDispatch();
const hideAvatar = useHideAvatarInMsgList(props.messageId);
const multiSelectMode = useSelector(isMessageSelectionMode);
const multiSelectMode = useIsMessageSelectionMode();
const onClickOnMessageOuterContainer = useCallback(
(event: MouseEvent<HTMLDivElement>) => {

@ -1,26 +1,20 @@
import classNames from 'classnames';
import { useSelector } from 'react-redux';
import styled from 'styled-components';
import { isOpenOrClosedGroup } from '../../../../models/conversationAttributes';
import { MessageRenderingProps } from '../../../../models/messageType';
import { StateType } from '../../../../state/reducer';
import {
getMessageTextProps,
isMessageSelectionMode,
} from '../../../../state/selectors/conversations';
import { SessionIcon } from '../../../icon';
import { MessageBody } from './MessageBody';
import { useMessageDirection } from '../../../../state/selectors';
type Props = {
messageId: string;
};
import {
useMessageDirection,
useMessageIsDeleted,
useMessageText,
} from '../../../../state/selectors';
import {
useIsMessageSelectionMode,
useSelectedIsGroupOrCommunity,
} from '../../../../state/selectors/selectedConversation';
import type { WithMessageId } from '../../../../session/types/with';
export type MessageTextSelectorProps = Pick<
MessageRenderingProps,
'text' | 'direction' | 'status' | 'isDeleted' | 'conversationType'
>;
type Props = WithMessageId;
const StyledMessageText = styled.div<{ isDeleted?: boolean }>`
white-space: pre-wrap;
@ -37,16 +31,12 @@ const StyledMessageText = styled.div<{ isDeleted?: boolean }>`
`}
`;
export const MessageText = (props: Props) => {
const selected = useSelector((state: StateType) => getMessageTextProps(state, props.messageId));
const multiSelectMode = useSelector(isMessageSelectionMode);
const direction = useMessageDirection(props.messageId);
if (!selected) {
return null;
}
const { text, isDeleted, conversationType } = selected;
export const MessageText = ({ messageId }: Props) => {
const multiSelectMode = useIsMessageSelectionMode();
const direction = useMessageDirection(messageId);
const isDeleted = useMessageIsDeleted(messageId);
const text = useMessageText(messageId);
const isOpenOrClosedGroup = useSelectedIsGroupOrCommunity();
const contents = isDeleted ? window.i18n('deleteMessageDeletedGlobally') : text?.trim();
if (!contents) {
@ -69,7 +59,7 @@ export const MessageText = (props: Props) => {
text={contents || ''}
disableLinks={multiSelectMode}
disableJumbomoji={false}
isGroup={isOpenOrClosedGroup(conversationType)}
isGroup={isOpenOrClosedGroup}
/>
</StyledMessageText>
);

@ -9,12 +9,10 @@ import { MessageRenderingProps } from '../../../../models/messageType';
import { ConvoHub } from '../../../../session/conversations';
import { StateType } from '../../../../state/reducer';
import { useMessageSelected } from '../../../../state/selectors';
import {
getGenericReadableMessageSelectorProps,
isMessageSelectionMode,
} from '../../../../state/selectors/conversations';
import { getGenericReadableMessageSelectorProps } from '../../../../state/selectors/conversations';
import { MessageContentWithStatuses } from '../message-content/MessageContentWithStatus';
import { StyledMessageReactionsContainer } from '../message-content/MessageReactions';
import { useIsMessageSelectionMode } from '../../../../state/selectors/selectedConversation';
export type GenericReadableMessageSelectorProps = Pick<
MessageRenderingProps,
@ -74,7 +72,7 @@ export const GenericReadableMessage = (props: Props) => {
const isMessageSelected = useMessageSelected(props.messageId);
const multiSelectMode = useSelector(isMessageSelectionMode);
const multiSelectMode = useIsMessageSelectionMode();
const [isRightClicked, setIsRightClicked] = useState(false);
const onMessageLoseFocus = useCallback(() => {

@ -22,7 +22,6 @@ import { ReplyingToMessageProps } from '../../components/conversation/compositio
import { MessageAttachmentSelectorProps } from '../../components/conversation/message/message-content/MessageAttachment';
import { MessageContentSelectorProps } from '../../components/conversation/message/message-content/MessageContent';
import { MessageContentWithStatusSelectorProps } from '../../components/conversation/message/message-content/MessageContentWithStatus';
import { MessageTextSelectorProps } from '../../components/conversation/message/message-content/MessageText';
import { GenericReadableMessageSelectorProps } from '../../components/conversation/message/message-item/GenericReadableMessage';
import { hasValidIncomingRequestValues } from '../../models/conversation';
import { isOpenOrClosedGroup } from '../../models/conversationAttributes';
@ -855,25 +854,6 @@ export const getMessageQuoteProps = createSelector(
}
);
export const getMessageTextProps = createSelector(
getMessagePropsByMessageId,
(props): MessageTextSelectorProps | undefined => {
if (!props || isEmpty(props)) {
return undefined;
}
const msgProps: MessageTextSelectorProps = pick(props.propsForMessage, [
'direction',
'status',
'text',
'isDeleted',
'conversationType',
]);
return msgProps;
}
);
export const getMessageAttachmentProps = createSelector(
getMessagePropsByMessageId,
(props): MessageAttachmentSelectorProps | undefined => {

Loading…
Cancel
Save