|
|
|
@ -1,5 +1,4 @@
|
|
|
|
|
import React from 'react';
|
|
|
|
|
import classNames from 'classnames';
|
|
|
|
|
|
|
|
|
|
import { Image } from './Image';
|
|
|
|
|
|
|
|
|
@ -7,6 +6,9 @@ import { SessionSpinner } from '../basic/SessionSpinner';
|
|
|
|
|
import { StagedLinkPreviewImage } from './composition/CompositionBox';
|
|
|
|
|
import { isImage } from '../../types/MIME';
|
|
|
|
|
import { fromArrayBufferToBase64 } from '../../session/utils/String';
|
|
|
|
|
import styled from 'styled-components';
|
|
|
|
|
import { Flex } from '../basic/Flex';
|
|
|
|
|
import { SessionIconButton } from '../icon';
|
|
|
|
|
|
|
|
|
|
type Props = {
|
|
|
|
|
isLoaded: boolean;
|
|
|
|
@ -18,10 +20,37 @@ type Props = {
|
|
|
|
|
onClose: (url: string) => void;
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
// Note Similar to QuotedMessageComposition
|
|
|
|
|
const StyledStagedLinkPreview = styled(Flex)`
|
|
|
|
|
position: relative;
|
|
|
|
|
/* Same height as a loaded Image Attachment */
|
|
|
|
|
min-height: 132px;
|
|
|
|
|
border-top: 1px solid var(--border-color);
|
|
|
|
|
`;
|
|
|
|
|
|
|
|
|
|
const StyledImage = styled.div`
|
|
|
|
|
div {
|
|
|
|
|
border-radius: 4px;
|
|
|
|
|
overflow: hidden;
|
|
|
|
|
}
|
|
|
|
|
`;
|
|
|
|
|
|
|
|
|
|
const StyledText = styled(Flex)`
|
|
|
|
|
overflow: hidden;
|
|
|
|
|
text-overflow: ellipsis;
|
|
|
|
|
word-break: break-all;
|
|
|
|
|
-webkit-line-clamp: 1;
|
|
|
|
|
-webkit-box-orient: vertical;
|
|
|
|
|
display: -webkit-box;
|
|
|
|
|
font-weight: bold;
|
|
|
|
|
margin: 0 0 0 var(--margins-sm);
|
|
|
|
|
`;
|
|
|
|
|
|
|
|
|
|
export const StagedLinkPreview = (props: Props) => {
|
|
|
|
|
const { isLoaded, onClose, title, image, domain, url } = props;
|
|
|
|
|
|
|
|
|
|
const isContentTypeImage = image && isImage(image.contentType);
|
|
|
|
|
|
|
|
|
|
if (isLoaded && !(title && domain)) {
|
|
|
|
|
return null;
|
|
|
|
|
}
|
|
|
|
@ -33,42 +62,47 @@ export const StagedLinkPreview = (props: Props) => {
|
|
|
|
|
: '';
|
|
|
|
|
|
|
|
|
|
return (
|
|
|
|
|
<div
|
|
|
|
|
className={classNames(
|
|
|
|
|
'module-staged-link-preview',
|
|
|
|
|
isLoading ? 'module-staged-link-preview--is-loading' : null
|
|
|
|
|
)}
|
|
|
|
|
<StyledStagedLinkPreview
|
|
|
|
|
container={true}
|
|
|
|
|
justifyContent={isLoading ? 'center' : 'space-between'}
|
|
|
|
|
alignItems="center"
|
|
|
|
|
width={'100%'}
|
|
|
|
|
padding={'var(--margins-md)'}
|
|
|
|
|
>
|
|
|
|
|
{isLoading ? <SessionSpinner loading={isLoading} /> : null}
|
|
|
|
|
{isLoaded && image && isContentTypeImage ? (
|
|
|
|
|
<div className="module-staged-link-preview__icon-container">
|
|
|
|
|
<Image
|
|
|
|
|
alt={window.i18n('stagedPreviewThumbnail', [domain || ''])}
|
|
|
|
|
softCorners={true}
|
|
|
|
|
height={72}
|
|
|
|
|
width={72}
|
|
|
|
|
url={dataToRender}
|
|
|
|
|
attachment={image as any}
|
|
|
|
|
/>
|
|
|
|
|
</div>
|
|
|
|
|
) : null}
|
|
|
|
|
{isLoaded ? (
|
|
|
|
|
<div className="module-staged-link-preview__content">
|
|
|
|
|
<div className="module-staged-link-preview__title">{title}</div>
|
|
|
|
|
|
|
|
|
|
<div className="module-staged-link-preview__footer">
|
|
|
|
|
<div className="module-staged-link-preview__location">{domain}</div>
|
|
|
|
|
</div>
|
|
|
|
|
</div>
|
|
|
|
|
) : null}
|
|
|
|
|
<button
|
|
|
|
|
type="button"
|
|
|
|
|
className="module-staged-link-preview__close-button"
|
|
|
|
|
<Flex
|
|
|
|
|
container={true}
|
|
|
|
|
justifyContent={isLoading ? 'center' : 'flex-start'}
|
|
|
|
|
alignItems={'center'}
|
|
|
|
|
>
|
|
|
|
|
{isLoading ? <SessionSpinner loading={isLoading} /> : null}
|
|
|
|
|
{isLoaded && image && isContentTypeImage ? (
|
|
|
|
|
<StyledImage>
|
|
|
|
|
<Image
|
|
|
|
|
alt={window.i18n('stagedPreviewThumbnail', [domain || ''])}
|
|
|
|
|
attachment={image as any}
|
|
|
|
|
height={100}
|
|
|
|
|
width={100}
|
|
|
|
|
url={dataToRender}
|
|
|
|
|
softCorners={true}
|
|
|
|
|
/>
|
|
|
|
|
</StyledImage>
|
|
|
|
|
) : null}
|
|
|
|
|
{isLoaded ? <StyledText>{title}</StyledText> : null}
|
|
|
|
|
</Flex>
|
|
|
|
|
<SessionIconButton
|
|
|
|
|
iconType="exit"
|
|
|
|
|
iconColor="var(--chat-buttons-icon-color)"
|
|
|
|
|
iconSize="small"
|
|
|
|
|
onClick={() => {
|
|
|
|
|
onClose(url || '');
|
|
|
|
|
}}
|
|
|
|
|
margin={'0 var(--margins-sm) 0 0'}
|
|
|
|
|
aria-label={window.i18n('close')}
|
|
|
|
|
style={{
|
|
|
|
|
position: isLoading ? 'absolute' : undefined,
|
|
|
|
|
right: isLoading ? 'var(--margins-sm)' : undefined,
|
|
|
|
|
}}
|
|
|
|
|
/>
|
|
|
|
|
</div>
|
|
|
|
|
</StyledStagedLinkPreview>
|
|
|
|
|
);
|
|
|
|
|
};
|
|
|
|
|