Signal-Desktop/ts/components/conversation/StagedLinkPreview.tsx

87 lines
2.3 KiB
TypeScript
Raw Normal View History

2021-06-25 16:08:16 +00:00
// Copyright 2019-2021 Signal Messenger, LLC
2020-10-30 20:34:04 +00:00
// SPDX-License-Identifier: AGPL-3.0-only
2019-01-16 03:03:56 +00:00
import React from 'react';
import classNames from 'classnames';
import { Image } from './Image';
2020-09-28 23:46:31 +00:00
import { LinkPreviewDate } from './LinkPreviewDate';
2019-01-16 03:03:56 +00:00
2019-01-14 21:49:58 +00:00
import { AttachmentType, isImageAttachment } from '../../types/Attachment';
import { LocalizerType } from '../../types/Util';
2019-01-16 03:03:56 +00:00
export type Props = {
2021-06-25 16:08:16 +00:00
title?: string;
description?: null | string;
date?: null | number;
domain?: string;
2019-01-16 03:03:56 +00:00
image?: AttachmentType;
2019-01-14 21:49:58 +00:00
i18n: LocalizerType;
2019-01-16 03:03:56 +00:00
onClose?: () => void;
};
2019-01-16 03:03:56 +00:00
2020-09-28 23:46:31 +00:00
export const StagedLinkPreview: React.FC<Props> = ({
2020-09-14 19:51:27 +00:00
onClose,
i18n,
title,
2020-09-28 23:46:31 +00:00
description,
2020-09-14 19:51:27 +00:00
image,
2020-09-28 23:46:31 +00:00
date,
2020-09-14 19:51:27 +00:00
domain,
2020-09-28 23:46:31 +00:00
}: Props) => {
const isImage = isImageAttachment(image);
2021-06-25 16:08:16 +00:00
const isLoaded = Boolean(domain);
2019-01-16 03:03:56 +00:00
2020-09-14 19:51:27 +00:00
return (
<div
className={classNames(
'module-staged-link-preview',
!isLoaded ? 'module-staged-link-preview--is-loading' : null
)}
>
{!isLoaded ? (
<div className="module-staged-link-preview__loading">
{i18n('loadingPreview')}
</div>
) : null}
2021-06-25 16:08:16 +00:00
{isLoaded && image && isImage && domain ? (
2020-09-14 19:51:27 +00:00
<div className="module-staged-link-preview__icon-container">
<Image
alt={i18n('stagedPreviewThumbnail', [domain])}
softCorners
height={72}
width={72}
url={image.url}
attachment={image}
i18n={i18n}
/>
</div>
) : null}
{isLoaded ? (
<div className="module-staged-link-preview__content">
<div className="module-staged-link-preview__title">{title}</div>
2020-09-28 23:46:31 +00:00
{description && (
<div className="module-staged-link-preview__description">
{description}
</div>
)}
<div className="module-staged-link-preview__footer">
<div className="module-staged-link-preview__location">{domain}</div>
<LinkPreviewDate
date={date}
className="module-message__link-preview__date"
/>
</div>
2020-09-14 19:51:27 +00:00
</div>
) : null}
<button
type="button"
className="module-staged-link-preview__close-button"
onClick={onClose}
aria-label={i18n('close')}
/>
</div>
);
};