fix: use StyledMessageHighlighter in MessageAttachment only when it is rendered

pull/2807/head
William Grant 2 years ago
parent 01ae43d7d0
commit d888999543

@ -31,6 +31,7 @@ import { LightBoxOptions } from '../../SessionConversation';
import { ClickToTrustSender } from './ClickToTrustSender'; import { ClickToTrustSender } from './ClickToTrustSender';
import styled from 'styled-components'; import styled from 'styled-components';
import classNames from 'classnames'; import classNames from 'classnames';
import { StyledMessageHighlighter } from './MessageContent';
export type MessageAttachmentSelectorProps = Pick< export type MessageAttachmentSelectorProps = Pick<
MessageRenderingProps, MessageRenderingProps,
@ -48,10 +49,13 @@ type Props = {
messageId: string; messageId: string;
imageBroken: boolean; imageBroken: boolean;
handleImageError: () => void; handleImageError: () => void;
highlight?: boolean;
}; };
// tslint:disable: use-simple-attributes // tslint:disable: use-simple-attributes
const StyledAttachmentContainer = styled.div<{ messageDirection: MessageModelType }>` const StyledAttachmentContainer = styled.div<{
messageDirection: MessageModelType;
}>`
text-align: center; text-align: center;
position: relative; position: relative;
overflow: hidden; overflow: hidden;
@ -61,10 +65,11 @@ const StyledAttachmentContainer = styled.div<{ messageDirection: MessageModelTyp
// tslint:disable-next-line max-func-body-length cyclomatic-complexity // tslint:disable-next-line max-func-body-length cyclomatic-complexity
export const MessageAttachment = (props: Props) => { export const MessageAttachment = (props: Props) => {
const { messageId, imageBroken, handleImageError } = props; const { messageId, imageBroken, handleImageError, highlight = false } = props;
const dispatch = useDispatch(); const dispatch = useDispatch();
const attachmentProps = useSelector(state => getMessageAttachmentProps(state as any, messageId)); const attachmentProps = useSelector(state => getMessageAttachmentProps(state as any, messageId));
const multiSelectMode = useSelector(isMessageSelectionMode); const multiSelectMode = useSelector(isMessageSelectionMode);
const onClickOnImageGrid = useCallback( const onClickOnImageGrid = useCallback(
(attachment: AttachmentTypeWithPath | AttachmentType) => { (attachment: AttachmentTypeWithPath | AttachmentType) => {
@ -116,6 +121,7 @@ export const MessageAttachment = (props: Props) => {
if (!attachments || !attachments[0]) { if (!attachments || !attachments[0]) {
return null; return null;
} }
const firstAttachment = attachments[0]; const firstAttachment = attachments[0];
const displayImage = canDisplayImage(attachments); const displayImage = canDisplayImage(attachments);
@ -130,18 +136,22 @@ export const MessageAttachment = (props: Props) => {
(isVideo(attachments) && hasVideoScreenshot(attachments))) (isVideo(attachments) && hasVideoScreenshot(attachments)))
) { ) {
return ( return (
<StyledAttachmentContainer messageDirection={direction}> <StyledMessageHighlighter highlight={highlight}>
<ImageGrid <StyledAttachmentContainer messageDirection={direction}>
attachments={attachments} <ImageGrid
onError={handleImageError} attachments={attachments}
onClickAttachment={onClickOnImageGrid} onError={handleImageError}
/> onClickAttachment={onClickOnImageGrid}
</StyledAttachmentContainer> />
</StyledAttachmentContainer>
</StyledMessageHighlighter>
); );
} }
if (!firstAttachment.pending && !firstAttachment.error && isAudio(attachments)) { if (!firstAttachment.pending && !firstAttachment.error && isAudio(attachments)) {
return ( return (
<div <StyledMessageHighlighter
highlight={highlight}
role="main" role="main"
onClick={(e: any) => { onClick={(e: any) => {
if (multiSelectMode) { if (multiSelectMode) {
@ -150,21 +160,20 @@ export const MessageAttachment = (props: Props) => {
e.stopPropagation(); e.stopPropagation();
e.preventDefault(); e.preventDefault();
}} }}
style={{ padding: 'var(--margins-xs) 0px' }}
> >
<AudioPlayerWithEncryptedFile <AudioPlayerWithEncryptedFile
src={firstAttachment.url} src={firstAttachment.url}
contentType={firstAttachment.contentType} contentType={firstAttachment.contentType}
messageId={messageId} messageId={messageId}
/> />
</div> </StyledMessageHighlighter>
); );
} }
const { pending, fileName, fileSize, contentType } = firstAttachment; const { pending, fileName, fileSize, contentType } = firstAttachment;
const extension = getExtensionForDisplay({ contentType, fileName }); const extension = getExtensionForDisplay({ contentType, fileName });
return ( return (
<div className="module-message__generic-attachment"> <StyledMessageHighlighter highlight={highlight} className="module-message__generic-attachment">
{pending ? ( {pending ? (
<div className="module-message__generic-attachment__spinner-container"> <div className="module-message__generic-attachment__spinner-container">
<Spinner size="small" /> <Spinner size="small" />
@ -200,7 +209,7 @@ export const MessageAttachment = (props: Props) => {
{fileSize} {fileSize}
</div> </div>
</div> </div>
</div> </StyledMessageHighlighter>
); );
}; };

@ -62,7 +62,7 @@ const opacityAnimation = keyframes`
} }
`; `;
const StyledMessageHighlighter = styled.div<{ export const StyledMessageHighlighter = styled.div<{
highlight: boolean; highlight: boolean;
}>` }>`
${props => ${props =>
@ -187,13 +187,12 @@ export const MessageContent = (props: Props) => {
</StyledMessageOpaqueContent> </StyledMessageOpaqueContent>
)} )}
{!isDeleted && ( {!isDeleted && (
<StyledMessageHighlighter highlight={highlight}> <MessageAttachment
<MessageAttachment messageId={props.messageId}
messageId={props.messageId} imageBroken={imageBroken}
imageBroken={imageBroken} handleImageError={handleImageError}
handleImageError={handleImageError} highlight={highlight}
/> />
</StyledMessageHighlighter>
)} )}
</IsMessageVisibleContext.Provider> </IsMessageVisibleContext.Provider>
</InView> </InView>

Loading…
Cancel
Save