Merge pull request #2540 from Bilb/fix-link-previews-small-images

fix: UI for link previews when the image is too less than 200px
pull/2525/head
Audric Ackermann 3 years ago committed by GitHub
commit b6305b6c5e
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

@ -152,10 +152,17 @@
background: white; background: white;
color: black; color: black;
border-radius: var(--border-radius-message-box); border-radius: var(--border-radius-message-box);
border-bottom-right-radius: 0;
border-bottom-left-radius: 0;
background-color: white; // TODO theming update // var(--message-link-preview-background-color)
margin: var(--padding-link-preview); margin: var(--padding-link-preview);
.module-image { .module-image {
margin: -1px; margin-bottom: 0;
border-radius: 0;
margin-top: -1px;
margin-left: -1px;
border-top-left-radius: var(--border-radius-message-box);
} }
&__text { &__text {
@ -164,25 +171,23 @@
} }
.module-message__link-preview__content { .module-message__link-preview__content {
padding: 0 0 var(--margins-xs) 0;
display: flex; display: flex;
flex-direction: row; flex-direction: row;
align-items: center; align-items: center;
flex-grow: 1; flex-grow: 1;
margin-left: var(--margins-sm);
} }
.module-message__link-preview__image_container { .module-message__link-preview__image_container {
margin: -2px;
margin-inline-end: 8px; margin-inline-end: 8px;
display: inline-block; display: inline-block;
} }
.module-message__link-preview__icon_container { .module-message__link-preview__icon_container {
display: flex;
justify-content: center;
flex: initial; flex: initial;
min-width: 54px; width: 100px;
width: 54px; height: 100px;
max-height: 54px;
position: relative; position: relative;
margin-left: -2px; margin-left: -2px;
margin-inline-end: 8px; margin-inline-end: 8px;

@ -1,13 +1,14 @@
import classNames from 'classnames'; import classNames from 'classnames';
import React from 'react'; import React from 'react';
import { isImageAttachment } from '../../../../types/Attachment'; import { isImageAttachment } from '../../../../types/Attachment';
import { ImageGrid } from '../../ImageGrid';
import { Image } from '../../Image'; import { Image } from '../../Image';
import { MessageRenderingProps } from '../../../../models/messageType'; import { MessageRenderingProps } from '../../../../models/messageType';
import { useDispatch, useSelector } from 'react-redux'; import { useDispatch, useSelector } from 'react-redux';
import { getMessageLinkPreviewProps } from '../../../../state/selectors/conversations'; import {
getIsMessageSelectionMode,
getMessageLinkPreviewProps,
} from '../../../../state/selectors/conversations';
import { SessionIcon } from '../../../icon'; import { SessionIcon } from '../../../icon';
import { MINIMUM_LINK_PREVIEW_IMAGE_WIDTH } from '../message-item/Message';
import { showLinkVisitWarningDialog } from '../../../dialog/SessionConfirm'; import { showLinkVisitWarningDialog } from '../../../dialog/SessionConfirm';
export type MessageLinkPreviewSelectorProps = Pick< export type MessageLinkPreviewSelectorProps = Pick<
@ -20,9 +21,12 @@ type Props = {
messageId: string; messageId: string;
}; };
const linkPreviewsImageSize = 100;
export const MessageLinkPreview = (props: Props) => { export const MessageLinkPreview = (props: Props) => {
const selected = useSelector(state => getMessageLinkPreviewProps(state as any, props.messageId)); const selected = useSelector(state => getMessageLinkPreviewProps(state as any, props.messageId));
const dispatch = useDispatch(); const dispatch = useDispatch();
const isMessageSelectionMode = useSelector(getIsMessageSelectionMode);
if (!selected) { if (!selected) {
return null; return null;
@ -44,10 +48,11 @@ export const MessageLinkPreview = (props: Props) => {
} }
const previewHasImage = first.image && isImageAttachment(first.image); const previewHasImage = first.image && isImageAttachment(first.image);
const width = first.image && first.image.width;
const isFullSizeImage = width && width >= MINIMUM_LINK_PREVIEW_IMAGE_WIDTH;
function openLinkFromPreview() { function openLinkFromPreview() {
if (isMessageSelectionMode) {
return;
}
if (previews?.length && previews[0].url) { if (previews?.length && previews[0].url) {
showLinkVisitWarningDialog(previews[0].url, dispatch); showLinkVisitWarningDialog(previews[0].url, dispatch);
} }
@ -59,23 +64,20 @@ export const MessageLinkPreview = (props: Props) => {
className={classNames('module-message__link-preview')} className={classNames('module-message__link-preview')}
onClick={openLinkFromPreview} onClick={openLinkFromPreview}
> >
{first.image && previewHasImage && isFullSizeImage ? (
<ImageGrid attachments={[first.image]} onError={props.handleImageError} />
) : null}
<div className={classNames('module-message__link-preview__content')}> <div className={classNames('module-message__link-preview__content')}>
{first.image && previewHasImage && !isFullSizeImage ? ( {previewHasImage ? (
<div className="module-message__link-preview__image_container"> <div className="module-message__link-preview__image_container">
<Image <Image
softCorners={true} softCorners={true}
alt={window.i18n('previewThumbnail', [first.domain])} alt={window.i18n('previewThumbnail', [first.domain])}
height={72} height={linkPreviewsImageSize}
width={72} width={linkPreviewsImageSize}
url={first.image.url} url={first.image.url}
attachment={first.image} attachment={first.image}
onError={props.handleImageError} onError={props.handleImageError}
/> />
</div> </div>
) : !first.image || !previewHasImage ? ( ) : (
<div className="module-message__link-preview__icon_container"> <div className="module-message__link-preview__icon_container">
<div className="module-message__link-preview__icon_container__inner"> <div className="module-message__link-preview__icon_container__inner">
<div className="module-message__link-preview__icon-container__circle-background"> <div className="module-message__link-preview__icon-container__circle-background">
@ -83,7 +85,7 @@ export const MessageLinkPreview = (props: Props) => {
</div> </div>
</div> </div>
</div> </div>
) : null} )}
<div className={classNames('module-message__link-preview__text')}> <div className={classNames('module-message__link-preview__text')}>
<div className="module-message__link-preview__title">{first.title}</div> <div className="module-message__link-preview__title">{first.title}</div>
<div className="module-message__link-preview__location">{first.domain}</div> <div className="module-message__link-preview__location">{first.domain}</div>

@ -647,6 +647,11 @@ export const getSelectedMessageIds = createSelector(
(state: ConversationsStateType): Array<string> => state.selectedMessageIds (state: ConversationsStateType): Array<string> => state.selectedMessageIds
); );
export const getIsMessageSelectionMode = createSelector(
getSelectedMessageIds,
(state: Array<string>): boolean => Boolean(state.length)
);
export const getLightBoxOptions = createSelector( export const getLightBoxOptions = createSelector(
getConversations, getConversations,
(state: ConversationsStateType): LightBoxOptions | undefined => state.lightBox (state: ConversationsStateType): LightBoxOptions | undefined => state.lightBox

2
ts/window.d.ts vendored

@ -43,7 +43,7 @@ declare global {
}; };
}; };
SessionSnodeAPI: SessionSnodeAPI; SessionSnodeAPI: SessionSnodeAPI;
onLogin: any; onLogin: (pw: string) => Promise<void>;
persistStore?: Persistor; persistStore?: Persistor;
restart: any; restart: any;
getSeedNodeList: () => Array<string> | undefined; getSeedNodeList: () => Array<string> | undefined;

Loading…
Cancel
Save